AutoPxEth.sol
General Overview
The AutoPxEth.sol
contract is an autocompounding vault adapted from the pxGMX vault system. It allows users to stake and unstake pxETH tokens, issuing/redeeming apxETH share tokens in return. The contract is programmed to automatically compound pxETH rewards by harvesting ETH rewards from multiple sources, including MEV, consensus layer, and execution layer. Rewards are distributed over time based on predetermined rates and durations, with a platform fee deducted before compounding.
Additionally, the contract includes various permissioned methods, enabling a governance multisig to configure the platform's fee recipient, the PirexEth
contract, withdrawal penalties, and the platform fee. It also modifies the transfer
and transferFrom
methods to trigger initiateRedemption
when apxETH is transferred to PirexEth
, streamlining the redemption process.
Technical Overview
Inherits: Ownable2Step, ERC4626
Author: redactedcartel.finance
State Variables
MAX_WITHDRAWAL_PENALTY
MAX_PLATFORM_FEE
FEE_DENOMINATOR
REWARDS_DURATION
pirexEth
periodFinish
rewardRate
lastUpdateTime
rewardPerTokenStored
rewardPerTokenPaid
rewards
totalStaked
withdrawalPenalty
platformFee
platform
Functions
updateReward
Update reward states
Parameters
Name | Type | Description |
---|---|---|
updateEarned | bool | Whether to update earned amount so far |
constructor
Parameters
Name | Type | Description |
---|---|---|
_asset | address | Asset contract address |
_platform | address | Platform address |
setPirexEth
Set the PirexEth contract address
Parameters
Name | Type | Description |
---|---|---|
_pirexEth | address | PirexEth contract address |
setWithdrawalPenalty
Set the withdrawal penalty
Parameters
Name | Type | Description |
---|---|---|
penalty | uint256 | Withdrawal penalty |
setPlatformFee
Set the platform fee
Parameters
Name | Type | Description |
---|---|---|
fee | uint256 | Platform fee |
setPlatform
Set the platform
Parameters
Name | Type | Description |
---|---|---|
_platform | address | Platform |
notifyRewardAmount
Notify and sync the newly added rewards to be streamed over time
Rewards are streamed following the duration set in REWARDS_DURATION
totalAssets
Get the amount of available pxETH in the contract
Rewards are streamed for the duration set in REWARDS_DURATION
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Assets |
lastTimeRewardApplicable
Returns the last effective timestamp of the current reward period
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Timestamp |
rewardPerToken
Returns the amount of rewards per staked token/asset
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Rewards amount |
earned
Returns the earned rewards amount so far
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Rewards amount |
assetsPerShare
Return the amount of assets per 1 (1e18) share
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Assets |
_stake
Intenal method to keep track of the total amount of staked token/asset on deposit/mint
_withdraw
Intenal method to keep track of the total amount of staked token/asset on withdrawal/redeem
beforeWithdraw
Deduct the specified amount of assets from totalStaked to prepare for transfer to user
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | Assets |
<none> | uint256 | Override-Required-Placeholder |
afterDeposit
Include the new assets in totalStaked so that rewards can be properly distributed
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | Assets |
<none> | uint256 | Override-Required-Placeholder |
previewRedeem
Preview the amount of assets a user would receive from redeeming shares
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | Shares |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Assets |
previewWithdraw
Preview the amount of shares a user would need to redeem the specified asset amount
This modified version takes into consideration the withdrawal fee
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | Assets |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Shares |
harvest
Harvest and stake available rewards after distributing fees to platform
transfer
Override transfer logic for direct initiateRedemption
trigger
Parameters
Name | Type | Description |
---|---|---|
to | address | Transfer destination |
amount | uint256 | Amount |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Success flag |
transferFrom
Override transferFrom logic for direct initiateRedemption
trigger
Parameters
Name | Type | Description |
---|---|---|
from | address | Transfer origin |
to | address | Transfer destination |
amount | uint256 | Amount |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | Success flag |