Smart contract integration
How to deposit into Magma
There are multiple ways to deposit MON or WMON into Magma via different functions.
interface _IMagma {
function deposit(uint256 assets, address receiver) external returns (uint256);
function depositWMON(uint256 assets, address receiver, uint256 referralId) external returns (uint256);
function depositWMONGVault(uint256 assets, address receiver, uint64 valId, uint256 referralId)
external
returns (uint256);
function mint(uint256 shares, address receiver) external returns (uint256);
function depositMON(address receiver, uint256 referralId) external payable returns (uint256 shares);
function depositMONGVault(address receiver, uint64 valId, uint256 referralId)
external
payable
returns (uint256 shares);
}The following is an example of how to deposit 10 MON into Magma to obtain the corresponding gMON shares. It will be a deposit with no referral, meaning the referral ID should be 0.
interface IMagma {
/**
* @param receiver Address that will receive the minted gMON.
* @param referralId Referral identifier for points attribution. Use 0 if none.
* @dev msg.value (MON): Native MON amount sent with the call (in wei). Example: 10 ether = 10 MON.
* @return Amount of gMON minted to `receiver` based on the current exchange rate.
*/
function depositMON(address receiver, uint256 referralId) external payable returns (uint256 shares);
}
// Example (deposit 10 MON → mint gMON to `user` with referralId = 0):
uint256 shares = IMagma(address(0x)).depositMON{ value: 10 ether }(user, 0);How to redeem gMON from Magma
In relation to redemptions, there is the possibility to redeem both to MON or WMON. This example focuses on the redemption from gMON to MON in Magma, which follows a 2-step process. To unstake on Monad, one has to undelegate the stake first, then withdraw the undelegated stake after WITHDRAWAL_DELAY epochs have passed. This is done respectively in our requestRedeem and redeemMon functions.
To request a redemption, this example should work as a reference:
After the withdrawal delay has passed, one can finish the redemption in this way:
Last updated