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

uint256 public constant MAX_WITHDRAWAL_PENALTY = 50_000;

MAX_PLATFORM_FEE

uint256 public constant MAX_PLATFORM_FEE = 200_000;

FEE_DENOMINATOR

uint256 public constant FEE_DENOMINATOR = 1_000_000;

REWARDS_DURATION

uint256 public constant REWARDS_DURATION = 7 days;

pirexEth

IPirexEth public pirexEth;

periodFinish

uint256 public periodFinish;

rewardRate

uint256 public rewardRate;

lastUpdateTime

uint256 public lastUpdateTime;

rewardPerTokenStored

uint256 public rewardPerTokenStored;

rewardPerTokenPaid

uint256 public rewardPerTokenPaid;

rewards

uint256 public rewards;

totalStaked

uint256 public totalStaked;

withdrawalPenalty

uint256 public withdrawalPenalty = 30_000;

platformFee

uint256 public platformFee = 100_000;

platform

address public platform;

Functions

updateReward

Update reward states

modifier updateReward(bool updateEarned);

Parameters

NameTypeDescription
updateEarnedboolWhether to update earned amount so far

constructor

constructor(address _asset, address _platform) ERC4626(ERC20(_asset), "Autocompounding Pirex Ether", "apxETH");

Parameters

NameTypeDescription
_assetaddressAsset contract address
_platformaddressPlatform address

setPirexEth

Set the PirexEth contract address

function setPirexEth(address _pirexEth) external onlyOwner;

Parameters

NameTypeDescription
_pirexEthaddressPirexEth contract address

setWithdrawalPenalty

Set the withdrawal penalty

function setWithdrawalPenalty(uint256 penalty) external onlyOwner;

Parameters

NameTypeDescription
penaltyuint256Withdrawal penalty

setPlatformFee

Set the platform fee

function setPlatformFee(uint256 fee) external onlyOwner;

Parameters

NameTypeDescription
feeuint256Platform fee

setPlatform

Set the platform

function setPlatform(address _platform) external onlyOwner;

Parameters

NameTypeDescription
_platformaddressPlatform

notifyRewardAmount

Notify and sync the newly added rewards to be streamed over time

Rewards are streamed following the duration set in REWARDS_DURATION

function notifyRewardAmount() external updateReward(false);

totalAssets

Get the amount of available pxETH in the contract

Rewards are streamed for the duration set in REWARDS_DURATION

function totalAssets() public view override returns (uint256);

Returns

NameTypeDescription
<none>uint256Assets

lastTimeRewardApplicable

Returns the last effective timestamp of the current reward period

function lastTimeRewardApplicable() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256Timestamp

rewardPerToken

Returns the amount of rewards per staked token/asset

function rewardPerToken() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256Rewards amount

earned

Returns the earned rewards amount so far

function earned() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256Rewards amount

assetsPerShare

Return the amount of assets per 1 (1e18) share

function assetsPerShare() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256Assets

_stake

Intenal method to keep track of the total amount of staked token/asset on deposit/mint

function _stake(uint256 amount) internal updateReward(true);

_withdraw

Intenal method to keep track of the total amount of staked token/asset on withdrawal/redeem

function _withdraw(uint256 amount) internal updateReward(true);

beforeWithdraw

Deduct the specified amount of assets from totalStaked to prepare for transfer to user

function beforeWithdraw(uint256 assets, uint256) internal override;

Parameters

NameTypeDescription
assetsuint256Assets
<none>uint256Override-Required-Placeholder

afterDeposit

Include the new assets in totalStaked so that rewards can be properly distributed

function afterDeposit(uint256 assets, uint256) internal override;

Parameters

NameTypeDescription
assetsuint256Assets
<none>uint256Override-Required-Placeholder

previewRedeem

Preview the amount of assets a user would receive from redeeming shares

function previewRedeem(uint256 shares) public view override returns (uint256);

Parameters

NameTypeDescription
sharesuint256Shares

Returns

NameTypeDescription
<none>uint256Assets

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

function previewWithdraw(uint256 assets) public view override returns (uint256);

Parameters

NameTypeDescription
assetsuint256Assets

Returns

NameTypeDescription
<none>uint256Shares

harvest

Harvest and stake available rewards after distributing fees to platform

function harvest() public updateReward(true);

transfer

Override transfer logic for direct initiateRedemption trigger

function transfer(address to, uint256 amount) public override returns (bool);

Parameters

NameTypeDescription
toaddressTransfer destination
amountuint256Amount

Returns

NameTypeDescription
<none>boolSuccess flag

transferFrom

Override transferFrom logic for direct initiateRedemption trigger

function transferFrom(address from, address to, uint256 amount) public override returns (bool);

Parameters

NameTypeDescription
fromaddressTransfer origin
toaddressTransfer destination
amountuint256Amount

Returns

NameTypeDescription
<none>boolSuccess flag

Events

Harvest

event Harvest(address indexed caller, uint256 value);

WithdrawalPenaltyUpdated

event WithdrawalPenaltyUpdated(uint256 penalty);

PlatformFeeUpdated

event PlatformFeeUpdated(uint256 fee);

PlatformUpdated

event PlatformUpdated(address _platform);

RewardAdded

event RewardAdded(uint256 reward);

SetPirexEth

event SetPirexEth(address _pirexEth);