🟢mint_with_mercurial_vault_depository
Permissionless - Callable for collateral amount input larger than 0 and below global cap and depository cap when minting is enabled
Flow
Checks
Anchor IDL accounts checks
Validates: non-zero
collateral_amount
Validates:
mint_disabled
is false for the depository
Handler
Calculates the possible precision loss on transferred LP token amounts
Deposits
collateral_amount
from user collateral's ATA to mercurial token vault in return for the LP tokens through CPI:mercurial_vault::cpi::deposit
Calculates the LP token minted by comparing the balance change of
depository_lp_token_vault
Checks if the LP token minted is not below the
collateral_amount
considering the possible precision loss, abort with slippage error otherwiseCalculates the total mint fee based on the amount of the LP token minted
Checks if the redeemable amount (same as the LP token minted) after deducting the mint fee is positive
Mint the redeemable amount (less fee) of
redeemable_mint
to the userUpdates the accounting in both
depository
andcontroller
Parameters
collateral_amount
the amount of collateral to be processed through minting
Accounts in
// ...
/// Takes 20 accounts
#[derive(Accounts)]
pub struct MintWithMangoDepository<'info> {
/// #1 Public call accessible to any user
pub user: Signer<'info>,
/// #2
#[account(mut)]
pub payer: Signer<'info>,
/// #3 The top level UXDProgram on chain account managing the redeemable mint
#[account(
mut,
seeds = [CONTROLLER_NAMESPACE],
bump = controller.load()?.bump,
constraint = controller.load()?.registered_mango_depositories.contains(&depository.key()) @UxdError::InvalidDepository,
has_one = redeemable_mint @UxdError::InvalidRedeemableMint
)]
pub controller: AccountLoader<'info, Controller>,
/// #4 UXDProgram on chain account bound to a Controller instance.
/// The `MangoDepository` manages a MangoAccount for a single Collateral.
#[account(
mut,
seeds = [MANGO_DEPOSITORY_NAMESPACE, depository.load()?.collateral_mint.as_ref()],
bump = depository.load()?.bump,
has_one = controller @UxdError::InvalidController,
has_one = mango_account @UxdError::InvalidMangoAccount,
)]
pub depository: AccountLoader<'info, MangoDepository>,
/// #5 The redeemable mint managed by the `controller` instance
/// Tokens will be minted during this instruction
#[account(
mut,
seeds = [REDEEMABLE_MINT_NAMESPACE],
bump = controller.load()?.redeemable_mint_bump,
)]
pub redeemable_mint: Box<Account<'info, Mint>>,
/// #6 The `user`'s TA for the `depository` `collateral_mint`
/// Will be debited during this instruction
#[account(
mut,
constraint = user_collateral.mint == depository.load()?.collateral_mint @UxdError::InvalidCollateralMint,
constraint = &user_collateral.owner == user.key @UxdError::InvalidOwner,
)]
pub user_collateral: Box<Account<'info, TokenAccount>>,
/// #7 The `user`'s TA for the `controller`'s `redeemable_mint`
/// Will be credited during this instruction
#[account(
mut,
constraint = user_redeemable.mint == controller.load()?.redeemable_mint @UxdError::InvalidRedeemableMint,
constraint = &user_redeemable.owner == user.key @UxdError::InvalidOwner,
)]
pub user_redeemable: Box<Account<'info, TokenAccount>>,
/// #8 The MangoMarkets Account (MangoAccount) managed by the `depository`
/// CHECK : Seeds checked. Depository registered
#[account(
mut,
seeds = [MANGO_ACCOUNT_NAMESPACE, depository.load()?.collateral_mint.as_ref()],
bump = depository.load()?.mango_account_bump,
)]
pub mango_account: AccountInfo<'info>,
/// #9 [MangoMarkets CPI] Index grouping perp and spot markets
/// CHECK: Mango CPI - checked MangoMarketV3 side
pub mango_group: UncheckedAccount<'info>,
/// #10 [MangoMarkets CPI] Cache
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_cache: UncheckedAccount<'info>,
/// #11 [MangoMarkets CPI] Root Bank for the `depository`'s `collateral_mint`
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_root_bank: UncheckedAccount<'info>,
/// #12 [MangoMarkets CPI] Node Bank for the `depository`'s `collateral_mint`
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_node_bank: UncheckedAccount<'info>,
/// #13 [MangoMarkets CPI] Vault for the `depository`'s `collateral_mint`
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_vault: UncheckedAccount<'info>,
/// #14 [MangoMarkets CPI] `depository`'s `collateral_mint` perp market
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_perp_market: UncheckedAccount<'info>,
/// #15 [MangoMarkets CPI] `depository`'s `collateral_mint` perp market orderbook bids
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_bids: UncheckedAccount<'info>,
/// #16 [MangoMarkets CPI] `depository`'s `collateral_mint` perp market orderbook asks
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_asks: UncheckedAccount<'info>,
/// #17 [MangoMarkets CPI] `depository`'s `collateral_mint` perp market event queue
/// CHECK: Mango CPI - checked MangoMarketV3 side
#[account(mut)]
pub mango_event_queue: UncheckedAccount<'info>,
/// #18 System Program
pub system_program: Program<'info, System>,
/// #19 Token Program
pub token_program: Program<'info, Token>,
/// #20 MangoMarketv3 Program
pub mango_program: Program<'info, MangoMarketV3>,
}
// ...
Last updated
Was this helpful?