🟒redeem_from_mercurial_vault_depository

Permissionless - Callable for redeemable 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 redeemable_amount

  • Handler

    • Calculates to total redeem fee based on the redeemable_amount

    • Calculates the LP token amount for withdraw with the redeemable_amount after deducting the redeem fee

    • Calculates the possible precision loss on transferred LP token amounts

    • Withdraws collateral_mint using LP token amount (less fee) from mercurial token vault to user collateral's ATA in return for the through CPI: mercurial_vault::cpi::withdraw

    • Calculates the collateral withdrawn by comparing the balance change of user_collateral

    • Calculates the redeemed LP token by comparing the balance change of depository_lp_token_vault

    • Checks if the redeemed LP token equals to the LP token amount for withdraw (less fee), abort with slippage error otherwise

    • Checks if the collateral withdrawn is not below the target redeemable amount (less fee) considering the possible precision loss, abort with slippage error otherwise

    • Burns the redeemable amount of redeemable_mint from the user

    • Updates the accounting in both depository and controller

Parameters

redeemable_amount - the amount of redeemable to be redeemed into collateral

Accounts in

Last updated

Was this helpful?