Struct defindex_vault::DeFindexVaultClient

source ·
pub struct DeFindexVaultClient<'a> {
    pub env: Env,
    pub address: Address,
    /* private fields */
}
Expand description

DeFindexVaultClient is a client for calling the contract defined in “DeFindexVault”.

Fields§

§env: Env§address: Address

Implementations§

source§

impl<'a> DeFindexVaultClient<'a>

source

pub fn new(env: &Env, address: &Address) -> Self

source§

impl<'a> DeFindexVaultClient<'a>

source

pub fn initialize( &self, assets: &Vec<AssetStrategySet>, manager: &Address, emergency_manager: &Address, vault_fee_receiver: &Address, vault_fee: &u32, defindex_protocol_receiver: &Address, factory: &Address, vault_name: &String, vault_symbol: &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.

§Arguments
  • 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.
  • vault_name: Name of the vault token to be displayed in metadata.
  • vault_symbol: Symbol representing the vault’s token.
§Returns
  • Result<(), ContractError>: Returns Ok(()) if initialization succeeds, or a ContractError if any setup fails (e.g., strategy mismatch with asset).
§Errors
  • ContractError::AlreadyInitialized: If the vault has already been initialized.
  • ContractError::StrategyDoesNotSupportAsset: If a strategy within an asset does not support the asset’s contract.
source

pub fn try_initialize( &self, assets: &Vec<AssetStrategySet>, manager: &Address, emergency_manager: &Address, vault_fee_receiver: &Address, vault_fee: &u32, defindex_protocol_receiver: &Address, factory: &Address, vault_name: &String, vault_symbol: &String, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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.

§Arguments
  • 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.
  • vault_name: Name of the vault token to be displayed in metadata.
  • vault_symbol: Symbol representing the vault’s token.
§Returns
  • Result<(), ContractError>: Returns Ok(()) if initialization succeeds, or a ContractError if any setup fails (e.g., strategy mismatch with asset).
§Errors
  • ContractError::AlreadyInitialized: If the vault has already been initialized.
  • ContractError::StrategyDoesNotSupportAsset: If a strategy within an asset does not support the asset’s contract.
source

pub fn deposit( &self, amounts_desired: &Vec<i128>, amounts_min: &Vec<i128>, from: &Address, invest: &bool, ) -> (Vec<i128>, i128)

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.

§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: Leave the deposited funds as idle assets in the vault.
§Returns
  • Result<(Vec<i128>, i128), ContractError> - Returns the actual deposited amounts and shares_to_mint if successful, otherwise a ContractError.
§Function Flow
  1. Fee Collection: Collects accrued fees before processing the deposit.
  2. Validation: Checks that the lengths of amounts_desired and amounts_min match the vault’s assets.
  3. Share Calculation: Calculates shares_to_mint based on the vault’s total managed funds and the deposit amount.
  4. Asset Transfer: Transfers each specified amount from the user’s address to the vault as idle funds.
  5. Vault Shares Minting: Mints vault shares for the user to represent their ownership in the vault.
  6. Investment Execution: If invest is true, generates and executes the investment allocations for the deposited funds.
    • Allocates funds across strategies proportionally to their current state.
    • Executes the investment to transition idle funds into the vault’s strategies.
§Notes
  • For the first deposit, if the vault has only one asset, shares are calculated directly based on the deposit amount.
  • For multiple assets, the function delegates to calculate_deposit_amounts_and_shares_to_mint for precise share computation.
  • An event is emitted to log the deposit, including the actual deposited amounts and minted shares.
  • If invest is false, deposited funds remain idle, allowing for manual investment at a later time.
§Errors
  • Returns a ContractError if any validation or execution step fails.
source

pub fn try_deposit( &self, amounts_desired: &Vec<i128>, amounts_min: &Vec<i128>, from: &Address, invest: &bool, ) -> Result<Result<(Vec<i128>, i128), <(Vec<i128>, i128) as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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.

§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: Leave the deposited funds as idle assets in the vault.
§Returns
  • Result<(Vec<i128>, i128), ContractError> - Returns the actual deposited amounts and shares_to_mint if successful, otherwise a ContractError.
§Function Flow
  1. Fee Collection: Collects accrued fees before processing the deposit.
  2. Validation: Checks that the lengths of amounts_desired and amounts_min match the vault’s assets.
  3. Share Calculation: Calculates shares_to_mint based on the vault’s total managed funds and the deposit amount.
  4. Asset Transfer: Transfers each specified amount from the user’s address to the vault as idle funds.
  5. Vault Shares Minting: Mints vault shares for the user to represent their ownership in the vault.
  6. Investment Execution: If invest is true, generates and executes the investment allocations for the deposited funds.
    • Allocates funds across strategies proportionally to their current state.
    • Executes the investment to transition idle funds into the vault’s strategies.
§Notes
  • For the first deposit, if the vault has only one asset, shares are calculated directly based on the deposit amount.
  • For multiple assets, the function delegates to calculate_deposit_amounts_and_shares_to_mint for precise share computation.
  • An event is emitted to log the deposit, including the actual deposited amounts and minted shares.
  • If invest is false, deposited funds remain idle, allowing for manual investment at a later time.
§Errors
  • Returns a ContractError if any validation or execution step fails.
source

pub fn withdraw(&self, withdraw_shares: &i128, from: &Address) -> Vec<i128>

Handles the withdrawal process for a specified number of vault shares.

This function performs the following steps:

  1. Validates the environment and the inputs:
    • Ensures the contract is initialized.
    • Checks that the withdrawal amount (withdraw_shares) is non-negative.
    • Verifies the authorization of the from address.
  2. Collects applicable fees.
  3. Calculates the proportionate withdrawal amounts for each asset based on the number of shares.
  4. Burns the specified shares from the user’s account.
  5. Processes the withdrawal for each asset:
    • First attempts to cover the withdrawal amount using idle funds.
    • If idle funds are insufficient, unwinds investments from the associated strategies to cover the remaining amount, accounting for rounding errors in the last strategy.
  6. Transfers the withdrawn funds to the user’s address (from).
  7. Emits an event to record the withdrawal details.
§Parameters:
  • e: The contract environment (Env).
  • withdraw_shares: The number of vault shares to withdraw.
  • from: The address initiating the withdrawal.
§Returns:
  • A Result containing a vector of withdrawn amounts for each asset (Vec<i128>), or a 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::WrongAmountsLength: If there is a mismatch in asset allocation data.
§TODOs:
  • Implement minimum amounts for withdrawals to ensure compliance with potential restrictions.
  • Replace the returned vector with the original asset_withdrawal_amounts map for better structure.
  • avoid the usage of a Map, choose between using map or vector
source

pub fn try_withdraw( &self, withdraw_shares: &i128, from: &Address, ) -> Result<Result<Vec<i128>, <Vec<i128> as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

Handles the withdrawal process for a specified number of vault shares.

This function performs the following steps:

  1. Validates the environment and the inputs:
    • Ensures the contract is initialized.
    • Checks that the withdrawal amount (withdraw_shares) is non-negative.
    • Verifies the authorization of the from address.
  2. Collects applicable fees.
  3. Calculates the proportionate withdrawal amounts for each asset based on the number of shares.
  4. Burns the specified shares from the user’s account.
  5. Processes the withdrawal for each asset:
    • First attempts to cover the withdrawal amount using idle funds.
    • If idle funds are insufficient, unwinds investments from the associated strategies to cover the remaining amount, accounting for rounding errors in the last strategy.
  6. Transfers the withdrawn funds to the user’s address (from).
  7. Emits an event to record the withdrawal details.
§Parameters:
  • e: The contract environment (Env).
  • withdraw_shares: The number of vault shares to withdraw.
  • from: The address initiating the withdrawal.
§Returns:
  • A Result containing a vector of withdrawn amounts for each asset (Vec<i128>), or a 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::WrongAmountsLength: If there is a mismatch in asset allocation data.
§TODOs:
  • Implement minimum amounts for withdrawals to ensure compliance with potential restrictions.
  • Replace the returned vector with the original asset_withdrawal_amounts map for better structure.
  • avoid the usage of a Map, choose between using map or vector
source

pub fn emergency_withdraw(&self, strategy_address: &Address, caller: &Address)

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.

§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> - Ok if successful, otherwise returns a ContractError.
source

pub fn try_emergency_withdraw( &self, strategy_address: &Address, caller: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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.

§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> - Ok if successful, otherwise returns a ContractError.
source

pub fn pause_strategy(&self, strategy_address: &Address, caller: &Address)

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> - Ok if successful, otherwise returns a ContractError.
source

pub fn try_pause_strategy( &self, strategy_address: &Address, caller: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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> - Ok if successful, otherwise returns a ContractError.
source

pub fn unpause_strategy(&self, strategy_address: &Address, caller: &Address)

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

pub fn try_unpause_strategy( &self, strategy_address: &Address, caller: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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

pub fn get_assets(&self) -> Vec<AssetStrategySet>

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

pub fn try_get_assets( &self, ) -> Result<Result<Vec<AssetStrategySet>, <Vec<AssetStrategySet> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

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

pub fn fetch_total_managed_funds( &self, ) -> Map<Address, CurrentAssetInvestmentAllocation>

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.

§Arguments:
  • e - The environment.
§Returns:
  • Map<Address, i128> - A map of asset addresses to their total managed amounts.
source

pub fn try_fetch_total_managed_funds( &self, ) -> Result<Result<Map<Address, CurrentAssetInvestmentAllocation>, <Map<Address, CurrentAssetInvestmentAllocation> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

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.

§Arguments:
  • e - The environment.
§Returns:
  • Map<Address, i128> - A map of asset addresses to their total managed amounts.
source

pub fn fetch_current_invested_funds(&self) -> Map<Address, i128>

Returns the current invested funds, representing the total assets allocated to strategies.

This function provides a map where the key is the asset address and the value is the total amount of that asset currently invested in various strategies.

§Arguments:
  • e - The environment.
§Returns:
  • Map<Address, i128> - A map of asset addresses to their total invested amounts.
source

pub fn try_fetch_current_invested_funds( &self, ) -> Result<Result<Map<Address, i128>, <Map<Address, i128> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

Returns the current invested funds, representing the total assets allocated to strategies.

This function provides a map where the key is the asset address and the value is the total amount of that asset currently invested in various strategies.

§Arguments:
  • e - The environment.
§Returns:
  • Map<Address, i128> - A map of asset addresses to their total invested amounts.
source

pub fn fetch_current_idle_funds(&self) -> Map<Address, i128>

Returns the current idle funds, representing the total assets held directly by the vault (not invested).

This function provides a map where the key is the asset address and the value is the total amount of that asset held as idle funds within the vault.

§Arguments:
  • e - The environment.
§Returns:
  • Map<Address, i128> - A map of asset addresses to their total idle amounts.
source

pub fn try_fetch_current_idle_funds( &self, ) -> Result<Result<Map<Address, i128>, <Map<Address, i128> as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

Returns the current idle funds, representing the total assets held directly by the vault (not invested).

This function provides a map where the key is the asset address and the value is the total amount of that asset held as idle funds within the vault.

§Arguments:
  • e - The environment.
§Returns:
  • Map<Address, i128> - A map of asset addresses to their total idle amounts.
source

pub fn get_asset_amounts_per_shares( &self, vault_shares: &i128, ) -> Map<Address, i128>

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
  • Map<Address, i128> - A map containing each asset address and its corresponding proportional amount.
source

pub fn try_get_asset_amounts_per_shares( &self, vault_shares: &i128, ) -> Result<Result<Map<Address, i128>, <Map<Address, i128> as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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
  • Map<Address, i128> - A map containing each asset address and its corresponding proportional amount.
source

pub fn get_fees(&self) -> (u32, u32)

source

pub fn try_get_fees( &self, ) -> Result<Result<(u32, u32), <(u32, u32) as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

source

pub fn collect_fees(&self)

source

pub fn try_collect_fees( &self, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

source§

impl<'a> DeFindexVaultClient<'a>

source

pub fn set_fee_receiver(&self, caller: &Address, new_fee_receiver: &Address)

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.

§Arguments:
  • e - The environment.
  • caller - The address initiating the change (must be the manager or emergency manager).
  • vault_fee_receiver - The new fee receiver address.
§Returns:
  • () - No return value.
source

pub fn try_set_fee_receiver( &self, caller: &Address, new_fee_receiver: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

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.

§Arguments:
  • e - The environment.
  • caller - The address initiating the change (must be the manager or emergency manager).
  • vault_fee_receiver - The new fee receiver address.
§Returns:
  • () - No return value.
source

pub fn get_fee_receiver(&self) -> 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.
source

pub fn try_get_fee_receiver( &self, ) -> Result<Result<Address, <Address as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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

pub fn set_manager(&self, manager: &Address)

Sets the manager for the vault.

This function allows the current manager or emergency manager to set a new manager for the vault.

§Arguments:
  • e - The environment.
  • manager - The new manager address.
§Returns:
  • () - No return value.
source

pub fn try_set_manager( &self, manager: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

Sets the manager for the vault.

This function allows the current manager or emergency manager to set a new manager for the vault.

§Arguments:
  • e - The environment.
  • manager - The new manager address.
§Returns:
  • () - No return value.
source

pub fn get_manager(&self) -> Address

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

pub fn try_get_manager( &self, ) -> Result<Result<Address, <Address as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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

pub fn set_emergency_manager(&self, emergency_manager: &Address)

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.

§Arguments:
  • e - The environment.
  • emergency_manager - The new emergency manager address.
§Returns:
  • () - No return value.
source

pub fn try_set_emergency_manager( &self, emergency_manager: &Address, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<Error, InvokeError>>

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.

§Arguments:
  • e - The environment.
  • emergency_manager - The new emergency manager address.
§Returns:
  • () - No return value.
source

pub fn get_emergency_manager(&self) -> 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.
source

pub fn try_get_emergency_manager( &self, ) -> Result<Result<Address, <Address as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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.
source§

impl<'a> DeFindexVaultClient<'a>

source

pub fn invest(&self, asset_investments: &Vec<Option<AssetInvestmentAllocation>>)

Executes the investment of the vault’s idle funds based on the specified asset allocations. This function allows partial investments by providing an optional allocation for each asset, and it ensures proper authorization and validation checks before proceeding with investments.

§Arguments
  • e - The current environment reference.
  • asset_investments - A vector of optional AssetInvestmentAllocation structures, where each element represents an allocation for a specific asset. The vector must match the number of vault assets in length.
§Returns
  • Result<(), ContractError> - Returns Ok(()) if the investments are successful or a ContractError if any issue occurs during validation or execution.
§Function Flow
  1. Extend Instance TTL: Extends the contract instance’s time-to-live to keep the instance active.
  2. Check Initialization: Verifies that the vault is properly initialized before proceeding.
  3. Access Control: Ensures the caller has the Manager role required to initiate investments.
  4. Asset Count Validation: Verifies that the length of the asset_investments vector matches the number of assets managed by the vault. If they don’t match, a WrongInvestmentLength error is returned.
  5. Investment Execution: Calls the check_and_execute_investments function to perform the investment after validating the inputs and ensuring correct execution flows for each asset allocation.
§Errors
  • Returns ContractError::WrongInvestmentLength if the length of asset_investments does not match the vault assets.
  • Returns ContractError if access control validation fails or if investment execution encounters an issue.
§Security
  • Only addresses with the Manager role can call this function, ensuring restricted access to managing investments.
source

pub fn try_invest( &self, asset_investments: &Vec<Option<AssetInvestmentAllocation>>, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

Executes the investment of the vault’s idle funds based on the specified asset allocations. This function allows partial investments by providing an optional allocation for each asset, and it ensures proper authorization and validation checks before proceeding with investments.

§Arguments
  • e - The current environment reference.
  • asset_investments - A vector of optional AssetInvestmentAllocation structures, where each element represents an allocation for a specific asset. The vector must match the number of vault assets in length.
§Returns
  • Result<(), ContractError> - Returns Ok(()) if the investments are successful or a ContractError if any issue occurs during validation or execution.
§Function Flow
  1. Extend Instance TTL: Extends the contract instance’s time-to-live to keep the instance active.
  2. Check Initialization: Verifies that the vault is properly initialized before proceeding.
  3. Access Control: Ensures the caller has the Manager role required to initiate investments.
  4. Asset Count Validation: Verifies that the length of the asset_investments vector matches the number of assets managed by the vault. If they don’t match, a WrongInvestmentLength error is returned.
  5. Investment Execution: Calls the check_and_execute_investments function to perform the investment after validating the inputs and ensuring correct execution flows for each asset allocation.
§Errors
  • Returns ContractError::WrongInvestmentLength if the length of asset_investments does not match the vault assets.
  • Returns ContractError if access control validation fails or if investment execution encounters an issue.
§Security
  • Only addresses with the Manager role can call this function, ensuring restricted access to managing investments.
source

pub fn rebalance(&self, instructions: &Vec<Instruction>)

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

pub fn try_rebalance( &self, instructions: &Vec<Instruction>, ) -> Result<Result<(), <() as TryFromVal<Env, Val>>::Error>, Result<ContractError, InvokeError>>

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.

Auto Trait Implementations§

§

impl<'a> Freeze for DeFindexVaultClient<'a>

§

impl<'a> !RefUnwindSafe for DeFindexVaultClient<'a>

§

impl<'a> !Send for DeFindexVaultClient<'a>

§

impl<'a> !Sync for DeFindexVaultClient<'a>

§

impl<'a> Unpin for DeFindexVaultClient<'a>

§

impl<'a> !UnwindSafe for DeFindexVaultClient<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, C> Compare<&T> for C
where C: Compare<T>,

§

type Error = <C as Compare<T>>::Error

§

fn compare(&self, a: &&T, b: &&T) -> Result<Ordering, <C as Compare<&T>>::Error>

§

impl<T, U, E, C> Compare<(T, U)> for C
where C: Compare<T, Error = E, Error = E> + Compare<U>,

§

type Error = E

§

fn compare( &self, a: &(T, U), b: &(T, U), ) -> Result<Ordering, <C as Compare<(T, U)>>::Error>

§

impl<T, U, V, E, C> Compare<(T, U, V)> for C
where C: Compare<T, Error = E, Error = E, Error = E> + Compare<U> + Compare<V>,

§

type Error = E

§

fn compare( &self, a: &(T, U, V), b: &(T, U, V), ) -> Result<Ordering, <C as Compare<(T, U, V)>>::Error>

§

impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
where C: Compare<T, Error = E, Error = E, Error = E, Error = E> + Compare<U> + Compare<V> + Compare<W>,

§

type Error = E

§

fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>

§

impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
where C: Compare<T, Error = E, Error = E, Error = E, Error = E, Error = E> + Compare<U> + Compare<V> + Compare<W> + Compare<X>,

§

type Error = E

§

fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>

§

impl<T, C> Compare<Box<T>> for C
where C: Compare<T>,

§

type Error = <C as Compare<T>>::Error

§

fn compare( &self, a: &Box<T>, b: &Box<T>, ) -> Result<Ordering, <C as Compare<Box<T>>>::Error>

§

impl<T, C> Compare<Option<T>> for C
where C: Compare<T>,

§

type Error = <C as Compare<T>>::Error

§

fn compare( &self, a: &Option<T>, b: &Option<T>, ) -> Result<Ordering, <C as Compare<Option<T>>>::Error>

§

impl<T, C> Compare<Rc<T>> for C
where C: Compare<T>,

§

type Error = <C as Compare<T>>::Error

§

fn compare( &self, a: &Rc<T>, b: &Rc<T>, ) -> Result<Ordering, <C as Compare<Rc<T>>>::Error>

§

impl<T, C> Compare<Vec<T>> for C
where C: Compare<T>,

§

type Error = <C as Compare<T>>::Error

§

fn compare( &self, a: &Vec<T>, b: &Vec<T>, ) -> Result<Ordering, <C as Compare<Vec<T>>>::Error>

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<E, T, U> IntoVal<E, T> for U
where E: Env, T: FromVal<E, U>,

§

fn into_val(&self, e: &E) -> T

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<E, T, U> TryIntoVal<E, T> for U
where E: Env, T: TryFromVal<E, U>,

§

type Error = <T as TryFromVal<E, U>>::Error

§

fn try_into_val(&self, env: &E) -> Result<T, <U as TryIntoVal<E, T>>::Error>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V