Withdraw

This section covers the withdraw functions on a Vault. You can do this in 3 ways: through Smart Contract, Through API or through SDK.

Method 1: Smart Contract call

Withdraw

To withdraw assets from the vault, use the withdraw method. Here are the steps to create the transaction:

  1. Prepare parameters:

    • withdraw_shares: The amount of vault shares you wish to withdraw.

    • min_amounts_out: A vector specifying the minimum amounts required to receive before the transaction fails (tolerance). This amount is represented in underlying assets.

    • from: The address of the user performing the withdrawal, who will receive the funds. Represents a Soroban address.

  2. Example arguments transaction:

    {
      "method": "withdraw",
      "params": {
        "withdraw_shares": 500,
        "min_amounts_out": [450],
        "from": "GCINP..."
      }
    }

In code it should look like something like this

let withdraw_args = vec![
            e,
            &withdraw_shares,
            &min_amounts_out,
            &from
        ]
let result = e.try_invoke_contract::(
            &vault_address,
            &Symbol::new(&e, "withdraw"),
            withdraw_args.into_val(e),
    ).unwrap_or_else(|_| {
        panic_with_error!(e, SomeError::SomeError);
    }).unwrap();

If you want to withdraw specifying the underlying asset, you need to do a "simple rule of three".

So first you call total_supply to get the total amount of shares of the vault, then you need to call fetch_total_managed_funds to get the total_amount of the asset

(Note that DeFindex support multiple assets, so if you are using a vault with only one asset, you should take the first element and get the total_amount)

Then, the needed shares to withdraw will be shares_to_withdraw=total_supply*amount_to_withdraw/total_amount


Method 2: Withdraw using API

Withdraws funds from the DeFindex vault.

Method 3: Using SDK

Withdraw from Vault

Remove funds by specifying amounts:

Withdraw by Shares

Remove funds by burning vault shares:

Last updated