Getting started
To make the most of this repository, you should have the following installed:
After cloning this repository and entering inside, run direnv allow
when prompted, and you will be met with following prompt.
🔨 Welcome to devshell
[build]
check - run all linters and build all packages
[deployments]
deploy - Deploy the Smart Contracts
[development]
dev-net - Run local Ethereum network for development
[docs]
docs-build - build the docs and place them in result directory
docs-serve - serve the docs
[formatting]
fmt - format the repo
[foundry]
anvil - A fast local Ethereum development node
cast - Perform Ethereum RPC calls from the comfort of your command line
forge - Build, test, fuzz, debug and deploy Solidity contracts
[general commands]
menu - prints this menu
[tests]
tests - Test the Smart Contracts
direnv: export +DEVSHELL_DIR +FOUNDRY_SOLC +IN_NIX_SHELL +NIXPKGS_PATH +PRJ_DATA_DIR +PRJ_ROOT +name ~PATH ~XDG_DATA_DIRS
The lib
directory contains git-submodules which in turn also have submodules.
To update all submodules recursively, execute:
git submodule update --init --recursive
Docs
To build the docs locally, run docs-build
. The output will be inside of ./result
.
Run docs-serve
to serve the docs locally (after building them previously). You can edit the docs in ./docs
.
Running tests
To run all tests, you can use check
(alias for nix flake check
); it will build all packages and run all tests.
You can use tests -h
to execute a specific test, which will provide more information.
Formatting
You can manually format the source using the fmt
command.
Design Doc
MevEth - Maximizing Ethereum Value
The MevEth
contract serves as a sophisticated platform for Liquid Staking Receipt (LSR) management, designed to optimize Ethereum value through efficient staking and reward distribution. This contract leverages multiple core modules to achieve its objectives, including admin control, staking management, share vault updates, ERC4626 integration, withdrawal queues and omni-chain tokens.
Core Modules and Functionality
The MevEth
contract comprises several core modules, each contributing to its comprehensive functionality:
- Accounting: Transparent fractional accounting system
- Admin Control Panel: Empowers administrators with control over staking, module updates, and share vault management.
- Staking Management: Allows efficient staking of Ether in the Beacon Chain, ensuring validators' registration and interaction with the staking module.
- Share Vault Updates: Facilitates seamless updates to the MevEth share vault, ensuring accurate reward distribution and protocol management.
- Role management: Supports roles management
- ERC4626 Integration: Supports ERC4626 interface for yield source integration, enabling compatibility with Yearn Vault and other protocols.
- Withdrawal Queues: First come, first served queues for withdrawal requests beyond buffer balances
- Omni-chain fungible tokens: Allows
MevEth
tokens to be sent accross chains
Contents
- MevEthErrors
- IAuth
- IBeaconDepositContract
- ICommonOFT
- IERC20Burnable
- IERC4626
- ILayerZeroEndpoint
- ILayerZeroReceiver
- ILayerZeroUserApplicationConfig
- IMevEth
- IMevEthShareVault
- IOFTReceiverV2
- IOFTWithFee
- IRateProvider
- IStakingModule
- ITinyMevEth
MevEthErrors
- Errors
- StakingPaused
- NotEnoughEth
- ZeroValue
- InvalidOperator
- DepositTooSmall
- InvalidSender
- PrematureStakingModuleUpdateFinalization
- PrematureMevEthShareVaultUpdateFinalization
- InvalidPendingStakingModule
- InvalidPendingMevEthShareVault
- TransferExceedsAllowance
- TransferFailed
- ZeroAddress
- AlreadyInitialized
- SendError
- FeesTooHigh
- WrongDepositAmount
- WrongWithdrawAmount
- UnAuthorizedCaller
- WithdrawTooSmall
- NotFinalised
- AlreadyClaimed
- AlreadyFinalised
- IndexExceedsQueueLength
- DepositWasFrontrun
- SandwichProtection
- NonZeroVaultBalance
- AlreadyDeposited
- IncorrectWithdrawalCredentials
SPDX-License-Identifier: SSPL-1.-0
Errors
StakingPaused
Errors
error StakingPaused();
NotEnoughEth
error NotEnoughEth();
ZeroValue
error ZeroValue();
InvalidOperator
error InvalidOperator();
DepositTooSmall
error DepositTooSmall();
InvalidSender
error InvalidSender();
PrematureStakingModuleUpdateFinalization
error PrematureStakingModuleUpdateFinalization();
PrematureMevEthShareVaultUpdateFinalization
error PrematureMevEthShareVaultUpdateFinalization();
InvalidPendingStakingModule
error InvalidPendingStakingModule();
InvalidPendingMevEthShareVault
error InvalidPendingMevEthShareVault();
TransferExceedsAllowance
error TransferExceedsAllowance();
TransferFailed
error TransferFailed();
ZeroAddress
error ZeroAddress();
AlreadyInitialized
error AlreadyInitialized();
SendError
error SendError();
FeesTooHigh
error FeesTooHigh();
WrongDepositAmount
error WrongDepositAmount();
WrongWithdrawAmount
error WrongWithdrawAmount();
UnAuthorizedCaller
error UnAuthorizedCaller();
WithdrawTooSmall
error WithdrawTooSmall();
NotFinalised
error NotFinalised();
AlreadyClaimed
error AlreadyClaimed();
AlreadyFinalised
error AlreadyFinalised();
IndexExceedsQueueLength
error IndexExceedsQueueLength();
DepositWasFrontrun
error DepositWasFrontrun();
SandwichProtection
error SandwichProtection();
NonZeroVaultBalance
error NonZeroVaultBalance();
AlreadyDeposited
error AlreadyDeposited();
IncorrectWithdrawalCredentials
error IncorrectWithdrawalCredentials();
IAuth
SPDX-License-Identifier: SSPL-1.-0
Functions
addAdmin
Adds an admin to the contract.
Only existing admins can add new admins.
function addAdmin(address newAdmin) external;
addOperator
This function adds a new operator to the contract.
This function adds a new operator to the contract. It is only callable by the contract owner. The new operator must be a valid Ethereum address.
function addOperator(address newOperator) external;
admins
This function is used to check if an address is an admin.
This function is used to check if an address is an admin. It takes an address as an argument and returns a boolean value.
function admins(address) external view returns (bool);
deleteAdmin
This function is used to delete an admin from the list of admins.
This function requires the address of the admin to be deleted. It will delete the admin from the list of admins.
function deleteAdmin(address oldAdmin) external;
deleteOperator
This function is used to delete an operator from the contract.
This function is called by the owner of the contract to delete an operator from the contract. The address of the operator to be deleted is passed as an argument.
function deleteOperator(address oldOperator) external;
operators
This function checks if the given address is an operator.
This function is used to check if the given address is an operator. It returns a boolean value indicating whether the address is an operator or not.
function operators(address) external view returns (bool);
Events
AdminAdded
event AdminAdded(address indexed newAdmin);
AdminDeleted
event AdminDeleted(address indexed oldAdmin);
OperatorAdded
event OperatorAdded(address indexed newOperator);
OperatorDeleted
event OperatorDeleted(address indexed oldOperator);
IBeaconDepositContract
SPDX-License-Identifier: SSPL-1.-0
Functions
deposit
Submit a Phase 0 DepositData object.
function deposit(bytes calldata pubkey, bytes calldata withdrawal_credentials, bytes calldata signature, bytes32 deposit_data_root) external payable;
Parameters
Name | Type | Description |
---|---|---|
pubkey | bytes | A BLS12-381 public key. |
withdrawal_credentials | bytes | Commitment to a public key for withdrawals. |
signature | bytes | A BLS12-381 signature. |
deposit_data_root | bytes32 | The SHA-256 hash of the SSZ-encoded DepositData object. Used as a protection against malformed input. |
get_deposit_root
Query the current deposit root hash.
function get_deposit_root() external view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The deposit root hash. |
ICommonOFT
Inherits: IERC165
SPDX-License-Identifier: SSPL-1.-0
Interface of the IOFT core standard
Functions
estimateSendFee
estimate send token _tokenId
to (_dstChainId
, _toAddress
)
_dstChainId - L0 defined chain id to send tokens too
_toAddress - dynamic bytes array which contains the address to whom you are sending tokens to on the dstChain
_amount - amount of the tokens to transfer
_useZro - indicates to use zro to pay L0 fees
_adapterParam - flexible bytes array to indicate messaging adapter services in L0
function estimateSendFee(
uint16 _dstChainId,
bytes32 _toAddress,
uint256 _amount,
bool _useZro,
bytes calldata _adapterParams
)
external
view
returns (uint256 nativeFee, uint256 zroFee);
circulatingSupply
returns the circulating amount of tokens on current chain
function circulatingSupply() external view returns (uint256);
token
returns the address of the ERC20 token
function token() external view returns (address);
Structs
LzCallParams
struct LzCallParams {
address payable refundAddress;
address zroPaymentAddress;
bytes adapterParams;
}
IERC20Burnable
Functions
burnFrom
function burnFrom(address account, uint256 amount) external;
IERC4626
SPDX-License-Identifier: SSPL-1.-0
Functions
asset
function asset() external view returns (address assetTokenAddress);
Returns
Name | Type | Description |
---|---|---|
assetTokenAddress | address | The address of the asset token |
totalAssets
function totalAssets() external view returns (uint256 totalManagedAssets);
Returns
Name | Type | Description |
---|---|---|
totalManagedAssets | uint256 | The amount of eth controlled by the vault |
convertToShares
function convertToShares(uint256 assets) external view returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets to convert to shares |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The value of the given assets in shares |
convertToAssets
function convertToAssets(uint256 shares) external view returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares to convert to assets |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The value of the given shares in assets |
maxDeposit
function maxDeposit(address reciever) external view returns (uint256 maxAssets);
Parameters
Name | Type | Description |
---|---|---|
reciever | address | The address in question of who would be depositing, doesn't matter in this case |
Returns
Name | Type | Description |
---|---|---|
maxAssets | uint256 | The maximum amount of assets that can be deposited |
previewDeposit
function previewDeposit(uint256 assets) external view returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be deposited |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be minted, under ideal conditions only |
deposit
function deposit(uint256 assets, address receiver) external payable returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of WETH which should be deposited |
receiver | address | The address user whom should recieve the mevEth out |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares minted |
maxMint
function maxMint(address reciever) external view returns (uint256 maxShares);
Parameters
Name | Type | Description |
---|---|---|
reciever | address | The address in question of who would be minting, doesn't matter in this case |
Returns
Name | Type | Description |
---|---|---|
maxShares | uint256 | The maximum amount of shares that can be minted |
previewMint
function previewMint(uint256 shares) external view returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be minted |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be required, under ideal conditions only |
mint
function mint(uint256 shares, address receiver) external payable returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that should be minted |
receiver | address | The address user whom should recieve the mevEth out |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets deposited |
maxWithdraw
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
Parameters
Name | Type | Description |
---|---|---|
owner | address | The address in question of who would be withdrawing |
Returns
Name | Type | Description |
---|---|---|
maxAssets | uint256 | The maximum amount of assets that can be withdrawn |
previewWithdraw
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be withdrawn |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be burned, under ideal conditions only |
withdraw
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that should be withdrawn |
receiver | address | The address user whom should recieve the mevEth out |
owner | address | The address of the owner of the mevEth |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares burned |
maxRedeem
function maxRedeem(address owner) external view returns (uint256 maxShares);
Parameters
Name | Type | Description |
---|---|---|
owner | address | The address in question of who would be redeeming their shares |
Returns
Name | Type | Description |
---|---|---|
maxShares | uint256 | The maximum amount of shares they could redeem |
previewRedeem
function previewRedeem(uint256 shares) external view returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be burned |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be withdrawn, under ideal conditions only |
redeem
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that should be burned |
receiver | address | The address user whom should recieve the wETH out |
owner | address | The address of the owner of the mevEth |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets withdrawn |
Events
Deposit
Emitted when a deposit is made, either through mint or deposit
event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);
Withdraw
Emitted when a withdrawal is made, either through redeem or withdraw
event Withdraw(address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);
ILayerZeroEndpoint
Inherits: ILayerZeroUserApplicationConfig
SPDX-License-Identifier: SSPL-1.-0
Functions
send
This function is used to send a payload to a destination on a different chain.
*The function takes in the following parameters:
- _dstChainId: The ID of the destination chain.
- _destination: The address of the destination on the destination chain.
- _payload: The payload to be sent.
- _refundAddress: The address to which the funds should be refunded in case of failure.
- _zroPaymentAddress: The address of the ZROPayment contract.
- _adapterParams: The parameters to be passed to the adapter.*
function send(
uint16 _dstChainId,
bytes calldata _destination,
bytes calldata _payload,
address payable _refundAddress,
address _zroPaymentAddress,
bytes calldata _adapterParams
)
external
payable;
receivePayload
receivePayload is used to receive payloads from other chains.
function receivePayload(
uint16 _srcChainId,
bytes calldata _srcAddress,
address _dstAddress,
uint64 _nonce,
uint256 _gasLimit,
bytes calldata _payload
)
external;
Parameters
Name | Type | Description |
---|---|---|
_srcChainId | uint16 | The source chain ID. |
_srcAddress | bytes | The source address. |
_dstAddress | address | The destination address. |
_nonce | uint64 | The nonce of the transaction. |
_gasLimit | uint256 | The gas limit of the transaction. |
_payload | bytes | The payload of the transaction. |
getInboundNonce
getInboundNonce() is a function that returns the inbound nonce of a given source chain and address.
getInboundNonce() takes two parameters: _srcChainId and _srcAddress. The _srcChainId is a uint16 representing the source chain ID and the _srcAddress is a bytes calldata representing the source address. The function returns a uint64 representing the inbound nonce.
function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (uint64);
getOutboundNonce
function getOutboundNonce(uint16 _dstChainId, address _srcAddress) external view returns (uint64);
estimateFees
This function estimates the fees for a cross-chain transaction.
The function takes in the destination chain ID, user application address, payload, boolean value for whether to pay in ZRO, and adapter parameter as input. It returns the native fee and ZRO fee as output.
function estimateFees(
uint16 _dstChainId,
address _userApplication,
bytes calldata _payload,
bool _payInZRO,
bytes calldata _adapterParam
)
external
view
returns (uint256 nativeFee, uint256 zroFee);
getChainId
getChainId()
Returns the chain ID of the current blockchain.
function getChainId() external view returns (uint16);
Returns
Name | Type | Description |
---|---|---|
<none> | uint16 | uint16 - The chain ID of the current blockchain. |
retryPayload
retryPayload is used to retry a payload from a source chain to a destination chain.
function retryPayload(uint16 _srcChainId, bytes calldata _srcAddress, bytes calldata _payload) external;
Parameters
Name | Type | Description |
---|---|---|
_srcChainId | uint16 | The source chain ID. |
_srcAddress | bytes | The source address. |
_payload | bytes | The payload to be retried. |
hasStoredPayload
function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool);
getSendLibraryAddress
function getSendLibraryAddress(address _userApplication) external view returns (address);
getReceiveLibraryAddress
function getReceiveLibraryAddress(address _userApplication) external view returns (address);
isSendingPayload
This function checks if a payload is being sent.
This function is used to check if a payload is being sent. It returns a boolean value.
function isSendingPayload() external view returns (bool);
isReceivingPayload
function isReceivingPayload() external view returns (bool);
getConfig
getConfig() is a function that allows users to retrieve a configuration from the contract.
getConfig() takes four parameters: _version, _chainId, _userApplication, and _configType. It returns a bytes memory containing the configuration.
function getConfig(uint16 _version, uint16 _chainId, address _userApplication, uint256 _configType) external view returns (bytes memory);
getSendVersion
getSendVersion() is a function that returns the version of the user application.
getSendVersion() takes in an address of the user application and returns a uint16 value representing the version of the user application.
function getSendVersion(address _userApplication) external view returns (uint16);
getReceiveVersion
This function returns the version of the user application.
This function is used to get the version of the user application. It takes in an address of the user application and returns a uint16 representing the version of the user application.
function getReceiveVersion(address _userApplication) external view returns (uint16);
ILayerZeroReceiver
SPDX-License-Identifier: SSPL-1.-0
Functions
lzReceive
This function is used to receive data from a different chain.
*This function takes in four parameters:
- _srcChainId: The ID of the source chain.
- _srcAddress: The address of the source chain.
- _nonce: A unique identifier for the transaction.
- _payload: The data to be received.*
function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) external;
ILayerZeroUserApplicationConfig
SPDX-License-Identifier: SSPL-1.-0
Functions
setConfig
This function sets the configuration of the contract.
*This function sets the configuration of the contract. It takes in four parameters:
- _version: The version of the configuration.
- _chainId: The chain ID of the configuration.
- _configType: The type of configuration.
- _config: The configuration data.*
function setConfig(uint16 _version, uint16 _chainId, uint256 _configType, bytes calldata _config) external;
setSendVersion
function setSendVersion(uint16 _version) external;
setReceiveVersion
Sets the version of the receive protocol.
This function sets the version of the receive protocol. It is used to ensure that the protocol is up to date.
function setReceiveVersion(uint16 _version) external;
forceResumeReceive
This function is used to force resume receive on a given source chain and address.
This function is used to force resume receive on a given source chain and address. It takes two parameters, _srcChainId and _srcAddress. _srcChainId is a uint16 representing the source chain ID and _srcAddress is a bytes calldata representing the source address. This function is only callable by the owner of the contract.
function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external;
IMevEth
SPDX-License-Identifier: SSPL-1.-0
Functions
convertToAssets
convertToAssets()
Converts a given number of shares to assets.
function convertToAssets(uint256 shares) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The number of shares to convert. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of assets. |
IMevEthShareVault
SPDX-License-Identifier: SSPL-1.-0
Functions
payRewards
!
The receive function handles mev/validator payments.
If if the msg.sender is the block.coinbase, a ValditorPayment
should be emitted
The profits (less fees) should be updated based on the median validator payment.
Otherwise, a MevPayment should be emitted and the fees/profits should be updated based on the medianMevPayment.
payRewards()
Function to send rewards to MevEth Contract.
This function is triggered by the owner of the contract and is used to pay rewards to MevETH Contract. In the case of failure, this function sends the funds to the Admin as a fallback.
function payRewards(uint256 rewards) external;
recoverToken
function recoverToken(address token, address recipient, uint256 amount) external;
sendFees
sendFees()
This function should only be called by the contract owner.
Function to send fees to the contract owner.
function sendFees(uint256 fees) external;
setProtocolFeeTo
function setProtocolFeeTo(address newFeeTo) external;
setNewMevEth
setNewMevEth()
Sets the newMevEth address
This function sets the newMevEth address to the address passed in as an argument. This address will be used to store the MEV-ETH tokens.
function setNewMevEth(address newMevEth) external;
IOFTReceiverV2
SPDX-License-Identifier: SSPL-1.-0
Functions
onOFTReceived
Called by the OFT contract when tokens are received from source chain.
function onOFTReceived(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes32 _from, uint256 _amount, bytes calldata _payload) external;
Parameters
Name | Type | Description |
---|---|---|
_srcChainId | uint16 | The chain id of the source chain. |
_srcAddress | bytes | The address of the OFT token contract on the source chain. |
_nonce | uint64 | The nonce of the transaction on the source chain. |
_from | bytes32 | The address of the account who calls the sendAndCall() on the source chain. |
_amount | uint256 | The amount of tokens to transfer. |
_payload | bytes | Additional data with no specified format. |
IOFTWithFee
Inherits: ICommonOFT
SPDX-License-Identifier: SSPL-1.-0
Interface of the IOFT core standard
Functions
sendFrom
send _amount
amount of token to (_dstChainId
, _toAddress
) from _from
_from
the owner of token
_dstChainId
the destination chain identifier
_toAddress
can be any size depending on the dstChainId
.
_amount
the quantity of tokens in wei
_minAmount
the minimum amount of tokens to receive on dstChain
_refundAddress
the address LayerZero refunds if too much message fee is sent
_zroPaymentAddress
set to address(0x0) if not paying in ZRO (LayerZero Token)
_adapterParams
is a flexible bytes array to indicate messaging adapter services
function sendFrom(
address _from,
uint16 _dstChainId,
bytes32 _toAddress,
uint256 _amount,
uint256 _minAmount,
LzCallParams calldata _callParams
)
external
payable;
IRateProvider
SPDX-License-Identifier: SSPL-1.-0
Functions
getRate
getRate()
Returns the current rate of a given asset.
function getRate() external view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | uint256 The current rate of the asset. |
IStakingModule
SPDX-License-Identifier: SSPL-1.-0
Functions
deposit
Allows users to deposit funds into the contract.
function deposit(ValidatorData calldata data, bytes32 latestDepositRoot) external payable;
Parameters
Name | Type | Description |
---|---|---|
data | ValidatorData | ValidatorData calldata containing the validator's public key, withdrawal credentials, and amount of tokens to be deposited. |
latestDepositRoot | bytes32 | bytes32 containing the latest deposit root. |
validators
function validators() external view returns (uint256);
mevEth
function mevEth() external view returns (address);
VALIDATOR_DEPOSIT_SIZE
VALIDATOR_DEPOSIT_SIZE() This function returns the size of the validator deposit.
This function is used to determine the size of the validator deposit. It is used to ensure that validators have the correct amount of funds in order to participate in the network.
function VALIDATOR_DEPOSIT_SIZE() external view returns (uint256);
payRewards
This function is used to pay rewards to the users.
This function is used to pay rewards to the users. It takes in a uint256 rewards parameter which is the amount of rewards to be paid.
function payRewards(uint256 rewards) external;
payValidatorWithdraw
This function allows a validator to withdraw their rewards from the contract.
This function is called by a validator to withdraw their rewards from the contract. It will transfer the rewards to the validator's address.
function payValidatorWithdraw() external;
recoverToken
function recoverToken(address token, address recipient, uint256 amount) external;
record
record() function is used to record the data in the smart contract.
record() function takes no parameters and returns four uint128 values.
function record() external returns (uint128, uint128, uint128, uint128);
registerExit
registerExit() allows users to exit the system.
registerExit() is a function that allows users to exit the system. It is triggered by an external call.
function registerExit() external;
batchMigrate
function batchMigrate(IStakingModule.ValidatorData[] calldata batchData) external;
Structs
ValidatorData
Structure for passing information about the validator deposit data.
struct ValidatorData {
address operator;
bytes pubkey;
bytes32 withdrawal_credentials;
bytes signature;
bytes32 deposit_data_root;
}
ITinyMevEth
SPDX-License-Identifier: SSPL-1.-0
smol interface for interacting with MevEth
Functions
grantRewards
This function is payable and should be called with the amount of rewards to be granted.
Function to grant rewards to other users.
function grantRewards() external payable;
grantValidatorWithdraw
This function must be called with a validator address and a payable amount.
Function to allow a validator to withdraw funds from the contract.
function grantValidatorWithdraw() external payable;
Contents
Contents
LzApp
Inherits: Auth, ILayerZeroReceiver, ILayerZeroUserApplicationConfig
SPDX-License-Identifier: SSPL-1.-0
State Variables
DEFAULT_PAYLOAD_SIZE_LIMIT
uint256 public constant DEFAULT_PAYLOAD_SIZE_LIMIT = 10_000;
lzEndpoint
ILayerZeroEndpoint public immutable lzEndpoint;
trustedRemoteLookup
mapping(uint16 => bytes) public trustedRemoteLookup;
minDstGasLookup
mapping(uint16 => mapping(uint16 => uint256)) public minDstGasLookup;
payloadSizeLimitLookup
mapping(uint16 => uint256) public payloadSizeLimitLookup;
precrime
address public precrime;
Functions
constructor
constructor(address authority, address _endpoint) Auth(authority);
lzReceive
function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public virtual override;
_blockingLzReceive
This function is used to receive a payload from a different chain.
This function is used to receive a payload from a different chain. It is triggered when a payload is sent from a different chain. The payload is stored in the _payload parameter. The _srcChainId parameter is used to identify the chain the payload is coming from. The _srcAddress parameter is used to identify the address the payload is coming from. The _nonce parameter is used to identify the payload.
function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual;
_lzSend
function _lzSend(
uint16 _dstChainId,
bytes memory _payload,
address payable _refundAddress,
address _zroPaymentAddress,
bytes memory _adapterParams,
uint256 _nativeFee
)
internal
virtual;
_checkGasLimit
function _checkGasLimit(uint16 _dstChainId, uint16 _type, bytes memory _adapterParams, uint256 _extraGas) internal view virtual;
_getGasLimit
This function is used to get the gas limit from the adapter parameters.
The function requires the adapter parameters to be at least 34 bytes long. If the adapter parameters are shorter than 34 bytes, the function will revert with an InvalidAdapterParams error. The gas limit is then loaded from the memory address of the adapter parameters plus 34 bytes.
function _getGasLimit(bytes memory _adapterParams) internal pure virtual returns (uint256 gasLimit);
_checkPayloadSize
function _checkPayloadSize(uint16 _dstChainId, uint256 _payloadSize) internal view virtual;
getConfig
getConfig() is a function that retrieves the configuration data from the lzEndpoint.
getConfig() takes in four parameters: _version, _chainId, address, and _configType. It returns a bytes memory.
function getConfig(uint16 _version, uint16 _chainId, address, uint256 _configType) external view returns (bytes memory);
setConfig
This function is used to set the configuration of the contract.
This function is only accessible to the admin of the contract. It takes in four parameters: _version, _chainId, _configType, and _config. The _version and _chainId parameters are used to identify the version and chainId of the contract. The _configType parameter is used to specify the type of configuration being set. The _config parameter is used to pass in the configuration data. The lzEndpoint.setConfig() function is then called to set the configuration.
function setConfig(uint16 _version, uint16 _chainId, uint256 _configType, bytes calldata _config) external override onlyAdmin;
setSendVersion
This function allows an admin to set the send version of the lzEndpoint.
This function is only available to admins and will override any existing send version.
function setSendVersion(uint16 _version) external override onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
_version | uint16 | The version of the lzEndpoint to be set. |
setReceiveVersion
This function sets the receive version of the lzEndpoint.
This function is only available to the admin and is used to set the receive version of the lzEndpoint.
function setReceiveVersion(uint16 _version) external override onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
_version | uint16 | The version to set the lzEndpoint to. |
forceResumeReceive
function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external override onlyAdmin;
setTrustedRemote
This function allows an admin to set a trusted remote chain.
This function sets a trusted remote chain by taking in a chain ID and a path. It then stores the path in the trustedRemoteLookup mapping and emits an event.
function setTrustedRemote(uint16 _remoteChainId, bytes calldata _path) external onlyAdmin;
setTrustedRemoteAddress
function setTrustedRemoteAddress(uint16 _remoteChainId, bytes calldata _remoteAddress) external onlyAdmin;
getTrustedRemoteAddress
getTrustedRemoteAddress() retrieves the trusted remote address for a given chain ID.
The function reverts if no trusted path is found for the given chain ID. The last 20 bytes of the path should be address(this).
function getTrustedRemoteAddress(uint16 _remoteChainId) external view returns (bytes memory);
setPrecrime
This function allows an admin to set the address of the Precrime contract.
This function sets the address of the Precrime contract and emits an event.
function setPrecrime(address _precrime) external onlyAdmin;
setMinDstGas
Sets the minimum gas for a packet type on a destination chain.
function setMinDstGas(uint16 _dstChainId, uint16 _packetType, uint256 _minGas) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
_dstChainId | uint16 | The ID of the destination chain. |
_packetType | uint16 | The type of packet. |
_minGas | uint256 | The minimum gas for the packet type. |
setPayloadSizeLimit
This function sets the payload size limit for a given destination chain.
This function is only callable by the admin and sets the payload size limit for a given destination chain.
function setPayloadSizeLimit(uint16 _dstChainId, uint256 _size) external onlyAdmin;
isTrustedRemote
function isTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool);
Events
SetPrecrime
event SetPrecrime(address precrime);
SetTrustedRemote
event SetTrustedRemote(uint16 _remoteChainId, bytes _path);
SetTrustedRemoteAddress
event SetTrustedRemoteAddress(uint16 _remoteChainId, bytes _remoteAddress);
SetMinDstGas
event SetMinDstGas(uint16 _dstChainId, uint16 _type, uint256 _minDstGas);
Errors
NoTrustedPath
error NoTrustedPath();
InvalidEndpointCaller
error InvalidEndpointCaller();
DestinationChainNotTrusted
error DestinationChainNotTrusted();
MinGasLimitNotSet
error MinGasLimitNotSet();
GasLimitTooLow
error GasLimitTooLow();
InvalidAdapterParams
error InvalidAdapterParams();
PayloadSizeTooLarge
error PayloadSizeTooLarge();
InvalidMinGas
error InvalidMinGas();
InvalidSourceSendingContract
error InvalidSourceSendingContract();
InvalidPayload
SPDX-License-Identifier: SSPL-1.-0
error InvalidPayload();
AmountTooSmall
error AmountTooSmall();
NonblockingLzApp
Inherits: LzApp
State Variables
failedMessages
mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32))) public failedMessages;
Functions
constructor
constructor(address authority, address _endpoint) LzApp(authority, _endpoint);
_blockingLzReceive
function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual override;
_storeFailedMessage
function _storeFailedMessage(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload, bytes memory _reason) internal virtual;
nonblockingLzReceive
function nonblockingLzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public virtual;
_nonblockingLzReceive
This function is used to receive a non-blocking LZ message from a source chain.
This function is used to receive a non-blocking LZ message from a source chain. It takes in the source chain ID, source address, nonce, and payload as parameters. It then verifies the source chain ID, source address, and nonce, and if they are valid, it stores the payload in the contract storage.
function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual;
retryMessage
function retryMessage(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public payable virtual;
Events
MessageFailed
event MessageFailed(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes _payload, bytes _reason);
RetryMessageSuccess
event RetryMessageSuccess(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes32 _payloadHash);
Errors
CallerMustBeLzApp
error CallerMustBeLzApp();
NoStoredMessage
error NoStoredMessage();
Contents
BaseOFTWithFee
Inherits: OFTCoreV2, Fee, ERC165, IOFTWithFee
SPDX-License-Identifier: SSPL-1.-0
Functions
constructor
constructor(uint8 _sharedDecimals, address authority, address _lzEndpoint) OFTCoreV2(_sharedDecimals, authority, _lzEndpoint) Fee(authority);
sendFrom
public functions
function sendFrom(
address _from,
uint16 _dstChainId,
bytes32 _toAddress,
uint256 _amount,
uint256 _minAmount,
LzCallParams calldata _callParams
)
public
payable
virtual
override;
supportsInterface
public view functions
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);
estimateSendFee
function estimateSendFee(
uint16 _dstChainId,
bytes32 _toAddress,
uint256 _amount,
bool _useZro,
bytes calldata _adapterParams
)
public
view
virtual
override
returns (uint256 nativeFee, uint256 zroFee);
circulatingSupply
This function returns the circulating supply of a token.
This function is used to get the circulating supply of a token. It is an override of the virtual function and is public and viewable. It returns a uint256 value.
function circulatingSupply() public view virtual override returns (uint256);
token
This function returns the address of the token associated with the contract.
This function is a virtual override of the token() function.
function token() public view virtual override returns (address);
_transferFrom
This function is used to transfer tokens from one address to another.
This function is used to transfer tokens from one address to another. It takes three parameters: _from, _to, and _amount. _from is the address from which the tokens are being transferred, _to is the address to which the tokens are being transferred, and _amount is the amount of tokens being transferred. This function is internal and virtual, and it overrides the Fee and OFTCoreV2 contracts. It returns the amount of tokens transferred.
function _transferFrom(address _from, address _to, uint256 _amount) internal virtual override(Fee, OFTCoreV2) returns (uint256);
Errors
AmountLessThanMinAmount
error AmountLessThanMinAmount();
Fee
Inherits: Auth
SPDX-License-Identifier: SSPL-1.-0
State Variables
BP_DENOMINATOR
uint256 public constant BP_DENOMINATOR = 10_000;
chainIdToFeeBps
mapping(uint16 => FeeConfig) public chainIdToFeeBps;
defaultFeeBp
uint16 public defaultFeeBp;
feeOwner
address public feeOwner;
Functions
constructor
constructor(address authority);
setDefaultFeeBp
function setDefaultFeeBp(uint16 _feeBp) public virtual onlyAdmin;
setFeeBp
function setFeeBp(uint16 _dstChainId, bool _enabled, uint16 _feeBp) public virtual onlyAdmin;
setFeeOwner
Sets the fee owner address
This function sets the fee owner address to the address passed in as an argument. If the address passed in is 0x0, the function will revert with the FeeOwnerNotSet error.
function setFeeOwner(address _feeOwner) public virtual onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
_feeOwner | address | The address to set as the fee owner |
quoteOFTFee
function quoteOFTFee(uint16 _dstChainId, uint256 _amount) public view virtual returns (uint256 fee);
_payOFTFee
function _payOFTFee(address _from, uint16 _dstChainId, uint256 _amount) internal virtual returns (uint256 amount, uint256 fee);
_transferFrom
This function is used to transfer tokens from one address to another.
This function is called by the transferFrom() function. It is used to transfer tokens from one address to another.
function _transferFrom(address _from, address _to, uint256 _amount) internal virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_from | address | The address from which the tokens are being transferred. |
_to | address | The address to which the tokens are being transferred. |
_amount | uint256 | The amount of tokens being transferred. |
Events
SetFeeBp
event SetFeeBp(uint16 dstchainId, bool enabled, uint16 feeBp);
SetDefaultFeeBp
event SetDefaultFeeBp(uint16 feeBp);
SetFeeOwner
event SetFeeOwner(address feeOwner);
Errors
FeeBpTooLarge
error FeeBpTooLarge();
FeeOwnerNotSet
error FeeOwnerNotSet();
Structs
FeeConfig
struct FeeConfig {
uint16 feeBP;
bool enabled;
}
OFTCoreV2
Inherits: NonblockingLzApp
SPDX-License-Identifier: SSPL-1.-0
State Variables
NO_EXTRA_GAS
uint256 public constant NO_EXTRA_GAS = 0;
PT_SEND
uint8 public constant PT_SEND = 0;
PT_SEND_AND_CALL
uint8 public constant PT_SEND_AND_CALL = 1;
sharedDecimals
uint8 public immutable sharedDecimals;
useCustomAdapterParams
bool public useCustomAdapterParams;
creditedPackets
mapping(uint16 => mapping(bytes => mapping(uint64 => bool))) public creditedPackets;
Functions
constructor
constructor(uint8 _sharedDecimals, address authority, address _lzEndpoint) NonblockingLzApp(authority, _lzEndpoint);
callOnOFTReceived
public functions
function callOnOFTReceived(
uint16 _srcChainId,
bytes calldata _srcAddress,
uint64 _nonce,
bytes32 _from,
address _to,
uint256 _amount,
bytes calldata _payload,
uint256 _gasForCall
)
public
virtual;
setUseCustomAdapterParams
This function allows the admin to set whether or not to use custom adapter parameters.
This function sets the boolean value of useCustomAdapterParams to the value of _useCustomAdapterParams. It also emits an event to notify that the value has been changed.
function setUseCustomAdapterParams(bool _useCustomAdapterParams) public virtual onlyAdmin;
_estimateSendFee
internal functions
function _estimateSendFee(
uint16 _dstChainId,
bytes32 _toAddress,
uint256 _amount,
bool _useZro,
bytes memory _adapterParams
)
internal
view
virtual
returns (uint256 nativeFee, uint256 zroFee);
_nonblockingLzReceive
This function is used to receive a packet from a source chain and process it.
The packet type is checked and if it is a PT_SEND packet, an acknowledgement is sent. If the packet type is not recognised, the transaction is reverted.
function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual override;
_send
function _send(
address _from,
uint16 _dstChainId,
bytes32 _toAddress,
uint256 _amount,
address payable _refundAddress,
address _zroPaymentAddress,
bytes memory _adapterParams
)
internal
virtual
returns (uint256 amount);
_sendAck
function _sendAck(uint16 _srcChainId, bytes memory, uint64, bytes memory _payload) internal virtual;
_checkAdapterParams
function _checkAdapterParams(uint16 _dstChainId, uint16 _pkType, bytes memory _adapterParams, uint256 _extraGas) internal virtual;
_ld2sd
This function converts a given amount of LD to SD.
The function takes a uint256 _amount as an argument and returns a uint64 amountSD. The amountSD is calculated by dividing the _amount by the _ld2sdRate(). If the amountSD is greater than the maximum value of a uint64, the function will revert with an AmountSDOverflow() error.
function _ld2sd(uint256 _amount) internal view virtual returns (uint64);
_sd2ld
_sd2ld() function converts an amount of SD (Solidity Dollars) to LD (Lumens Dollars)
_sd2ld() function takes a uint64 _amountSD as an argument and returns a uint256 LD amount. The conversion rate is determined by the _ld2sdRate() function.
function _sd2ld(uint64 _amountSD) internal view virtual returns (uint256);
_removeDust
_removeDust() removes dust from an amount of tokens.
_removeDust() takes an amount of tokens and removes the dust from it. The dust is calculated by taking the remainder of the amount divided by the ld2sdRate. The amountAfter is the amount of tokens minus the dust.
function _removeDust(uint256 _amount) internal view virtual returns (uint256 amountAfter, uint256 dust);
_encodeSendPayload
_encodeSendPayload() is a function that encodes the payload for a send transaction.
_encodeSendPayload() takes two parameters, a bytes32 _toAddress and a uint64 _amountSD. It returns a bytes memory. It uses the abi.encodePacked() function to encode the payload. The payload consists of the PT_SEND constant, the _toAddress and the _amountSD.
function _encodeSendPayload(bytes32 _toAddress, uint64 _amountSD) internal view virtual returns (bytes memory);
_decodeSendPayload
This function decodes a payload for a send transaction.
The function takes in a bytes memory _payload and returns an address to and uint64 amountSD. The first 12 bytes of bytes32 are dropped and the address is taken from the 13th byte. The amountSD is taken from the 33rd byte. If the first byte of the payload is not PT_SEND or the length of the payload is not 41, the function will revert with an InvalidPayload error.
function _decodeSendPayload(bytes memory _payload) internal view virtual returns (address to, uint64 amountSD);
_debitFrom
Debit an amount from a given address on a given chain
This function debits an amount from a given address on a given chain.
function _debitFrom(address _from, uint16 _dstChainId, bytes32 _toAddress, uint256 _amount) internal virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
_from | address | The address from which the amount is to be debited |
_dstChainId | uint16 | The chain ID of the chain from which the amount is to be debited |
_toAddress | bytes32 | The address to which the amount is to be credited |
_amount | uint256 | The amount to be debited |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount debited |
_creditTo
This function is used to credit an amount to a given address on a given chain.
*This function is used to credit an amount to a given address on a given chain. It takes in three parameters:
- _srcChainId: The chain ID of the source chain.
- _toAddress: The address to which the amount is to be credited.
- _amount: The amount to be credited. This function returns the amount credited.*
function _creditTo(uint16 _srcChainId, address _toAddress, uint256 _amount) internal virtual returns (uint256);
_transferFrom
function _transferFrom(address _from, address _to, uint256 _amount) internal virtual returns (uint256);
_ld2sdRate
This function returns the rate of LD2SD conversion.
This function is used to get the rate of LD2SD conversion.
function _ld2sdRate() internal view virtual returns (uint256);
Events
SendToChain
Emitted when _amount
tokens are moved from the _sender
to (_dstChainId
, _toAddress
)
_nonce
is the outbound nonce
event SendToChain(uint16 indexed _dstChainId, address indexed _from, bytes32 indexed _toAddress, uint256 _amount);
ReceiveFromChain
Emitted when _amount
tokens are received from _srcChainId
into the _toAddress
on the local chain.
_nonce
is the inbound nonce.
event ReceiveFromChain(uint16 indexed _srcChainId, address indexed _to, uint256 _amount);
SetUseCustomAdapterParams
event SetUseCustomAdapterParams(bool _useCustomAdapterParams);
CallOFTReceivedSuccess
event CallOFTReceivedSuccess(uint16 indexed _srcChainId, bytes _srcAddress, uint64 _nonce, bytes32 _hash);
NonContractAddress
event NonContractAddress(address _address);
Errors
CallerMustBeOFTCore
error CallerMustBeOFTCore();
UnknownPacketType
error UnknownPacketType();
AdapterParamsMustBeEmpty
error AdapterParamsMustBeEmpty();
AmountSDOverflow
error AmountSDOverflow();
OFTWithFee
Inherits: BaseOFTWithFee, ERC20
SPDX-License-Identifier: SSPL-1.-0
State Variables
ld2sdRate
uint256 internal immutable ld2sdRate;
Functions
constructor
constructor(
string memory _name,
string memory _symbol,
uint8 decimals,
uint8 _sharedDecimals,
address authority,
address _lzEndpoint
)
ERC20(_name, _symbol, decimals)
BaseOFTWithFee(_sharedDecimals, authority, _lzEndpoint);
circulatingSupply
public functions
function circulatingSupply() public view virtual override returns (uint256);
token
This function returns the address of the token contract.
This function is used to return the address of the token contract. It is a public view virtual override function.
function token() public view virtual override returns (address);
_debitFrom
internal functions
function _debitFrom(address _from, uint16, bytes32, uint256 _amount) internal virtual override returns (uint256);
_creditTo
This function is used to credit an amount to a given address.
This function is used to mint a given amount to a given address. It is an internal virtual override function.
function _creditTo(uint16, address _toAddress, uint256 _amount) internal virtual override returns (uint256);
_transferFrom
This function transfers tokens from one address to another.
If the transfer is from this contract, no allowance check is necessary. Otherwise, the allowance of the spender is checked.
function _transferFrom(address _from, address _to, uint256 _amount) internal virtual override returns (uint256);
_ld2sdRate
This function returns the rate of conversion from LD to SD.
This function is internal and view virtual override.
function _ld2sdRate() internal view virtual override returns (uint256);
_spendAllowance
OpenZeppelin ERC20 extensions
Updates owner
s allowance for spender
based on spent amount
.
Does not update the allowance amount in case of infinite allowance.
Revert if not enough allowance is available.
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual;
_transfer
Moves amount
of tokens from from
to to
.
This internal function is equivalent to {transfer}, and can be used to
e.g. implement automatic token fees, slashing mechanisms, etc.
function _transfer(address from, address to, uint256 amount) internal;
Errors
InsufficientAllowance
error InsufficientAllowance();
InsufficientBalance
error InsufficientBalance();
SharedDecimalsTooLarge
error SharedDecimalsTooLarge();
ZeroAddress
error ZeroAddress();
Contents
Auth
SPDX-License-Identifier: SSPL-1.-0
State Variables
adminsCounter
uint8 adminsCounter;
operators
mapping(address => bool) public operators;
admins
mapping(address => bool) public admins;
Functions
constructor
This constructor sets the initialAdmin address as an admin and operator.
The adminsCounter is incremented unchecked.
constructor(address initialAdmin);
onlyAdmin
modifier onlyAdmin();
onlyOperator
modifier onlyOperator();
addAdmin
addAdmin() function allows an admin to add a new admin to the contract.
This function is only accessible to the existing admins and requires the address of the new admin. If the new admin is already set, the function will revert. Otherwise, the adminsCounter will be incremented and the new admin will be added to the admins mapping. An AdminAdded event will be emitted.
function addAdmin(address newAdmin) external onlyAdmin;
deleteAdmin
Deletes an admin from the list of admins.
Only admins can delete other admins. If the adminsCounter is 0, the transaction will revert.
function deleteAdmin(address oldAdmin) external onlyAdmin;
addOperator
Adds a new operator to the list of operators
Only the admin can add a new operator
function addOperator(address newOperator) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
newOperator | address | The address of the new operator |
deleteOperator
function deleteOperator(address oldOperator) external onlyAdmin;
Events
AdminAdded
event AdminAdded(address indexed newAdmin);
AdminDeleted
event AdminDeleted(address indexed oldAdmin);
OperatorAdded
event OperatorAdded(address indexed newOperator);
OperatorDeleted
event OperatorDeleted(address indexed oldOperator);
Errors
Unauthorized
error Unauthorized();
AlreadySet
error AlreadySet();
NoAdmin
error NoAdmin();
AuthManager
SPDX-License-Identifier: SSPL-1.-0
Periphery contract to unify Auth updates across MevEth, MevEthShareVault and WagyuStaker
deployment address should be added as admin in initial setup
contract addresses are upgradeable. To upgrade auth a redeploy is necessary
State Variables
auth
address public immutable auth;
mevEth
address public mevEth;
mevEthShareVault
address public mevEthShareVault;
wagyuStaker
address public wagyuStaker;
Functions
constructor
constructor(address initialAdmin, address initialMevEth, address initialShareVault, address initialStaker);
onlyAuth
modifier onlyAuth();
updateMevEth
Updates the mevEth address
This function is only callable by the authorized address
function updateMevEth(address newMevEth) external onlyAuth;
Parameters
Name | Type | Description |
---|---|---|
newMevEth | address | The new mevEth address |
updateMevEthShareVault
function updateMevEthShareVault(address newMevEthShareVault) external onlyAuth;
updateWagyuStaker
function updateWagyuStaker(address newWagyuStaker) external onlyAuth;
addAdmin
Adds a new admin to the MevEth, WagyuStaker, and MevEthShareVault contracts.
If the MevEthShareVault is a multisig, the MevEthShareVaultAuthUpdateMissed
event is emitted.
function addAdmin(address newAdmin) external onlyAuth;
deleteAdmin
function deleteAdmin(address oldAdmin) external onlyAuth;
addOperator
function addOperator(address newOperator) external onlyAuth;
deleteOperator
function deleteOperator(address oldOperator) external onlyAuth;
Events
MevEthShareVaultAuthUpdateMissed
emitted when MevEthShareVault is a multisig to log missed auth updates
missed updates will need to be manually added when upgrading from a multisig
event MevEthShareVaultAuthUpdateMissed(address changeAddress, Operation operation);
Errors
Unauthorized
error Unauthorized();
Enums
Operation
enum Operation {
ADDADMIN,
DELETEADMIN,
ADDOPERATOR,
DELETEOPERATOR
}
Contents
BytesLib
SPDX-License-Identifier: SSPL-1.-0
Functions
slice
function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory);
toAddress
toAddress() is a pure function that takes in two parameters, bytes memory _bytes and uint256 _start, and returns an address.
The function first checks if the length of _bytes is greater than or equal to _start + 20. If not, it reverts with an OutOfBounds error. Otherwise, it loads the address from the memory and returns it.
function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address);
toUint8
This function takes in a bytes memory and a uint256 start and returns a uint8.
This function uses assembly to load the memory and return the uint8.
function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8);
toUint64
function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64);
Errors
SliceOverflow
error SliceOverflow();
OutOfBounds
error OutOfBounds();
ExcessivelySafeCall
SPDX-License-Identifier: SSPL-1.-0
Functions
excessivelySafeCall
Use when you really really really don't trust the called contract. This prevents the called contract from causing reversion of the caller in as many ways as we can.
The main difference between this and a solidity low-level call is that we limit the number of bytes that the callee can cause to be copied to caller memory. This prevents stupid things like malicious contracts returning 10,000,000 bytes causing a local OOG when copying to memory.
function excessivelySafeCall(address _target, uint256 _gas, uint16 _maxCopy, bytes memory _calldata) internal returns (bool, bytes memory);
Parameters
Name | Type | Description |
---|---|---|
_target | address | The address to call |
_gas | uint256 | The amount of gas to forward to the remote contract |
_maxCopy | uint16 | The maximum number of bytes of returndata to copy to memory. |
_calldata | bytes | The data to send to the remote contract |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | success and returndata, as .call() . Returndata is capped to _maxCopy bytes. |
<none> | bytes |
MevEth
- State Variables
- stakingPaused
- initialized
- feeDenominator
- pendingStakingModuleCommittedTimestamp
- pendingMevEthShareVaultCommittedTimestamp
- MODULE_UPDATE_TIME_DELAY
- MAX_DEPOSIT
- MIN_DEPOSIT
- mevEthShareVault
- pendingMevEthShareVault
- stakingModule
- pendingStakingModule
- WETH9
- lastRewards
- fraction
- CREAM_TO_MEV_ETH_PERCENT
- creamToken
- lastDeposit
- depositedValidators
- queueLength
- requestsFinalisedUntil
- withdrawalAmountQueued
- withdrawalQueue
- Functions
- constructor
- calculateNeededEtherBuffer
- init
- _stakingUnpaused
- pauseStaking
- unpauseStaking
- commitUpdateStakingModule
- finalizeUpdateStakingModule
- cancelUpdateStakingModule
- commitUpdateMevEthShareVault
- finalizeUpdateMevEthShareVault
- cancelUpdateMevEthShareVault
- createValidator
- grantRewards
- grantValidatorWithdraw
- claim
- processWithdrawalQueue
- asset
- totalAssets
- convertToShares
- convertToAssets
- maxDeposit
- previewDeposit
- _deposit
- deposit
- maxMint
- previewMint
- mint
- maxWithdraw
- previewWithdraw
- _withdraw
- _updateAllowance
- withdraw
- withdrawQueue
- maxRedeem
- previewRedeem
- redeem
- max
- min
- redeemCream
- receive
- transfer
- transferFrom
- Events
- MevEthInitialized
- StakingPaused
- StakingUnpaused
- StakingModuleUpdateCommitted
- StakingModuleUpdateFinalized
- StakingModuleUpdateCanceled
- MevEthShareVaultUpdateCommitted
- MevEthShareVaultUpdateFinalized
- MevEthShareVaultUpdateCanceled
- ValidatorCreated
- Rewards
- ValidatorWithdraw
- WithdrawalQueueOpened
- WithdrawalQueueClosed
- CreamRedeemed
- Structs
Inherits: OFTWithFee, IERC4626, ITinyMevEth
Author: Manifold Finance
SPDX-License-Identifier: SSPL-1.-0
Contract that allows deposit of ETH, for a Liquid Staking Receipt (LSR) in return.
LSR is represented through an ERC4626 token and interface.
State Variables
stakingPaused
Inidicates if staking is paused.
bool public stakingPaused;
initialized
Indicates if contract is initialized.
bool public initialized;
feeDenominator
withdraw fee denominator
uint16 internal constant feeDenominator = 10_000;
pendingStakingModuleCommittedTimestamp
Timestamp when pending staking module update can be finalized.
uint64 public pendingStakingModuleCommittedTimestamp;
pendingMevEthShareVaultCommittedTimestamp
Timestamp when pending mevEthShareVault update can be finalized.
uint64 public pendingMevEthShareVaultCommittedTimestamp;
MODULE_UPDATE_TIME_DELAY
Time delay before staking module or share vault can be finalized.
uint64 internal constant MODULE_UPDATE_TIME_DELAY = 7 days;
MAX_DEPOSIT
Max amount of ETH that can be deposited.
uint128 internal constant MAX_DEPOSIT = type(uint128).max;
MIN_DEPOSIT
Min amount of ETH that can be deposited.
uint128 public constant MIN_DEPOSIT = 0.01 ether;
mevEthShareVault
The address of the MevEthShareVault.
address public mevEthShareVault;
pendingMevEthShareVault
The address of the pending MevEthShareVault when a new vault has been committed but not finalized.
address public pendingMevEthShareVault;
stakingModule
The staking module used to stake Ether.
IStakingModule public stakingModule;
pendingStakingModule
The pending staking module when a new module has been committed but not finalized.
IStakingModule public pendingStakingModule;
WETH9
WETH Implementation used by MevEth.
WETH public immutable WETH9;
lastRewards
Last rewards payment by block number
uint256 internal lastRewards;
fraction
Struct used to accounting the ETH staked within MevEth.
Fraction public fraction;
CREAM_TO_MEV_ETH_PERCENT
The percent out of 1000 crETH2 can be redeemed for as mevEth
uint256 public constant CREAM_TO_MEV_ETH_PERCENT = 1130;
creamToken
The canonical address of the crETH2 address
address public constant creamToken = 0x49D72e3973900A195A155a46441F0C08179FdB64;
lastDeposit
Sandwich protection mapping of last user deposits by block number
mapping(address => uint256) lastDeposit;
depositedValidators
Deposited validators mapping to prevent double deposits
mapping(bytes => bool) depositedValidators;
queueLength
The length of the withdrawal queue.
uint256 public queueLength;
requestsFinalisedUntil
mark the latest withdrawal request that was finalised
uint256 public requestsFinalisedUntil;
withdrawalAmountQueued
Withdrawal amount queued
uint256 public withdrawalAmountQueued;
withdrawalQueue
The mapping representing the withdrawal queue.
The index in the queue is the key, and the value is the WithdrawalTicket.
mapping(uint256 ticketNumber => WithdrawalTicket ticket) public withdrawalQueue;
Functions
constructor
Construction creates mevETH token, sets authority and weth address.
Pending staking module and committed timestamp will both be zero on deployment.
constructor(address authority, address weth, address layerZeroEndpoint) OFTWithFee("Mev Liquid Staked Ether", "mevETH", 18, 8, authority, layerZeroEndpoint);
Parameters
Name | Type | Description |
---|---|---|
authority | address | Address of the controlling admin authority. |
weth | address | Address of the WETH contract to use for deposits. |
layerZeroEndpoint | address | Chain specific endpoint for LayerZero. |
calculateNeededEtherBuffer
Calculate the needed Ether buffer required when creating a new validator.
function calculateNeededEtherBuffer() public view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | uint256 The required Ether buffer. |
init
Initializes the MevEth contract, setting the staking module and share vault addresses.
This function can only be called once and is protected by the onlyAdmin modifier.
function init(address initialShareVault, address initialStakingModule) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
initialShareVault | address | The initial share vault set during initialization. |
initialStakingModule | address | The initial staking module set during initialization. |
_stakingUnpaused
Ensures that staking is not paused when invoking a specific function.
This check is used on the createValidator, deposit and mint functions.
function _stakingUnpaused() internal view;
pauseStaking
Pauses staking on the MevEth contract.
This function is only callable by addresses with the admin role.
function pauseStaking() external onlyAdmin;
unpauseStaking
Unauses staking on the MevEth contract.
This function is only callable by addresses with the admin role.
function unpauseStaking() external onlyAdmin;
commitUpdateStakingModule
Starts the process to update the staking module. To finalize the update, the MODULE_UPDATE_TIME_DELAY must elapse and the finalizeUpdateStakingModule function must be called.
This function is only callable by addresses with the admin role.
function commitUpdateStakingModule(IStakingModule newModule) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
newModule | IStakingModule | The new staking module. |
finalizeUpdateStakingModule
Finalizes the staking module update if a pending staking module exists.
This function is only callable by addresses with the admin role.
function finalizeUpdateStakingModule() external onlyAdmin;
cancelUpdateStakingModule
Cancels a pending staking module update.
This function is only callable by addresses with the admin role.
function cancelUpdateStakingModule() external onlyAdmin;
commitUpdateMevEthShareVault
Starts the process to update the share vault. To finalize the update, the MODULE_UPDATE_TIME_DELAY must elapse and the finalizeUpdateStakingModule function must be called.
This function is only callable by addresses with the admin role
function commitUpdateMevEthShareVault(address newMevEthShareVault) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
newMevEthShareVault | address | The new share vault |
finalizeUpdateMevEthShareVault
Finalizes the share vault update if a pending share vault exists.
This function is only callable by addresses with the admin role.
function finalizeUpdateMevEthShareVault() external onlyAdmin;
cancelUpdateMevEthShareVault
Cancels a pending share vault update.
This function is only callable by addresses with the admin role.
function cancelUpdateMevEthShareVault() external onlyAdmin;
createValidator
This function passes through the needed Ether to the Staking module, and the assosiated credentials with it
This function is only callable by addresses with the operator role and if staking is unpaused
function createValidator(IStakingModule.ValidatorData calldata newData, bytes32 latestDepositRoot) external onlyOperator;
Parameters
Name | Type | Description |
---|---|---|
newData | IStakingModule.ValidatorData | The data needed to create a new validator |
latestDepositRoot | bytes32 |
grantRewards
Grants rewards updating the fraction.elastic.
called from validator rewards updates
function grantRewards() external payable;
grantValidatorWithdraw
Allows the MevEthShareVault or the staking module to withdraw validator funds from the contract.
Before updating the fraction, the withdrawal queue is processed, which pays out any pending withdrawals.
This function is only callable by the MevEthShareVault or the staking module.
function grantValidatorWithdraw() external payable;
claim
Claim Finalised Withdrawal Ticket
function claim(uint256 withdrawalId) external;
Parameters
Name | Type | Description |
---|---|---|
withdrawalId | uint256 | Unique ID of the withdrawal ticket |
processWithdrawalQueue
Processes the withdrawal queue, reserving any pending withdrawals with the contract's available balance.
function processWithdrawalQueue(uint256 newRequestsFinalisedUntil) external onlyOperator;
asset
The underlying asset of the mevEth contract
function asset() external view returns (address assetTokenAddress);
Returns
Name | Type | Description |
---|---|---|
assetTokenAddress | address | The address of the asset token |
totalAssets
The total amount of assets controlled by the mevEth contract
function totalAssets() external view returns (uint256 totalManagedAssets);
Returns
Name | Type | Description |
---|---|---|
totalManagedAssets | uint256 | The amount of eth controlled by the mevEth contract |
convertToShares
Function to convert a specified amount of assets to shares based on the elastic and base.
function convertToShares(uint256 assets) public view returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets to convert to shares |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The value of the given assets in shares |
convertToAssets
Function to convert a specified amount of shares to assets based on the elastic and base.
function convertToAssets(uint256 shares) public view returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares to convert to assets |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The value of the given shares in assets |
maxDeposit
Function to indicate the maximum deposit possible.
function maxDeposit(address) external view returns (uint256 maxAssets);
Returns
Name | Type | Description |
---|---|---|
maxAssets | uint256 | The maximum amount of assets that can be deposited. |
previewDeposit
Function to simulate the amount of shares that would be minted for a given deposit at the current ratio.
function previewDeposit(uint256 assets) external view returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be deposited |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be minted, under ideal conditions only |
_deposit
internal deposit function to process Weth or Eth deposits
function _deposit(address receiver, uint256 assets, uint256 shares) internal;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address user whom should receive the mevEth out |
assets | uint256 | The amount of assets to deposit |
shares | uint256 | The amount of shares that should be minted |
deposit
Function to deposit assets into the mevEth contract
function deposit(uint256 assets, address receiver) external payable returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of WETH which should be deposited |
receiver | address | The address user whom should receive the mevEth out |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares minted |
maxMint
Function to indicate the maximum amount of shares that can be minted at the current ratio.
function maxMint(address) external view returns (uint256 maxShares);
Returns
Name | Type | Description |
---|---|---|
maxShares | uint256 | The maximum amount of shares that can be minted |
previewMint
Function to simulate the amount of assets that would be required to mint a given amount of shares at the current ratio.
function previewMint(uint256 shares) external view returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be minted |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be required, under ideal conditions only |
mint
Function to mint shares of the mevEth contract
function mint(uint256 shares, address receiver) external payable returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that should be minted |
receiver | address | The address user whom should receive the mevEth out |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets deposited |
maxWithdraw
Function to indicate the maximum amount of assets that can be withdrawn at the current state.
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
Parameters
Name | Type | Description |
---|---|---|
owner | address | The address in question of who would be withdrawing |
Returns
Name | Type | Description |
---|---|---|
maxAssets | uint256 | The maximum amount of assets that can be withdrawn |
previewWithdraw
Function to simulate the amount of shares that would be allocated for a specified amount of assets.
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be withdrawn |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be burned, under ideal conditions only |
_withdraw
Function to withdraw assets from the mevEth contract
function _withdraw(bool useQueue, address receiver, address owner, uint256 assets, uint256 shares) internal;
Parameters
Name | Type | Description |
---|---|---|
useQueue | bool | Flag whether to use the withdrawal queue |
receiver | address | The address user whom should receive the mevEth out |
owner | address | The address of the owner of the mevEth |
assets | uint256 | The amount of assets that should be withdrawn |
shares | uint256 | shares that will be burned |
_updateAllowance
internal function to update allowance for withdraws if necessary
function _updateAllowance(address owner, uint256 shares) internal;
Parameters
Name | Type | Description |
---|---|---|
owner | address | owner of tokens |
shares | uint256 | amount of shares to update |
withdraw
Withdraw assets if balance is available
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that should be withdrawn |
receiver | address | The address user whom should receive the mevEth out |
owner | address | The address of the owner of the mevEth |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares burned |
withdrawQueue
Withdraw assets or open queue ticket for claim depending on balance available
function withdrawQueue(uint256 assets, address receiver, address owner) external returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that should be withdrawn |
receiver | address | The address user whom should receive the mevEth out |
owner | address | The address of the owner of the mevEth |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares burned |
maxRedeem
Function to simulate the maximum amount of shares that can be redeemed by the owner.
function maxRedeem(address owner) external view returns (uint256 maxShares);
Parameters
Name | Type | Description |
---|---|---|
owner | address | The address in question of who would be redeeming their shares |
Returns
Name | Type | Description |
---|---|---|
maxShares | uint256 | The maximum amount of shares they could redeem |
previewRedeem
Function to simulate the amount of assets that would be withdrawn for a specified amount of shares.
function previewRedeem(uint256 shares) external view returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that would be burned |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets that would be withdrawn, under ideal conditions only |
redeem
Function to redeem shares from the mevEth contract
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares that should be burned |
receiver | address | The address user whom should receive the wETH out |
owner | address | The address of the owner of the mevEth |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The amount of assets withdrawn |
max
Returns the largest of two numbers.
function max(uint256 a, uint256 b) internal pure returns (uint256);
min
Returns the smallest of two numbers.
function min(uint256 a, uint256 b) internal pure returns (uint256);
redeemCream
Redeem Cream staked eth tokens for mevETH at a fixed ratio
function redeemCream(uint256 creamAmount) external;
Parameters
Name | Type | Description |
---|---|---|
creamAmount | uint256 | The amount of Cream tokens to redeem |
receive
Only Weth withdraw is defined for the behaviour. Deposits should be directed to deposit / mint. Rewards via grantRewards and validator withdraws via grantValidatorWithdraw.
receive() external payable;
transfer
function transfer(address to, uint256 amount) public virtual override returns (bool);
transferFrom
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool);
Events
MevEthInitialized
Event emitted when the MevEth is successfully initialized.
event MevEthInitialized(address indexed mevEthShareVault, address indexed stakingModule);
StakingPaused
Emitted when staking is paused.
event StakingPaused();
StakingUnpaused
Emitted when staking is unpaused.
event StakingUnpaused();
StakingModuleUpdateCommitted
Event emitted when a new staking module is committed. The MODULE_UPDATE_TIME_DELAY must elapse before the staking module update can be finalized.
event StakingModuleUpdateCommitted(address indexed oldModule, address indexed pendingModule, uint64 indexed eligibleForFinalization);
StakingModuleUpdateFinalized
Event emitted when a new staking module is finalized.
event StakingModuleUpdateFinalized(address indexed oldModule, address indexed newModule);
StakingModuleUpdateCanceled
Event emitted when a new pending module update is canceled.
event StakingModuleUpdateCanceled(address indexed oldModule, address indexed pendingModule);
MevEthShareVaultUpdateCommitted
Event emitted when a new share vault is committed. To finalize the update, the MODULE_UPDATE_TIME_DELAY must elapse and the finalizeUpdateMevEthShareVault function must be called.
event MevEthShareVaultUpdateCommitted(address indexed oldVault, address indexed pendingVault, uint64 indexed eligibleForFinalization);
MevEthShareVaultUpdateFinalized
Event emitted when a new share vault is finalized.
event MevEthShareVaultUpdateFinalized(address indexed oldVault, address indexed newVault);
MevEthShareVaultUpdateCanceled
Event emitted when a new pending share vault update is canceled.
event MevEthShareVaultUpdateCanceled(address indexed oldVault, address indexed newVault);
ValidatorCreated
Event emitted when a new validator is created
event ValidatorCreated(address indexed stakingModule, IStakingModule.ValidatorData newValidator);
Rewards
Event emitted when rewards are granted.
event Rewards(address sender, uint256 amount);
ValidatorWithdraw
Emitted when validator withdraw funds are received.
event ValidatorWithdraw(address sender, uint256 amount);
WithdrawalQueueOpened
Event emitted when a withdrawal ticket is added to the queue.
event WithdrawalQueueOpened(address indexed recipient, uint256 indexed withdrawalId, uint256 assets);
WithdrawalQueueClosed
event WithdrawalQueueClosed(address indexed recipient, uint256 indexed withdrawalId, uint256 assets);
CreamRedeemed
event CreamRedeemed(address indexed redeemer, uint256 creamAmount, uint256 mevEthAmount);
Structs
Fraction
Central struct used for share accounting + math.
struct Fraction {
uint128 elastic;
uint128 base;
}
WithdrawalTicket
Struct representing a withdrawal ticket which is added to the withdrawal queue.
struct WithdrawalTicket {
bool claimed;
address receiver;
uint128 amount;
uint128 accumulatedAmount;
}
MevETHRateProvider
Inherits: IRateProvider
SPDX-License-Identifier: SSPL-1.-0
Returns the value of mevETH in terms of ETH
State Variables
mevETH
The address of the mevETH contract
IMevEth public immutable mevETH;
Functions
constructor
Constructs the MevETHRateProvider contract, setting the mevETH address
constructor(IMevEth _mevETH);
getRate
Returns the value of mevETH in terms of ETH
function getRate() external view override returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | the value of mevETH in terms of ETH |
MevEthShareVault
Inherits: Auth, IMevEthShareVault
Author: Manifold Finance
SPDX-License-Identifier: SSPL-1.-0
This contract controls the ETH Rewards earned by mevEth
State Variables
protocolBalance
ProtocolBalance struct to account for the protocol fees and rewards.
ProtocolBalance public protocolBalance;
mevEth
The address of the MevEth contract.
address public mevEth;
protocolFeeTo
The address that protocol fees are sent to.
address public protocolFeeTo;
Functions
constructor
Construction sets authority, MevEth, and averageFeeRewardsPerBlock.
constructor(address authority, address _mevEth, address _protocolFeeTo) Auth(authority);
Parameters
Name | Type | Description |
---|---|---|
authority | address | The address of the controlling admin authority. |
_mevEth | address | The address of the WETH contract to use for deposits. |
_protocolFeeTo | address | The address that protocol fees are sent to. |
payRewards
Function to pay rewards to the MevEth contract
Only callable by an operator.
function payRewards(uint256 rewards) external onlyOperator;
Parameters
Name | Type | Description |
---|---|---|
rewards | uint256 | rewards to pay to the MevEth contract |
sendFees
Function to collect the fees owed to the prorotocol.
function sendFees(uint256 fees) external onlyAdmin;
setProtocolFeeTo
function setProtocolFeeTo(address newProtocolFeeTo) external onlyAdmin;
recoverToken
Function to recover tokens sent to the contract.
This function is only callable by an admin.
function recoverToken(address token, address recipient, uint256 amount) external onlyAdmin;
setNewMevEth
Function to set a new mevEth address.
function setNewMevEth(address newMevEth) external onlyAdmin;
payValidatorWithdraw
Function to pay MevEth when withdrawing funds from a validator
This function is only callable by an admin and emits an event for offchain validator registry tracking.
function payValidatorWithdraw() external onlyOperator;
receive
Function to receive ETH.
receive() external payable;
Events
RewardsCollected
Event emitted when the protocol balance is updated during logRewards
event RewardsCollected(uint256 indexed protocolFeesOwed, uint256 indexed rewardsOwed);
TokenRecovered
Event emitted when a tokens are recovered from the contract.
event TokenRecovered(address indexed recipient, address indexed token, uint256 indexed amount);
ProtocolFeeToUpdated
Event emitted when the protocolFeeTo address is updated.
event ProtocolFeeToUpdated(address indexed newProtocolFeeTo);
FeesSent
Event emitted when the protocol fees are sent to the protocolFeeTo address.
event FeesSent(uint256 indexed feesSent);
RewardsPaid
Event emitted when rewards are paid to the MevEth contract.
event RewardsPaid(uint256 indexed rewards);
MevEthUpdated
Event emitted when the mevEth address is updated.
event MevEthUpdated(address indexed meveth);
ValidatorWithdraw
Event emitted when funds representing a validator withdrawal are sent to the MevEth contract.
event ValidatorWithdraw(address sender, uint256 amount);
Structs
ProtocolBalance
Struct to account for the protocol fees and rewards.
struct ProtocolBalance {
uint128 feesPaid;
uint128 rewardsPaid;
uint128 exitsPaid;
uint128 totalWithdrawn;
}
WagyuStaker
Inherits: Auth, IStakingModule
SPDX-License-Identifier: SSPL-1.-0
This contract stakes Ether inside of the BeaconChainDepositContract directly
State Variables
record
Record of total deposits, withdraws, rewards paid and validators exited
Record public record;
validators
The number of validators on the consensus layer registered under this contract
uint256 public validators;
mevEth
The address of the MevEth contract
address public mevEth;
VALIDATOR_DEPOSIT_SIZE
Validator deposit size.
uint256 public constant override VALIDATOR_DEPOSIT_SIZE = 32 ether;
BEACON_CHAIN_DEPOSIT_CONTRACT
The Canonical Address of the BeaconChainDepositContract
IBeaconDepositContract public immutable BEACON_CHAIN_DEPOSIT_CONTRACT;
Functions
constructor
Construction sets authority, MevEth, and deposit contract addresses
constructor(address _authority, address _depositContract, address _mevEth) Auth(_authority);
Parameters
Name | Type | Description |
---|---|---|
_authority | address | The address of the controlling admin authority |
_depositContract | address | The address of the beacon deposit contract |
_mevEth | address | The address of the mevETH contract |
deposit
Function to deposit funds into the BEACON_CHAIN_DEPOSIT_CONTRACT, and register a validator
function deposit(IStakingModule.ValidatorData calldata data, bytes32 latestDepositRoot) external payable;
payRewards
Function to pay rewards to the MevEth contract
Only callable by an operator
function payRewards(uint256 rewards) external onlyOperator;
Parameters
Name | Type | Description |
---|---|---|
rewards | uint256 | rewards to pay to the MevEth contract |
registerExit
function registerExit() external;
payValidatorWithdraw
Function to pay MevEth when withdrawing funds from a validator
This function is only callable by an operator and emits an event for offchain validator registry tracking.
function payValidatorWithdraw() external onlyOperator;
recoverToken
Function to recover tokens sent to the contract.
This function is only callable by an admin.
function recoverToken(address token, address recipient, uint256 amount) external onlyAdmin;
setNewMevEth
Function to set a new mevEth address.
function setNewMevEth(address newMevEth) external onlyAdmin;
batchMigrate
Batch register Validators for migration
only Admin
function batchMigrate(IStakingModule.ValidatorData[] calldata batchData) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
batchData | IStakingModule.ValidatorData[] | list of each validators' data struct |
receive
Function to receive Ether
receive() external payable;
Events
NewValidator
Event emitted when a validator is registered
event NewValidator(address indexed operator, bytes pubkey, bytes32 withdrawalCredentials, bytes signature, bytes32 deposit_data_root);
TokenRecovered
Event emitted when tokens are recovered from the contract.
event TokenRecovered(address indexed recipient, address indexed token, uint256 indexed amount);
RewardsPaid
Event emitted when rewards are paid to the MevEth contract.
event RewardsPaid(uint256 indexed amount);
ValidatorWithdraw
Event emitted when funds representing a validator withdrawal are sent to the MevEth contract.
event ValidatorWithdraw(address sender, uint256 amount);
MevEthUpdated
Event emitted when the mevEth address is updated.
event MevEthUpdated(address indexed meveth);
Structs
Record
struct Record {
uint128 totalDeposited;
uint128 totalWithdrawn;
uint128 totalRewardsPaid;
uint128 totalValidatorExitsPaid;
}