The rust-client provides a convenient way to interact with the DAMM v2 program and get swap quotes.Before you begin, here are some important resources:
Program ID (Mainnet & Devnet):24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi
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.
Copy
Ask AI
// Total unlocked amount in the vault available for withdrawal// current_time is current Solana node timestamptotal_unlocked_amount = vault_data.get_unlocked_amount(current_time)
We currently keep 10% of the total deposits in the vault to support swaps and immediate withdrawals.
Copy
Ask AI
// 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
Copy
Ask AI
// 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())?;
Retrieve the vault, token_vault, lp_mint, user_token and user_lp values
Copy
Ask AI
// 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())?;
You can retrieve the list of pubkeys of the lending platform pools integrated with the vault
Copy
Ask AI
// 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);}
Call the function to withdraw funds from the selected strategy pool
Copy
Ask AI
// 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,)?