PirexEth.sol

General Overview

The PirexEth.sol contract is the main contracts for handling pxETH interactions. It allows users to deposit ETH and receive pxETH tokens, which can be automatically staked for earning rewards. Users can also redeem their pxETH for ETH or upxETH. It also manages all associated fees for depositing, redeeming, and instantly converting pxETH.

Technical Overview

Inherits: PirexEthValidators

Author: redactedcartel.finance

State Variables

pirexFees

IPirexFees public immutable pirexFees;

maxFees

mapping(DataTypes.Fees => uint32) public maxFees;

fees

mapping(DataTypes.Fees => uint32) public fees;

paused

uint256 public paused;

Functions

whenNotPaused

modifier whenNotPaused();

constructor

constructor(
    address _pxEth,
    address _admin,
    address _beaconChainDepositContract,
    address _upxEth,
    uint256 _depositSize,
    uint256 _preDepositAmount,
    address _pirexFees,
    uint48 _initialDelay
)
    PirexEthValidators(_pxEth, _admin, _beaconChainDepositContract, _upxEth, _depositSize, _preDepositAmount, _initialDelay);

Parameters

NameTypeDescription
_pxEthaddressPxETH contract address
_adminaddressAdmin address
_beaconChainDepositContractaddressThe address of the beacon chain deposit contract
_upxEthaddressUpxETH address
_depositSizeuint256Amount of eth to stake
_preDepositAmountuint256Amount of ETH for pre-deposit
_pirexFeesaddressPirexFees contract address
_initialDelayuint48Delay required to schedule the acceptance of a access control transfer started

setFee

Set fee

function setFee(DataTypes.Fees f, uint32 fee) external onlyRole(GOVERNANCE_ROLE);

Parameters

NameTypeDescription
fDataTypes.FeesFee
feeuint32Fee amount

setMaxFee

Set Max fee

function setMaxFee(DataTypes.Fees f, uint32 maxFee) external onlyRole(GOVERNANCE_ROLE);

Parameters

NameTypeDescription
fDataTypes.FeesFee
maxFeeuint32Max fee amount

togglePauseState

toggle the contract's pause state

function togglePauseState() external onlyRole(GOVERNANCE_ROLE);

emergencyWithdraw

Emergency withdrawal for all ERC20 tokens (except pxETH) and ETH

This function should only be called under major emergency

function emergencyWithdraw(address receiver, address token, uint256 amount)
    external
    onlyRole(GOVERNANCE_ROLE)
    onlyWhenDepositEtherPaused;

Parameters

NameTypeDescription
receiveraddressReceiver address
tokenaddressToken address
amountuint256Token amount

deposit

Handle pxETH minting in return for ETH deposits

function deposit(address receiver, bool shouldCompound)
    external
    payable
    whenNotPaused
    nonReentrant
    returns (uint256 postFeeAmount, uint256 feeAmount);

Parameters

NameTypeDescription
receiveraddressReceiver of the minted pxETH or apxEth
shouldCompoundboolWhether to also compound into the vault

Returns

NameTypeDescription
postFeeAmountuint256pxETH minted for the receiver
feeAmountuint256pxETH distributed as fees

initiateRedemption

Initiate redemption by burning pxETH in return for upxETH

function initiateRedemption(uint256 _assets, address _receiver, bool _shouldTriggerValidatorExit)
    external
    override
    whenNotPaused
    nonReentrant
    returns (uint256 postFeeAmount, uint256 feeAmount);

Parameters

NameTypeDescription
_assetsuint256If caller is AutoPxEth then apxETH; pxETH otherwise
_receiveraddressReceiver for upxETH
_shouldTriggerValidatorExitboolWhether the initiation should trigger voluntary exit

Returns

NameTypeDescription
postFeeAmountuint256pxETH burnt for the receiver
feeAmountuint256pxETH distributed as fees

redeemWithUpxEth

Redeem back ETH using upxEth

function redeemWithUpxEth(uint256 _tokenId, uint256 _assets, address _receiver) external whenNotPaused nonReentrant;

Parameters

NameTypeDescription
_tokenIduint256Redeem batch identifier
_assetsuint256Amount of ETH to redeem
_receiveraddressAddress of the ETH receiver

instantRedeemWithPxEth

Instant redeem back ETH using pxETH

function instantRedeemWithPxEth(uint256 _assets, address _receiver)
    external
    whenNotPaused
    nonReentrant
    returns (uint256 postFeeAmount, uint256 feeAmount);

Parameters

NameTypeDescription
_assetsuint256Amount of pxETH to redeem
_receiveraddressAddress of the ETH receiver

Returns

NameTypeDescription
postFeeAmountuint256Post-fee amount for the receiver
feeAmountuint256Fee amount sent to the PirexFees

_computeAssetAmounts

Compute post-fee asset and fee amounts from a fee type and total assets

function _computeAssetAmounts(DataTypes.Fees f, uint256 assets)
    internal
    view
    returns (uint256 postFeeAmount, uint256 feeAmount);

Parameters

NameTypeDescription
fDataTypes.FeesFee
assetsuint256ETH or pxETH asset amount

Returns

NameTypeDescription
postFeeAmountuint256Post-fee asset amount (for mint/burn/claim/etc.)
feeAmountuint256Fee amount

Events

Deposit

event Deposit(
    address indexed caller,
    address indexed receiver,
    bool indexed shouldCompound,
    uint256 deposited,
    uint256 receivedAmount,
    uint256 feeAmount
);

InitiateRedemption

event InitiateRedemption(uint256 assets, uint256 postFeeAmount, address indexed receiver);

RedeemWithUpxEth

event RedeemWithUpxEth(uint256 tokenId, uint256 assets, address indexed receiver);

RedeemWithPxEth

event RedeemWithPxEth(uint256 assets, uint256 postFeeAmount, address indexed _receiver);

SetFee

event SetFee(DataTypes.Fees indexed f, uint32 fee);

SetMaxFee

event SetMaxFee(DataTypes.Fees indexed f, uint32 maxFee);

SetPauseState

event SetPauseState(address account, uint256 state);

EmergencyWithdrawal

event EmergencyWithdrawal(address indexed receiver, address indexed token, uint256 amount);