fn total_supply(env: soroban_sdk::Env) -> i128
fn allowance(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
) -> i128
fn approve(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
amount: i128,
expiration_ledger: u32,
)
fn balance(env: soroban_sdk::Env, id: soroban_sdk::Address) -> i128
fn transfer(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
to: soroban_sdk::Address,
amount: i128,
)
fn transfer_from(
env: soroban_sdk::Env,
spender: soroban_sdk::Address,
from: soroban_sdk::Address,
to: soroban_sdk::Address,
amount: i128,
)
fn burn(env: soroban_sdk::Env, from: soroban_sdk::Address, amount: i128)
fn burn_from(
env: soroban_sdk::Env,
spender: soroban_sdk::Address,
from: soroban_sdk::Address,
amount: i128,
)
fn decimals(env: soroban_sdk::Env) -> u32
fn name(env: soroban_sdk::Env) -> soroban_sdk::String
fn symbol(env: soroban_sdk::Env) -> soroban_sdk::String
Initializes the DeFindex Vault contract with the required parameters.
This function sets the roles for manager, emergency manager, vault fee receiver, and manager. It also stores the list of assets to be managed by the vault, including strategies for each asset.
assets: List of asset allocations for the vault, including strategies associated with each asset.manager: Primary vault manager with permissions for vault control.emergency_manager: Address with emergency access for emergency control over the vault.vault_fee_receiver: Address designated to receive the vault fee receiver's portion of management fees.vault_fee: Vault-specific fee percentage in basis points (typically set at 0-2% APR).defindex_protocol_receiver: Address receiving DeFindex’s protocol-wide fee in basis points (0.5% APR).factory: Factory contract address for deployment linkage.soroswap_router: Address of the Soroswap routervault_name: Name of the vault token to be displayed in metafn __constructor(
env: soroban_sdk::Env,
assets: soroban_sdk::Vec,
roles: soroban_sdk::Map,
vault_fee: u32,
defindex_protocol_receiver: soroban_sdk::Address,
defindex_protocol_rate: u32,
factory: soroban_sdk::Address,
soroswap_router: soroban_sdk::Address,
name_symbol: soroban_sdk::Map,
upgradable: bool,
)
Handles user deposits into the DeFindex Vault and optionally allocates investments automatically.
This function processes a deposit by transferring each specified asset amount from the user's address to
the vault, allocating assets according to the vault's defined strategy ratios, and minting vault shares that
represent the user's proportional share in the vault. Additionally, if the invest parameter is set to true,
the function will immediately generate and execute investment allocations based on the vault's strategy configuration.
e - The current environment reference (Env), for access to the contract state and utilities.amounts_desired - A vector specifying the user's intended deposit amounts for each asset.amounts_min - A vector of minimum deposit amounts required for the transaction to proceed.from - The address of the user making the deposit.invest - A boolean flag indicating whether to immediately invest the deposited funds into the vault's strategies:fn deposit(
env: soroban_sdk::Env,
amounts_desired: soroban_sdk::Vec,
amounts_min: soroban_sdk::Vec,
from: soroban_sdk::Address,
invest: bool,
) -> Result<
(
soroban_sdk::Vec,
i128,
Option>>,
),
ContractError,
>
Handles the withdrawal process for a specified number of vault shares.
This function performs the following steps:
withdraw_shares) is non-negative.from address.from).e: The contract environment (Env).withdraw_shares: The number of vault shares to withdraw.fn withdraw(
env: soroban_sdk::Env,
withdraw_shares: i128,
from: soroban_sdk::Address,
) -> Result, ContractError>
Executes an emergency withdrawal from a specific strategy.
This function allows the emergency manager or manager to withdraw all assets from a particular strategy and store them as idle funds within the vault. It also pauses the strategy to prevent further use until unpaused.
e - The environment.strategy_address - The address of the strategy to withdraw from.caller - The address initiating the emergency withdrawal (must be the manager or emergency manager).Result<(), ContractError> - Ok if successful, otherwise returns a ContractError.fn rescue(
env: soroban_sdk::Env,
strategy_address: soroban_sdk::Address,
caller: soroban_sdk::Address,
) -> Result<(), ContractError>
Pauses a strategy to prevent it from being used in the vault.
This function pauses a strategy by setting its paused field to true. Only the manager or emergency
manager can pause a strategy.
e - The environment.strategy_address - The address of the strategy to pause.caller - The address initiating the pause (must be the manager or emergency manager).Result<(), ContractError> - Ok if successful, otherwise returns a ContractError.fn pause_strategy(
env: soroban_sdk::Env,
strategy_address: soroban_sdk::Address,
caller: soroban_sdk::Address,
) -> Result<(), ContractError>
Unpauses a previously paused strategy.
This function unpauses a strategy by setting its paused field to false, allowing it to be used
again in the vault.
e - The environment.strategy_address - The address of the strategy to unpause.caller - The address initiating the unpause (must be the manager or emergency manager).Result<(), ContractError> - Ok if successful, otherwise returns a ContractError.fn unpause_strategy(
env: soroban_sdk::Env,
strategy_address: soroban_sdk::Address,
caller: soroban_sdk::Address,
) -> Result<(), ContractError>
Retrieves the list of assets managed by the DeFindex Vault.
e - The environment.Vec<AssetStrategySet> - A vector of AssetStrategySet structs representing the assets managed by the vault.fn get_assets(env: soroban_sdk::Env) -> soroban_sdk::Vec
Returns the total managed funds of the vault, including both invested and idle funds.
This function provides a map where the key is the asset address and the value is the total amount of that asset being managed by the vault.
e - The environment.Map<Address, i128> - A map of asset addresses to their total managed amounts.fn fetch_total_managed_funds(
env: soroban_sdk::Env,
) -> soroban_sdk::Map
This function extends the contract's time-to-live and calculates how much of each asset corresponds
per the provided number of vault shares (vault_shares). It provides proportional allocations for each asset
in the vault relative to the specified shares.
e - The current environment reference.vault_shares - The number of vault shares for which the corresponding asset amounts are calculated.Map<Address, i128> - A map containing each asset address and its corresponding proportional amount.fn get_asset_amounts_per_shares(
env: soroban_sdk::Env,
vault_shares: i128,
) -> Result, ContractError>
Retrieves the current fee rates for the vault and the DeFindex protocol.
This function returns the fee rates for both the vault and the DeFindex protocol.
e - The environment.(u32, u32) - A tuple containing:fn get_fees(env: soroban_sdk::Env) -> (u32, u32)
fn report(env: soroban_sdk::Env) -> Result, ContractError>
Sets the fee receiver for the vault.
This function allows the manager or emergency manager to set a new fee receiver address for the vault.
e - The environment.caller - The address initiating the change (must be the manager or emergency manager).vault_fee_receiver - The new fee receiver address.() - No return value.fn set_fee_receiver(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
new_fee_receiver: soroban_sdk::Address,
)
Retrieves the current fee receiver address for the vault.
e - The environment.Result<Address, ContractError> - The fee receiver address if successful, otherwise returns a ContractError.fn get_fee_receiver(
env: soroban_sdk::Env,
) -> Result
Sets the manager for the vault.
This function allows the current manager to set a new manager for the vault.
e - The environment.new_manager - The new manager address.() - No return value.fn set_manager(
env: soroban_sdk::Env,
new_manager: soroban_sdk::Address,
) -> Result<(), ContractError>
Retrieves the current manager address for the vault.
e - The environment.Result<Address, ContractError> - The manager address if successful, otherwise returns a ContractError.fn get_manager(env: soroban_sdk::Env) -> Result
Sets the emergency manager for the vault.
This function allows the current manager or emergency manager to set a new emergency manager for the vault.
e - The environment.emergency_manager - The new emergency manager address.() - No return value.fn set_emergency_manager(
env: soroban_sdk::Env,
emergency_manager: soroban_sdk::Address,
)
Retrieves the current emergency manager address for the vault.
e - The environment.Result<Address, ContractError> - The emergency manager address if successful, otherwise returns a ContractError.fn get_emergency_manager(
env: soroban_sdk::Env,
) -> Result
Sets the rebalance manager for the vault.
This function allows the current manager to set a new rebalance manager for the vault.
e - The environment.new_rebalance_manager - The new rebalance manager address.() - No return value.fn set_rebalance_manager(
env: soroban_sdk::Env,
new_rebalance_manager: soroban_sdk::Address,
)
Retrieves the current rebalance manager address for the vault.
e - The environment.Result<Address, ContractError> - The rebalance manager address if successful, otherwise returns a ContractError.fn get_rebalance_manager(
env: soroban_sdk::Env,
) -> Result
Upgrades the contract with new WebAssembly (WASM) code.
This function updates the contract with new WASM code provided by the new_wasm_hash.
e - The runtime environment.new_wasm_hash - The hash of the new WASM code to upgrade the contract to.fn upgrade(
env: soroban_sdk::Env,
new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), ContractError>
fn rebalance(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
instructions: soroban_sdk::Vec,
) -> Result<(), ContractError>
Locks fees for all assets and their strategies.
Iterates through each asset and its strategies, locking fees based on new_fee_bps or the default vault fee.
e - The environment reference.new_fee_bps - Optional fee basis points to override the default.Result<Vec<(Address, i128)>, ContractError> - A vector of tuples with strategy addresses and locked fee amounts in their underlying_asset.fn lock_fees(
env: soroban_sdk::Env,
new_fee_bps: Option,
) -> Result, ContractError>
Releases locked fees for a specific strategy.
e - The environment reference.strategy - The address of the strategy for which to release fees.amount - The amount of fees to release.Result<Report, ContractError> - A report of the released fees or a ContractError if the operation fails.fn release_fees(
env: soroban_sdk::Env,
strategy: soroban_sdk::Address,
amount: i128,
) -> Result
Distributes the locked fees for all assets and their strategies.
This function iterates through each asset and its strategies, calculating the fees to be distributed to the vault fee receiver and the DeFindex protocol fee receiver based on their respective fee rates. It ensures proper authorization and validation checks before proceeding with the distribution.
e - The environment reference.caller - The address initiating the fee distribution.Result<Vec<(Address, i128)>, ContractError> - A vector of tuples with asset addresses and the total distributed fee amounts.fn distribute_fees(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
) -> Result, ContractError>
Sorts two token addresses in a consistent order.
token_a - The address of the first token.token_b - The address of the second token.Returns Result<(Address, Address), SoroswapLibraryError> where Ok contains a tuple with the sorted token addresses, and Err indicates an error such as identical tokens.
fn sort_tokens(
env: soroban_sdk::Env,
token_a: soroban_sdk::Address,
token_b: soroban_sdk::Address,
) -> Result<(soroban_sdk::Address, soroban_sdk::Address), SoroswapLibraryError>
Calculates the deterministic address for a pair without making any external calls. check https://github.com/paltalabs/deterministic-address-soroban
e - The environment.factory - The factory address.token_a - The address of the first token.token_b - The address of the second token.Returns Result<Address, SoroswapLibraryError> where Ok contains the deterministic address for the pair, and Err indicates an error such as identical tokens or an issue with sorting.
fn pair_for(
env: soroban_sdk::Env,
factory: soroban_sdk::Address,
token_a: soroban_sdk::Address,
token_b: soroban_sdk::Address,
) -> Result
Fetches and sorts the reserves for a pair of tokens using the factory address.
e - The environment.factory - The factory address.token_a - The address of the first token.token_b - The address of the second token.Returns Result<(i128, i128), SoroswapLibraryError> where Ok contains a tuple of sorted reserves, and Err indicates an error such as identical tokens or an issue with sorting.
fn get_reserves_with_factory(
env: soroban_sdk::Env,
factory: soroban_sdk::Address,
token_a: soroban_sdk::Address,
token_b: soroban_sdk::Address,
) -> Result<(i128, i128), SoroswapLibraryError>
Fetches and sorts the reserves for a pair of tokens using the pair address.
e - The environment.pair - The pair address.token_a - The address of the first token.token_b - The address of the second token.Returns Result<(i128, i128), SoroswapLibraryError> where Ok contains a tuple of sorted reserves, and Err indicates an error such as identical tokens or an issue with sorting.
fn get_reserves_with_pair(
env: soroban_sdk::Env,
pair: soroban_sdk::Address,
token_a: soroban_sdk::Address,
token_b: soroban_sdk::Address,
) -> Result<(i128, i128), SoroswapLibraryError>
Given some amount of an asset and pair reserves, returns an equivalent amount of the other asset.
amount_a - The amount of the first asset.reserve_a - Reserves of the first asset in the pair.reserve_b - Reserves of the second asset in the pair.Returns Result<i128, SoroswapLibraryError> where Ok contains the calculated equivalent amount, and Err indicates an error such as insufficient amount or liquidity
fn quote(
env: soroban_sdk::Env,
amount_a: i128,
reserve_a: i128,
reserve_b: i128,
) -> Result
Given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset.
amount_in - The input amount of the asset.reserve_in - Reserves of the input asset in the pair.reserve_out - Reserves of the output asset in the pair.Returns Result<i128, SoroswapLibraryError> where Ok contains the calculated maximum output amount, and Err indicates an error such as insufficient input amount or liquidity.
fn get_amount_out(
env: soroban_sdk::Env,
amount_in: i128,
reserve_in: i128,
reserve_out: i128,
) -> Result
Given an output amount of an asset and pair reserves, returns a required input amount of the other asset.
amount_out - The output amount of the asset.reserve_in - Reserves of the input asset in the pair.reserve_out - Reserves of the output asset in the pair.Returns Result<i128, SoroswapLibraryError> where Ok contains the required input amount, and Err indicates an error such as insufficient output amount or liquidity.
fn get_amount_in(
env: soroban_sdk::Env,
amount_out: i128,
reserve_in: i128,
reserve_out: i128,
) -> Result
Performs chained get_amount_out calculations on any number of pairs.
e - The environment.factory - The factory address.amount_in - The input amount.path - Vector of token addresses representing the path.Returns Result<Vec<i128>, SoroswapLibraryError> where Ok contains a vector of calculated amounts, and Err indicates an error such as an invalid path.
fn get_amounts_out(
env: soroban_sdk::Env,
factory: soroban_sdk::Address,
amount_in: i128,
path: soroban_sdk::Vec,
) -> Result, SoroswapLibraryError>
Performs chained get_amount_in calculations on any number of pairs.
e - The environment.factory - The factory address.amount_out - The output amount.path - Vector of token addresses representing the path.Returns Result<Vec<i128>, SoroswapLibraryError> where Ok contains a vector of calculated amounts, and Err indicates an error such as an invalid path.
fn get_amounts_in(
env: soroban_sdk::Env,
factory: soroban_sdk::Address,
amount_out: i128,
path: soroban_sdk::Vec,
) -> Result, SoroswapLibraryError>