Get the total amount of tokens that are available for withdrawal. The vault will lock the yield claimed initially and release them over a pre-defined period of time.
// Total unlocked amount in the vault available for withdrawal// current_time is current Solana node timestamptotal_unlocked_amount = vault_state.get_unlocked_amount(current_time)
We currently keep 10% of the total deposits in the vault to support swaps and immediate withdrawals.
// Get the vault reserve value// Get the token vault datalet token_data: anchor_spl::token::TokenAccount = program_client.account(vault_data.token_vault)?;vault_reserves = token_data.amount //vault reserve value
Retrieve the vault, token_vault, lp_mint, user_token and user_lp values
// Retrieve the value for vault// You can use the one of our supported token_mints (you can find the token_mint values in the "Constants" sectionlet (vault, _vault_bump) = Pubkey::find_program_address( &[b"vault".as_ref(), token_mint.as_ref(), mercurial_vault::get_base_key().as_ref()], &mercurial_vault::id(),);// Retrieve the value of token_vaultlet (token_vault, _token_vault_bump) = Pubkey::find_program_address( &[b"token_vault".as_ref(), vault.as_ref()], &program_client.id(),);//Retrieve the value of vault_state to get the lp_mint valuelet vault_state: mercurial_vault::state::Vault = program_client.account(vault)?;let lp_mint = vault_state.lp_mint;// Retrieve user_token and user_lp values using the get_or_create_ata fnlet user_token = get_or_create_ata(program_client, token_mint, program_client.payer())?;let user_lp = get_or_create_ata(program_client, lp_mint, program_client.payer())?;
2
Execute the instruction to deposit liquidity into the pool
let builder = program_client .request() .accounts(mercurial_vault::accounts::DepositWithdrawLiquidity { vault, token_vault, lp_mint, user_token, user_lp, user: program_client.payer(), token_program: spl_token::id(), }) .args(mercurial_vault::instruction::Deposit { token_amount, // total amount of tokens to be deposited minimum_lp_token_amount: 0, });let signature = builder.send()?;
Retrieve the vault, token_vault, lp_mint, user_token and user_lp values
// Retrieve the vaultlet (vault, _vault_bump) = Pubkey::find_program_address( &[b"vault".as_ref(), token_mint.as_ref(), mercurial_vault::get_base_key().as_ref()], &mercurial_vault::id(),);// Retrieve the vault of token_vaultlet (token_vault, _token_vault_bump) = Pubkey::find_program_address( &[b"token_vault".as_ref(), vault.as_ref()], &program_client.id(),);//Retrieve the value of vault_state to get the lp_mint valuelet vault_state: mercurial_vault::state::Vault = program_client.account(vault)?;let lp_mint = vault_state.lp_mint;// Retrieve user_token and user_lp values using the get_or_create_ata fnlet user_token = get_or_create_ata(program_client, token_mint, program_client.payer())?;let user_lp = get_or_create_ata(program_client, lp_mint, program_client.payer())?;
2
Execute the instruction to withdraw liquidity from pool
If you are integrating the vaults directly onto your platform, you can use this function to withdraw funds directly from a selected lending platform.
1
Retrieve the list of pubkeys of the lending platform pools integrated with the vault
// Get the vault pubkey using the token_mint of the vaultlet (vault, _) = Pubkey::find_program_address( &[b"vault".as_ref(), token_mint.as_ref(), mercurial_vault::get_base_key().as_ref()], &mercurial_vault::id(),);// Retrieve the vault statelet vault_data: mercurial_vault::state::Vault = program_client.account(vault)?;// Iterate through all the lending platform pools integrated with the vaultfor (i, &strategy_pubkey) in vault_data.strategies.iter().enumerate(){ // get strategy pubkey println!("{}", strategy_pubkey);}
2
Call the function to withdraw funds from the selected strategy pool
// Get the strategy_state using the strategy_pubkeylet strategy_state: mercurial_vault::state::Strategy = program_client.account(strategy_pubkey)?;// Call the fn to withdraw funds directly from the strategylet strategy_handler = get_strategy_handler(strategy_state.strategy_type);strategy_handler.withdraw_directly_from_strategy( &program_client, strategy, token_mint, base, unmint_amount,)?