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:
interface IMagma {
/**
* @param shares Amount of gMON shares to redeem (e.g., 10).
* @param controller Address designated to manage the claim on behalf of the owner. For simple flows, set to `owner`.
* @param owner Owner of the shares to redeem (e.g., `user`).
* @return requestId Unique identifier of the pending redeem request, used later to claim with `redeem` or `redeemMON`.
*/
function requestRedeem(uint256 shares, address controller, address owner) external returns (uint256 requestId);
/**
* @param account Address whose gMON balance (shares) to query.
* @return shares Current number of gMON shares held by `account`.
* @dev Returns the ERC20 balance of gMON for the address; i.e., the number of shares.
*/
function balanceOf(address account) external view returns (uint256 shares);
}
// Example (request redeem of 10 shares → controller and owner are `user`):
uint256 requestId = IMagma(address(0x)).requestRedeem(10, user, user);After the withdrawal delay has passed, one can finish the redemption in this way:
interface IMagma {
/**
* @param requestId Identifier of the pending redeem request (e.g., from `ownerRequestId(owner)`).
* @param controller Address authorized to complete the redeem for this request.
* @param receiver Address that will receive the withdrawn MON.
* @return assets Amount of MON (in wei) transferred to `receiver` upon successful redeem.
*/
function redeemMON(uint256 requestId, address controller, address receiver) external returns (uint256 assets);
/**
* @param owner Address whose active redeem request id to query.
* @return requestId Current active request id for `owner`, or 0 if none.
*/
function ownerRequestId(address owner) external view returns (uint256 requestId);
}
// Example flow:
// 1) Fetch the user's active request id.
// 2) Redeem MON to the user (controller and receiver are the user).
uint256 requestId = IMagma(address(0x)).ownerRequestId(user);
uint256 assets = IMagma(address(0x)).redeemMON(requestId, user, user);Last updated