Smart Contract
Contract Information(magETH.sol)
Solidity Version: 0.8.10
State Variables
asset:
Type:
ERC20
Description: Represents the ERC20 token that users supply to the vault.
Code:
ERC20 public immutable asset
pollToken:
Type:
address
Description: Represents the pool token of the Morpho supply pool.
Code:
address immutable pollToken
stEthToken:
Type:
ERC20
Description: Represents the StEth token.
Code:
ERC20 immutable stEthToken
morpho:
Type:
IMorpho
Description: Represents the Morpho protocol contract.
Code:
IMorpho immutable morpho
lens:
Type:
ILens
Description: Represents the Morpho Lens contract.
Code:
ILens immutable lens
AGGREGATION_ROUTER_V5:
Type:
address
Description: Represents the 1inch V5 Router contract address.
Code:
address immutable AGGREGATION_ROUTER_V5
borrowPoolToken:
Type:
address
Description: Represents the pool token of the Morpho borrow pool.
Code:
address immutable borrowPoolToken
WETH9:
Type:
IWETH9
Description: Represents the WETH9 contract.
Code:
IWETH9 immutable WETH9
governance:
Type:
address
Description: Represents the current governance of the contract.
Code:
address public governance
pendingGovernance:
Type:
address
Description: Represents the new governance when a governance change is proposed.
Code:
address public pendingGovernance
rewardDistributor:
Type:
IRewardsDistributor
Description: Represents the contract responsible for distributing rewards.
Code:
IRewardsDistributor public rewardDistributor
degenScoreBeacon:
Type:
IDegenScoreBeacon
Description: Represents the Degen Score Beacon contract.
Code:
IDegenScoreBeacon immutable degenScoreBeacon
cap:
Type:
uint
Description: The total allowable deposit amount or vault limit.
Code:
uint public cap
degenCap:
Type:
uint
Description: The total allowable deposit amount for users with a certain Degen Score.
Code:
uint public deganCap
traitId:
Type:
uint256
Description: A trait ID used in the context of Degen Scores.
Code:
uint256 private traitId
maxAge:
Type:
uint64
Description: The maximum age of Degen.
Code:
uint64 private maxAge
vaultsLeverage:
Type:
Leverage
Description: An enum variable representing the vault's leverage (One, Two, or Three).
Code:
Leverage public vaultsLeverage
Modifiers
onlyGovernance: Ensures that only the governance address can execute certain functions.
onlyEOA: Ensures that only externally owned accounts (EOAs) can execute certain functions.
Events
PendingGovernance(address indexed governance)
: Emitted when a new governance address is proposed.GovernanceAccepted(address indexed newGovernance)
: Emitted when a proposed governance change is accepted.RewardsClaimed(address account, uint256 amount)
: Emitted when a user claims rewards.
Enums
Operation: An enum representing various vault operations, such as opening a position, closing a position, deleveraging, leveraging, and reinvesting idle WETH.
Leverage: An enum representing different levels of leverage (One, Two, Three).
MAGETH FUNCTIONS
Internal Functions:
Swap:
function swap(bytes memory _data) internal returns(uint)
This is an internal function that swaps two tokens using 1inchV5.
Name | Type | Description |
_data | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
TotalAssets:
function totalAssets() internal view override returns (uint256)
This function returns the total amount of underlying assets held by the vault.
previewDeposit:
function previewDeposit(uint256 assets) internal view override returns (uint256)
This function allows users to simulate the effects of their deposit at the current block.
Name | Type | Description |
assets | uint256 | Amount of ETH user wants to deposit |
previewRedeem:
function previewRedeem(uint256 shares) internal view override returns (uint256)
This function allows users to simulate the effects of their deposit at the current block.
Name | Type | Description |
shares | uint256 | Amount of share user wants to redeem |
External Functions:
maxDeposit:
function maxDeposit(address) external pure override returns (uint256)
Maximum amount of the underlying asset that can be deposited into the Vault for the receiver, through a deposit call.deposit:
function deposit(uint256 assets, address receiver, bytes calldata _data1) external payable onlyEOA nonReentrant override returns (uint256 shares)
This function Mints shares Vault shares to the receiver by depositing assets of underlying tokens.
Name | Type | Description |
assets | uint256 | Amount of asset user wants to deposit |
receiver | address | Address of share receiver |
_data1 | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
withdraw:
function withdraw(uint256 shares, address receiver, address owner, bytes calldata _data1) external nonReentrant onlyEOA override returns(uint256 assets)
Burns shares from the owner and sends exact assets of underlying tokens to the receiver.
Name | Type | Description |
shares | uint256 | Amount of share user want to burn |
receiver | address | Address of asset receiver |
Owner | address | Address of the owner of shares |
_data1 | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
executeOperation:
function executeOperation(address[] calldata assets, uint[] calldata amounts, uint[] calldata premiums, address initiator, bytes calldata params) external override returns (bool)
The function is designed to be called by the Aave lending pool contract and executes a specific operation on behalf of the caller. The function is designed to be called by the Aave lending pool contract and executes a specific operation on behalf of the caller. There are four possible operation types that are deposit, withdraw, deleverage and leverage.
Name | Type | Description |
assets | address[] | An array of addresses representing the assets to be borrowed. |
amounts | uint[] | An array of unsigned integers representing the amounts of each asset to be borrowed. |
premiums | uint[] | An array of unsigned integers representing the premiums associated with each asset |
initaitor | address | An Ethereum address representing the initiator of the operation |
params | bytes | Params in bytes data format |
deleverage:
function deleverage(uint amount, bytes calldata _data1) external nonReentrant onlyGovernance
Deleverage function can only be called by governance and it is used to deleverage the vault. (for example: 3x leverge to 2x leverage)
Name | Type | Description |
amount | uint256 | amount of Weth that must be repaid to the morpho in order to deleverage the vault. |
_data1 | bytes | Data representing swap route and swap data (taken from 1inch external API call). |
leverage:
function leverage(uint amount, bytes calldata _data1) external nonReentrant onlyGovernance
Leverage function can only be called by governance and it is used to leverage the vault (Vault works 3 leverage value).
Name | Type | Description |
amount | uint256 | amount of WETH need to borrow to leverage the vault |
_data1 | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
harvest:
function harvest(uint amount, bytes calldata _data1)external onlyGovernance
Harvest function can only be called by governance and it is used to help maintain the desired level of leverage for the vault. Specifically, if the vault has generated profits from supplying stETH, its leverage may fluctuate from the intended level, and the "harvest" function can be used to re-balance the position and bring the leverage to the desired level.
Name | Type | Description |
amount | uint | Amount of stETH to harvest |
_data1 | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
assetOf:
function assetsOf(address user) external view override returns (uint256)
This function returns total assets of user.
Name | Type | Description |
user | address | Address of user whose total asset we want in return |
assetsPerShare:
function assetsPerShare() external view override returns (uint256)
This function returns the current value of the assets per share, which is determined by dividing the current total assets in the pool by the total number of shares.maxMint:
function maxMint(address) external pure override returns (uint256)
Maximum amount of shares that can be minted from the Vault for the receiver, through a mint call.maxWithdraw:
function maxWithdraw(address owner) external view override returns (uint256)
Maximum amount of the underlying asset that can be withdrawn from the owner balance in the Vault, through a withdraw call.
Name | Type | Description |
owner | address | Address of owner |
maxRedeem:
function maxRedeem(address owner) external view override returns (uint256)
Maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, through a redeem call.
Name | Type | Description |
owner | address | Address of owner |
setGovernance:
function setGovernance(address _governance) external onlyGovernance
This function is an external method that can only be called by the current governance entity. Its purpose is to update the address of the pending governance entity. The function takes a single parameter,_governance
which represents the address of the new governance entity.
Name | Type | Description |
_goverance | address | Address of new governance |
acceptGovernance:
function acceptGovernance() external
This function is used in conjunction with the "setGovernance" function, allowing for a smooth and secure transition of governance control from one entity to another. This function is used for accepting current governance ownership and it is only called by pending governance.setCap:
function setCap(uint _cap)external onlyGovernance
This function should be called by the existing governance address and it is used to set the cap (cap is the vault limit or allowable deposit amount for non-beacon users).
Name | Type | Description |
_cap | uint | Total vault limit or cap |
setDegenCap:
function setDegenCap(uint _cap) external onlyGovernance
This function should be called by the existing governance address and it is used to set the cap (cap is the total vault limit or total allowable deposit).
Name | Type | Description |
_cap | uint | Vault capacity for Beacon holders |
setRewardDistributor:
function setRewardDistributor(address _rewardDistributor)external onlyGovernance
This function sets the address of the reward distributor contract which distributes morpho rewards to the magETH holder.
Name | Type | Description |
_rewardDistributor | address | address of the reward distributor contract |
setTraitIdAndMaxAge:
function setTraitIdAndMaxAge(uint256 _traitId, uint64 _maxAge)external onlyGovernance
This function sets the traitID and max age of the beacon. So that beacon holder that has traitID and max age will be eligible for the extra cap (DegenCap).
Name | Type | Description |
_traitId | uint256 | traitID of the beacon |
_maxAge | uint64 | Max age of the beacon |
WrapIdelEthToWeth:
function WrapIdelEthToWeth(uint amount)external onlyGovernance
This function wraps the input ETH amount which is idle in the vault contract.
Name | Type | Description |
amount | uint | Amount of ETH to wrap |
reinvestIdleSteth:
function reinvestIdleSteth(uint amount)external onlyGovernance
This function can only be called by governance to reinvest the idle stETH of the vault on morpho
Name | Type | Description |
amount | uint | Amount of stETH to reinvest in vault |
reinvestIdle:
function reinvestIdle(uint amount, bytes calldata _data)external onlyGovernance
This function can only be called by governance to reinvest the idle WETH of the vault on morpho.
Name | Type | Description |
amount | uint | Amount of WETH to reinvest in vault |
claimReward:
function claimReward(address _account, uint _claimable, bytes32[] calldata _proof)external
This function is used by magETH holders to claim morpho tokens. This function verifies whether the caller can claim morpho tokens using Merkle tree proofs.
Name | Type | Description |
_account | address | Address of reward claimer |
_claimable | uint | Morpho reward amount to claim |
_proof | bytes32[ | Merkle tree proof that proofs that account can claim input claimable amount. |
convertToShares:
function convertToShares(uint256 assets) public view returns (uint256)
This function returns the amount of shares that the Vault would exchange for the amount of assets provided.
Name | Type | Description |
assets | uint256 | Amount of assets |
convertToAssets:
function convertToAssets(uint256 shares) public view returns (uint256)
This function returns amount of assets that the Vault would exchange for the amount of shares provided.
Name | Type | Description |
shares | uint256 | Amount of shares |
convertToSupply:
function convertToSupply(uint256 assets) public view returns (uint256 supplyAmount, uint256 borrowAmount)
This function gives amount of supply token and borrow token required to remove in order to remove input assets amount from morpho position by keeping the leverage same.
Name | Type | Description |
assets | uint256 | Amount of assets |
getVaultsActualBalance:
function getVaultsActualBalance() public view returns(uint amount)
This function gives the theoretical amount of stETH that vault will have after paying all the borrowed Weth on morpho.getborrowedAmountForDeleverage:
function getborrowedAmountForDeleverage() public view returns(uint amount)
This function returns the amount of borrowed WETH needs to repay to deleverage the vault.getborrowedAmountForLeverage:
function getborrowedAmountForleverage() public view returns(uint amount)
This function returns the amount of borrowed WETH needs to supply to leverage the vault.getHarvestAmount:
function getHarvestAmount() public view returns(uint amount)
This function returns the amount of stETH that needs supply and Weth needs to borrow in order to re-balance the vault position on morpho and bring the leverage to the desired level.
Private Functions:
triggerFlashLoan:
function triggerFlashLoan(uint8 operation, uint amount, bytes calldata _data1, address _receiver)private
The triggerFlashLoan function is a private function that is used to trigger a flash loan from the Aave lending pool. The flash loan can be used to perform various operations like opening or closing positions, deleveraging, or leveraging. The function takes four parameters: operation from enum operation, amount, _data1 which is the data required for swap, and _receiver.
Name | Type | Description |
operation | uint8 | operation can be numbers ranging from 0 to 3, 0 representing deposit, 1 representing withdraw, 2 representing deleverage, and 3 representing leverage. |
amount | uint | Flashloan Amount of WETH |
_data1 | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
_receiver | address | Address of receiver for withdrawal operation. |
_open1xLeverage:
function _open1xLeverage(uint amount, bytes calldata data, address receiver)private
This function is used in the deposit function when the vault’s current leverage is 1x. This function deposit asset on morpho by supply without borrowing any WETH.
Name | Type | Description |
amount | uint | amount of ETH supplied by user |
data | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
receiver | address | Address of receiver |
_close1xLeverage:
function _close1xLeverage(uint amount, bytes calldata data, address _receiver) private
This function is used in the withdraw function when the vault’s current leverage is 1x. This function withdraws the amount of stETH from morpho and converts it into WETH. Then it transfers the ETH to the receiver by unwrapping the WETH.
Name | Type | Description |
amount | uint | amount of stETH to remove |
data | bytes | Data representing swap route and swap data (taken from 1inch external API call) |
_receiver | address | Address of receiver |
Last updated