Comment on page
AeraVaultV2
Inherits: IVault, ERC165, Ownable2Step, Pausable, ReentrancyGuard
Aera Vault V2 Vault contract.
Largest possible fee earned proportion per one second.
0.0000001% per second, i.e. 3.1536% per year. 0.0000001% * (365 * 24 * 60 * 60) = 3.1536% or 3.16224% per year in leap years.
uint256 private constant _MAX_FEE = 10 ** 9;
Number of decimals for fee token.
uint256 private immutable _feeTokenDecimals;
Number of decimals for numeraire token.
uint256 private immutable _numeraireTokenDecimals;
Fee token used by asset registry.
IERC20 private immutable _feeToken;
Fee per second in 18 decimal fixed point format.
uint256 public immutable fee;
Asset registry address.
IAssetRegistry public immutable assetRegistry;
The address of wrapped native token.
address public immutable wrappedNativeToken;
STORAGE ///
Hooks module address.
IHooks public hooks;
Guardian address.
address public guardian;
Fee recipient address.
address public feeRecipient;
True if vault has been finalized.
bool public finalized;
Last measured value of assets in vault.
uint256 public lastValue;
Last spot price of fee token.
uint256 public lastFeeTokenPrice;
Fee earned amount for each prior fee recipient.
mapping(address => uint256) public fees;
Total fee earned and unclaimed amount by all fee recipients.
uint256 public feeTotal;
Last timestamp when fee index was reserved.
uint256 public lastFeeCheckpoint;
MODIFIERS ///
Throws if called by any account other than the owner or guardian.
modifier onlyOwnerOrGuardian();
Throws if called by any account other than the guardian.
modifier onlyGuardian();
Throws if called after the vault is finalized.
modifier whenNotFinalized();
Throws if hooks is not set
modifier whenHooksSet();
Calculate current guardian fees.
modifier reserveFees();
Check insolvency of fee token was not made worse.
modifier checkReservedFees();
FUNCTIONS ///
constructor() Ownable ReentrancyGuard;
FUNCTIONS ///
MUST revert if not called by owner.
function deposit(AssetValue[] calldata amounts)
external
override
nonReentrant
onlyOwner
whenHooksSet
whenNotFinalized
reserveFees;
Parameters
Name | Type | Description |
---|---|---|
amounts | AssetValue[] | Assets and amounts to deposit. |
Withdraw assets.
MUST revert if not called by owner.
function withdraw(AssetValue[] calldata amounts)
external
override
nonReentrant
onlyOwner
whenHooksSet
whenNotFinalized
reserveFees;
Parameters
Name | Type | Description |
---|---|---|
amounts | AssetValue[] | Assets and amounts to withdraw. |
Set current guardian and fee recipient.
MUST revert if not called by owner.
function setGuardianAndFeeRecipient(
address newGuardian,
address newFeeRecipient
) external override onlyOwner whenNotFinalized reserveFees;
Parameters
Name | Type | Description |
---|---|---|
newGuardian | address | |
newFeeRecipient | address | |
Sets the current hooks module.
MUST revert if not called by owner.
function setHooks(address newHooks)
external
override
nonReentrant
onlyOwner
whenNotFinalized
reserveFees;
Parameters
Name | Type | Description |
---|---|---|
newHooks | address | |
Execute a transaction via the vault.
reserveFees modifier is not used to avoid reverts.
function execute(Operation calldata operation)
external
override
nonReentrant
onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
operation | Operation | Struct details for target and calldata to execute. |
Terminate the vault and return all funds to owner.
MUST revert if not called by owner.
function finalize()
external
override
nonReentrant
onlyOwner
whenHooksSet
whenNotFinalized
reserveFees;
Stops the guardian from submission and halts fee accrual.
MUST revert if not called by owner or guardian.
function pause()
external
override
nonReentrant
onlyOwnerOrGuardian
whenNotFinalized
reserveFees;
Resume fee accrual and guardian submissions.
MUST revert if not called by owner.
function resume() external override onlyOwner whenHooksSet whenNotFinalized;
Submit a series of transactions for execution via the vault.
MUST revert if not called by guardian.
function submit(Operation[] calldata operations)
external
override
nonReentrant
onlyGuardian
whenHooksSet
whenNotFinalized
whenNotPaused
reserveFees
checkReservedFees;
Parameters
Name | Type | Description |
---|---|---|
operations | Operation[] | Sequence of operations to execute. |
Claim fees on behalf of a current or previous fee recipient.
function claim() external override nonReentrant reserveFees;
Get current balances of all assets.
function holdings() external view override returns (AssetValue[] memory);
Returns
Name | Type | Description |
---|---|---|
<none> | AssetValue[] | assetAmounts Amounts of registered assets. |
Get current total value of assets in vault.
function value() external view override returns (uint256 vaultValue);
Returns
Name | Type | Description |
---|---|---|
vaultValue | uint256 | value Current total value. |
Returns true if this contract implements the interface defined by
interfaceId
. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.function supportsInterface(bytes4 interfaceId)
public
view
override
returns (bool);
Leaves the contract without owner. It will not be possible to call
onlyOwner
functions. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby disabling any functionality that is only available to the owner.function renounceOwnership() public view override onlyOwner;
Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one. Can only be called by the current owner.
function transferOwnership(address newOwner) public override onlyOwner;
Only accept native token from the wrapped native token contract when burning wrapped native tokens.
receive() external payable;
INTERNAL FUNCTIONS ///
Calculate guardian fee index.
function _getFeeIndex() internal view returns (uint256 feeIndex);
Returns
Name | Type | Description |
---|---|---|
feeIndex | uint256 | Guardian fee index. |
Calculate current guardian fees.
function _reserveFees() internal;
Get current total value of assets in vault and price of fee token.
It calculates the value in Numeraire token decimals.
function _value(IAssetRegistry.AssetPriceReading[] memory erc20SpotPrices)
internal
view
returns (uint256 vaultValue, uint256 feeTokenPrice);
Parameters
Name | Type | Description |
---|---|---|
erc20SpotPrices | IAssetRegistry.AssetPriceReading[] | Spot prices of ERC20 assets. |
Returns
Name | Type | Description |
---|---|---|
vaultValue | uint256 | Current total value. |
feeTokenPrice | uint256 | Fee token price. |
Check that assets in provided amounts are sorted and unique.
function _checkAmountsSorted(AssetValue[] memory amounts) internal pure;
Parameters
Name | Type | Description |
---|---|---|
amounts | AssetValue[] | Struct details for assets and amounts to withdraw. |
Check request to withdraw.
function _checkWithdrawRequest(
IAssetRegistry.AssetInformation[] memory assets,
AssetValue[] memory amounts
) internal view;
Parameters
Name | Type | Description |
---|---|---|
assets | IAssetRegistry.AssetInformation[] | Struct details for asset information from asset registry. |
amounts | AssetValue[] | Struct details for assets and amounts to withdraw. |
Get spot prices and units of requested assets.
Spot prices are scaled to 18 decimals.
function _getSpotPricesAndUnits(
IAssetRegistry.AssetInformation[] memory assets,
IAssetRegistry.AssetPriceReading[] memory erc20SpotPrices
)
internal
view
returns (uint256[] memory spotPrices, uint256[] memory assetUnits);
Parameters
Name | Type | Description |
---|---|---|
assets | IAssetRegistry.AssetInformation[] | Registered assets in asset registry and their information. |
erc20SpotPrices | IAssetRegistry.AssetPriceReading[] | Struct details for spot prices of ERC20 assets. |
Returns
Name | Type | Description |
---|---|---|
spotPrices | uint256[] | Spot prices of assets. |
assetUnits | uint256[] | Units of assets. |
Get total amount of assets in vault.
function _getHoldings(IAssetRegistry.AssetInformation[] memory assets)
internal
view
returns (AssetValue[] memory assetAmounts);
Parameters
Name | Type | Description |
---|---|---|
assets | IAssetRegistry.AssetInformation[] | Struct details for registered assets in asset registry. |
Returns
Name | Type | Description |
---|---|---|
assetAmounts | AssetValue[] | Amount of assets. |
Check if balance of fee becomes insolvent or becomes more insolvent.
function _checkReservedFees(uint256 prevFeeTokenBalance) internal view;
Parameters
Name | Type | Description |
---|---|---|
prevFeeTokenBalance | uint256 | Balance of fee token before action. |
Check if the address can be a guardian.
function _checkGuardianAddress(
address newGuardian,
address owner_
) internal pure;
Parameters
Name | Type | Description |
---|---|---|
newGuardian | address | Address to check. |
owner_ | address | Owner address. |
Check if the address can be a fee recipient.
function _checkFeeRecipientAddress(
address newFeeRecipient,
address owner_
) internal pure;
Parameters
Name | Type | Description |
---|---|---|
newFeeRecipient | address | Address to check. |
owner_ | address | Owner address. |
Check if the address can be an asset registry.
function _checkAssetRegistryAddress(address newAssetRegistry) internal view;
Parameters
Name | Type | Description |
---|---|---|
newAssetRegistry | address | Address to check. |
Check if the address can be a hooks contract.
function _checkHooksAddress(address newHooks) internal view;
Parameters
Name | Type | Description |
---|---|---|
newHooks | address | Address to check. |
Check whether asset is registered to asset registry or not.
function _isAssetRegistered(
IERC20 asset,
IAssetRegistry.AssetInformation[] memory registeredAssets
) internal pure returns (bool isRegistered, uint256 index);
Parameters
Name | Type | Description |
---|---|---|
asset | IERC20 | Asset to check. |
registeredAssets | IAssetRegistry.AssetInformation[] | Array of registered assets. |
Returns
Name | Type | Description |
---|---|---|
isRegistered | bool | True if asset is registered. |
index | uint256 | Index of asset in asset registry. |
Last modified 1mo ago