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.
e - The environment reference.assets - List of asset allocations for the vault, including strategies for each asset.roles - Map of role IDs to addresses containing:vault_fee - Vault-specific fee in basis points (0_2000 for 0.20%)defindex_protocol_receiver - Address receiving protocol feesdefindex_protocol_rate - Protocol fee rate in basis points (0-9000 for 0-90%)soroswap_router - Soroswap router addressname_symbol - Map containing:upgradable - Boolean flag for contract upgradeabilityfn __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,
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 and mints 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:true: Generate and execute investments after the deposit.false: Leafn 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 user withdrawals from the DeFindex Vault by burning shares and returning assets.
This function processes a withdrawal request by burning the specified amount of vault shares and returning a proportional amount of the vault's assets to the user. It can unwind positions from strategies if necessary to fulfill the withdrawal.
e: The contract environment (Env).withdraw_shares: The number of vault shares to withdraw.min_amounts_out: A vector of minimum amounts required for each asset to be withdrawn.from: The address initiating the withdrawal.Result<Vec<i128>, ContractError> - On success, returns a vector of withdrawn amounts
where each index corresponds to the asset index in the vault's asset list.
Returns ContractError if the withdrawal fails.ContractError::AmountOverTotalSupply: If the specified shares exceed the total supply.ContractError::ArithmeticError: If any arithmetic operation fails during calculations.fn withdraw(
env: soroban_sdk::Env,
withdraw_shares: i128,
min_amounts_out: soroban_sdk::Vec,
from: soroban_sdk::Address,
) -> Result, ContractError>
Executes rescue (formerly 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> - Success (()) or ContractError if the rescue operation failsfn 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> - Success (()) or ContractError if the pause operation failsfn 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,
) -> Result, ContractError>
Returns the total managed funds of the vault, including both invested and idle funds.
This function provides a vector of CurrentAssetInvestmentAllocation structs containing information
about each asset's current allocation, including both invested amounts in strategies and idle amounts.
e - The environment.Result<Vec<CurrentAssetInvestmentAllocation>, ContractError> - A vector of asset allocations or errorfn fetch_total_managed_funds(
env: soroban_sdk::Env,
) -> Result, ContractError>
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.Result<Vec<i128>, ContractError> - A vector of asset amounts corresponding to the vault shares, where each index
matches the asset index in the vault's asset list. Returns ContractError if calculation fails.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)
Generates reports for all strategies in the vault, tracking their performance and fee accrual.
This function iterates through all assets and their associated strategies to generate performance reports. It updates each strategy's report with current balances and calculates gains or losses since the last report.
e - The environment reference.Result<Vec<Report>, ContractError> - On success, returns a vector of reports
where each report contains performance metrics for a strategy. Returns
ContractError if report generation fails.Reports track:
fn report(env: soroban_sdk::Env) -> Result, ContractError>
Sets the fee receiver for the vault.
This function allows the manager or the vault fee receiver to set a new fee receiver address for the vault.
e - The environment.caller - The address initiating the change (must be the manager or the vault fee receiver).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.Result<(), ContractError> - Success (()) or ContractError if the manager change failsfn 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 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.Result<(), ContractError> - Returns Ok(()) on success, ContractError if upgrade failsfn upgrade(
env: soroban_sdk::Env,
new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), ContractError>
Rebalances the vault by executing a series of instructions.
e - The environment.instructions - A vector of Instruction structs representing actions (withdraw, invest, swap, zapper) to be taken.Result<(), ContractError> - Ok if successful, otherwise returns a 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>