Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

AssetsManagementTrait

Defines how the ERC4626 vault manages its underlying assets. This trait provides the core asset management functionality for the vault, abstracting the actual storage and transfer mechanisms. It enables two primary implementation patterns:

1. Self-managed assets: The vault contract holds assets directly on its own address. This is the default behavior provided by ERC4626SelfAssetsManagement implementation.

2. External vault: Assets are managed by an external contract, allowing for more complex asset management strategies. The exact implementation is expected to be defined by the contract implementing the ERC4626 component.

The trait methods are called during deposit, withdrawal, and total assets calculations, ensuring that the vault’s share pricing remains accurate regardless of the underlying asset management strategy.

CAUTION: Implementations must ensure that get_total_assets returns the actual amount of assets that can be withdrawn by users. Inaccurate reporting can lead to incorrect share valuations and potential economic attacks.

See the examples:

  • Self-managed vault: ERC4626SelfAssetsManagement at the end of the file.
  • External vault: ERC4626ExternalAssetsManagement in ERC4626ExternalVaultMock.

Fully qualified path: openzeppelin_token::erc20::extensions::erc4626::erc4626::ERC4626Component::AssetsManagementTrait

pub trait AssetsManagementTrait<TContractState, +HasComponent<TContractState>>

Trait functions

get_total_assets

Returns the total amount of underlying assets under the vault’s management. Used for share price calculations and determining the vault’s total value.

This method should return the actual amount of assets that the vault controls and that can be used to satisfy withdrawal requests. For self-managed vaults, this is typically the vault contract’s token balance. For external vaults, this should include any assets deposited in external protocols, minus any that are locked or unredeemable.

The accuracy of this method is critical for proper vault operation:

  • Overreporting can lead to share dilution and user losses.
  • Underreporting can lead to share inflation and potential economic attacks.

Fully qualified path: openzeppelin_token::erc20::extensions::erc4626::erc4626::ERC4626Component::AssetsManagementTrait::get_total_assets

fn get_total_assets(self: @ComponentState<TContractState>) -> u256

transfer_assets_in

Transfers assets from an external address into the vault’s management. Called during deposit and mint operations.

This method should handle the actual transfer of underlying assets from the from address into the vault’s control. For self-managed vaults, this typically means transferring tokens to the vault contract’s address. For external vaults, this might involve transferring into an external contract.

Requirements:

  • MUST transfer exactly assets amount of the underlying token.
  • SHOULD revert if the transfer fails or insufficient allowance/balance.

Fully qualified path: openzeppelin_token::erc20::extensions::erc4626::erc4626::ERC4626Component::AssetsManagementTrait::transfer_assets_in

fn transfer_assets_in(ref self: ComponentState<TContractState>, from: ContractAddress, assets: u256)

transfer_assets_out

Transfers assets from the vault’s management to an external address. Called during withdraw and redeem operations.

This method should handle the actual transfer of underlying assets from the vault’s control to the to address. For self-managed vaults, this typically means transferring tokens from the vault contract’s address. For external vaults, this might involve withdrawing from an external contract first.

Requirements:

  • MUST transfer exactly assets amount of the underlying token.
  • SHOULD revert if insufficient assets are available or transfer fails.

Fully qualified path: openzeppelin_token::erc20::extensions::erc4626::erc4626::ERC4626Component::AssetsManagementTrait::transfer_assets_out

fn transfer_assets_out(ref self: ComponentState<TContractState>, to: ContractAddress, assets: u256)