Contract ae3409a4090bc087b86b4e9b444d2b8017ccd97b90b069d44d005ab9f8e1468b

← Back to Index 📥 Download WASM

Meta

rssdkver 22.0.6#0c47dcfa187069d241f11fb082730f667b55e802
rsver 1.85.0

Instances

  • CA27MPQ4NIZ6CGUXV5LY2DVMXVYCUC5SWVIZES4DSUQJZUNB7W5SNCUG
  • CA2FIPJ7U6BG3N7EOZFI74XPJZOEOD4TYWXFVCIO5VDCHTVAGS6F4UKK
  • CA3GTBI7INMFEF3LFY2TVQQP72CZA3LHFLHCCVIUCEGLURCE3J5YAFID
  • CA5RG7DCLMNJFRMG3LP2VDUBWCZ4QTZ776VCEQKWBPGDUAJAT26K2OXM
  • CA7AURROFFMNWA4GE6LUEBXNIGUUGSSQYDCEBGJVUXL3UZZ4JHH7NGYC
  • CAFIN4DOSWRGSZO454VKGTVUQRZ4IEJMJJZKOND3Z3HWDY7YC6YY7JLF
  • CAGLV2DZBRSHSNPECBTUMSU7OPGIWVGCUON35K273TX4JY4YI5E5AF4D
  • CAGP3V7WKOJX2W3J24OZQRTGPZFPW2DXVIHY2TDP7CUPM6CKAL5WR4LU
  • CAIZ3NMNPEN5SQISJV7PD2YY6NI6DIPFA4PCRUBOGDE4I7A3DXDLK5OI
  • CAQ6PAG4X6L7LJVGOKSQ6RU2LADWK4EQXRJGMUWL7SECS7LXUEQLM5U7
  • CARJWUIFWRTJUQR44TIX2ZBQQ5JNQ3MOBKAIW3BO7UDDEG543RXL7Q2J
  • CAVL4BSHMU5ECWZCB6ETYSBV4EWTRMHAGMVUEJ5PXM3P3E3AOJPX2TLU
  • CB3LKO733H3STIDCKWY4H25FH426HA7WSERMJ3CZBQTKPOESKZ7LGOWA
  • CBAU3UYY3WMTUZ23XS7I4YXU63GCKXFHO26MNZ7RPIRXP3YUJMYGJRAV
  • CBCDAA5URMD55FQ5UQX3SCXLJTJQ35FNZHKNICVMAWLPSTJOX4BITYD6
  • CBDZYJVQJQT7QJ7ZTMGNGZ7RR3DF32LERLZ26A2HLW5FNJ4OOZCLI3OG
  • CBE5MXHDG2OL4J7WNNJDEV6J36TKG4XG5DEQQ6V4MNNEFXE34VI3SEKN
  • CBEYCIXFYK6FEUJCJSBHJQF2O4KJQAFX254UZBXWYRV7PRUYDGLYH3HG
  • CBFOUCSD3ZJ3CXMKERIDTKS7GCEAGZBGOGSFCP67RYOJVSRRDWYP564T
  • CBGC65JVYZZTGPVHURM32GFMMTUQJZVRTB6QAQDLNP4FG3LVFS5XJ7L2
  • CBHB2G4TMSVWE4YFDTFYRYNCP5KUT6RQVWQGIM4LQO2IKKHVDB7N5JJQ
  • CBHK3QURQ7OFTNMYQS7TBKPRWN3QDGNLIGANFGUFHG2SEE7WRJEMWWGE
  • CBNKCU3HGFKHFOF7JTGXQCNKE3G3DXS5RDBQUKQMIIECYKXPIOUGB2S3
  • CBNPBFVYCLQRWR5WFNRYYZWC3WGLWD7FXHZDZ4CO2LSJLUEDDTWLKHYG
  • CBSU24OXATTHBPNLWVEXIN3OZZSONBGVH6J4S3STQMR27ZR54MD4WEOL
  • CBYQ6LIUFBXPKN57AMP6YBPX4EKBSGPLZBO4CN4R5HYJXY57M3MQRRGQ
  • CBYTOTXFO5IVMH5N2ZRR376IRTKS5ZO3QBYUMNBMQFLAOXCAQC6DBDFK
  • CBZWNB2B7TNLCSFDOXZ24F54CWWUPDQ76DSHFLHBYC4KSPBCFHOHNYYN
  • CC24OISYJHWXZIFZBRJHFLVO5CNN3PQSKZE5BBBZLSSI5Z23TKC6GQY2
  • CC3KWIAIQGHJL7CRUBZMUO5R2M4IV352ACE2MLAI2B3236GGJ7X6Z5E7
  • CC767WIU5QGJMXYHDDYJAJEF2YWPHOXOZDWD3UUAZVS4KQPRXCKPT2YZ
  • CCA2ZJP5BVRXYTQH4FAGHCAUMRYCXVC4CRYC2NXHWMR7TIVX36U7F5HR
  • CCAOBAAWWWP7R24ZZ5S2C7GUUKZTOXPHFNQXYICBXMQZY2IBYNCVOWOL
  • CCCXWCYZU4QNUIIPTMWV2KFDRAREW2O5FSXL3L24L7FWXSQCDKTRFUPW
  • CCDH4BEUFSS643VAEISE2MNTR64WZFJMJ3VTPNHNDUT363DPRUFOQ3SV
  • CCFWKCD52JNSQLN5OS4F7EG6BPDT4IRJV6KODIEIZLWPM35IKHOKT6S2
  • CCKTLDG6I2MMJCKFWXXBXMA42LJ3XN2IOW6M7TK6EWNPJTS736ETFF2N
  • CCLJFYWNVMNLF3TFO2AJMYFGMI2EBP5U3BWPOL437IKGHNUJYOWIHTV3
  • CCV43DIK4TLUHFKNE3XL4QMNU6P7EGKMYNCDFRIB4HX4FTRM2IBDQEPS
  • CD45F76UVOSMUMSHLP2OMCNF7N662DQA76IM6PP7PWTCITGMZITULHZ7
  • CD4JGS6BB5NZVSNKRNI43GUC6E3OBYLCLBQZJVTZLDVHQ5KDAOHVOIQF
  • CDI7QVDTNDFEHB25VFQGMNFALGCXXKAWUSHOTQR2D4O44CATQJ5ZQMN6
  • CDIHXKZ4PFKAIONK52JAR6ZNMP62F3UP7XTIBSJTQLMLHQ44PQ5Q2H3J
  • CDONBLOOTYZ7QN62ZLJFHK7CT3JCP3JEZDCRSG3VLGAP73QAXS7HF6HU
  • CDQPH6PYFPMZU37OBZU44UOTXHCMH2RFRMXZXGOX3KAR6REDSWY6W3KI
  • CDRSZ4OGRVUU5ONTI6C6UNF5QFJ3OGGQCNTC5UXXTZQFVRTILJFSVG5D
  • CDSM6RP3GP6MSV7PXN7OSXCJ5EGMSLGLYFJ4QEPPMQWABD5JU5UPAOZM
  • CDV7RJP6RE3O2RJWQSJRBVRIG7QDVI6Y552NU54NBVUOVKUAMQQCPQQM

Interface

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.

Arguments

  • 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:
  • Emergency Manager: For emergency control
  • Vault Fee Receiver: For receiving vault fees
  • Manager: For primary vault control
  • Rebalance Manager: For rebalancing operations
  • vault_fee - Vault-specific fee in basis points (0_2000 for 0.20%)
  • defindex_protocol_receiver - Address receiving protocol fees
  • defindex_protocol_rate - Protocol fee rate in basis points (0-9000 for 0-90%)
  • soroswap_router - Soroswap router address
  • name_symbol - Map containing:
  • "name": Vault token name
  • "symbol": Vault token symbol
  • upgradable - Boolean flag for contract upgradeability

Function Flow

  1. Role Assignment:
  • Sets Emergency Manager
  • Sets Vault Fee Receiver
  • Sets Manager
  • Sets Rebalance Manager
  1. Fee Configuration:
  • Sets vault fe
fn __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.

Parameters

  • 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: Lea
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 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.

Parameters:

  • 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.

Returns

  • 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.

Errors:

  • ContractError::AmountOverTotalSupply: If the specified shares exceed the total supply.
  • ContractError::ArithmeticError: If any arithmetic operation fails during calculations.
  • `ContractError
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.

Arguments:

  • 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).

Returns

  • Result<(), ContractError> - Success (()) or ContractError if the rescue operation fails
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.

Arguments:

  • 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).

Returns

  • Result<(), ContractError> - Success (()) or ContractError if the pause operation fails
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.

Arguments:

  • 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).

Returns:

  • 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.

Arguments:

  • e - The environment.

Returns:

  • 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.

Arguments:

  • e - The environment.

Returns:

  • Result<Vec<CurrentAssetInvestmentAllocation>, ContractError> - A vector of asset allocations or error
fn 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.

Arguments

  • e - The current environment reference.
  • vault_shares - The number of vault shares for which the corresponding asset amounts are calculated.

Returns

  • 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.

Arguments

  • e - The environment.

Returns

  • (u32, u32) - A tuple containing:
  • The vault fee rate as a percentage in basis points.
  • The DeFindex protocol fee rate as a percentage in basis points.
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.

Arguments

  • e - The environment reference.

Function Flow

  1. Instance Extension:
  • Extends contract TTL
  1. Asset & Strategy Retrieval:
  • Gets all assets and their strategies
  • Initializes reports vector
  1. Report Generation:
  • For each asset:
  • For each strategy:
  • Gets current strategy balance
  • Updates report with new balance
  • Stores updated report

Returns

  • 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.

Note

Reports track:

  • Current strategy balance
  • Gains or losses since last report
  • Locked fees
  • Fee distribution status
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.

Arguments:

  • 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.

Returns:

  • () - 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.

Arguments:

  • e - The environment.

Returns:

  • 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.

Arguments:

  • e - The environment.
  • new_manager - The new manager address.

Returns

  • Result<(), ContractError> - Success (()) or ContractError if the manager change fails
fn set_manager(
    env: soroban_sdk::Env,
    new_manager: soroban_sdk::Address,
) -> Result<(), ContractError>

Retrieves the current manager address for the vault.

Arguments:

  • e - The environment.

Returns:

  • 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.

Arguments:

  • e - The environment.
  • emergency_manager - The new emergency manager address.

Returns:

  • () - 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.

Arguments:

  • e - The environment.

Returns:

  • 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.

Arguments:

  • e - The environment.
  • new_rebalance_manager - The new rebalance manager address.

Returns:

  • () - 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.

Arguments:

  • e - The environment.

Returns:

  • 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.

Arguments

  • e - The runtime environment.
  • new_wasm_hash - The hash of the new WASM code to upgrade the contract to.

Returns

  • Result<(), ContractError> - Returns Ok(()) on success, ContractError if upgrade fails
fn upgrade(
    env: soroban_sdk::Env,
    new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), ContractError>

Rebalances the vault by executing a series of instructions.

Arguments:

  • e - The environment.
  • instructions - A vector of Instruction structs representing actions (withdraw, invest, swap, zapper) to be taken.

Returns:

  • 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.

Arguments

  • e - The environment reference.
  • new_fee_bps - Optional fee basis points to override the default.

Returns

  • 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.

Arguments

  • e - The environment reference.
  • strategy - The address of the strategy for which to release fees.
  • amount - The amount of fees to release.

Returns

  • 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.

Arguments

  • e - The environment reference.
  • caller - The address initiating the fee distribution.

Returns

  • 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.

Arguments

  • token_a - The address of the first token.
  • token_b - The address of the second token.

Returns

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

Arguments

  • e - The environment.
  • factory - The factory address.
  • token_a - The address of the first token.
  • token_b - The address of the second token.

Returns

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.

Arguments

  • e - The environment.
  • factory - The factory address.
  • token_a - The address of the first token.
  • token_b - The address of the second token.

Returns

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.

Arguments

  • e - The environment.
  • pair - The pair address.
  • token_a - The address of the first token.
  • token_b - The address of the second token.

Returns

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.

Arguments

  • 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

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.

Arguments

  • 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

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.

Arguments

  • 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

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.

Arguments

  • e - The environment.
  • factory - The factory address.
  • amount_in - The input amount.
  • path - Vector of token addresses representing the path.

Returns

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.

Arguments

  • e - The environment.
  • factory - The factory address.
  • amount_out - The output amount.
  • path - Vector of token addresses representing the path.

Returns

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>

Imports

WebAssembly Text (WAT) ▶