LiquidityVault
Inherits: ILiquidityVault, ERC165Upgradeable, AccessControlUpgradeable, PausableUpgradeable, UUPSUpgradeable, ERC20Upgradeable
Title: LiquidityVault
Author: @SocksNFlops
The base liquidity vault contract used by FulfillmentVault and RolloverVault
State Variables
KEEPER_ROLE
The role for the keeper
bytes32 public constant KEEPER_ROLE = keccak256("KEEPER_ROLE")
WHITELIST_ROLE
bytes32 public constant WHITELIST_ROLE = keccak256("WHITELIST_ROLE")
LiquidityVaultStorageLocation
The storage location of the LiquidityVault contract
keccak256(abi.encode(uint256(keccak256("buttonwood.storage.LiquidityVault")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant LiquidityVaultStorageLocation =
0x279d7268e134fe9470212f64c617da0df55170c0eafa03169b80558ce404b000
Functions
_getLiquidityVaultStorage
Gets the storage location of the LiquidityVault contract
function _getLiquidityVaultStorage() private pure returns (LiquidityVaultStorage storage $);
Returns
| Name | Type | Description |
|---|---|---|
$ | LiquidityVaultStorage | The storage location of the LiquidityVault contract |
__LiquidityVault_init
Initializes the LiquidityVault contract and calls parent initializers
function __LiquidityVault_init(
string memory name,
string memory symbol,
uint8 _decimals,
uint8 _decimalsOffset,
address[] memory _depositableAssets,
address[] memory _redeemableAssets
) internal onlyInitializing;
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the liquidity vault |
symbol | string | The symbol of the liquidity vault |
_decimals | uint8 | The decimals of the liquidity vault |
_decimalsOffset | uint8 | The decimals offset for measuring internal precision of shares |
_depositableAssets | address[] | The addresses of the depositable assets |
_redeemableAssets | address[] | The addresses of the redeemable assets |
__LiquidityVault_init_unchained
Initializes the LiquidityVault contract only
function __LiquidityVault_init_unchained(
uint8 _decimals,
uint8 _decimalsOffset,
address[] memory _depositableAssets,
address[] memory _redeemableAssets
) internal onlyInitializing;
Parameters
| Name | Type | Description |
|---|---|---|
_decimals | uint8 | The decimals of the liquidity vault |
_decimalsOffset | uint8 | The decimals offset for measuring internal precision of shares |
_depositableAssets | address[] | The addresses of the depositable assets |
_redeemableAssets | address[] | The addresses of the redeemable assets |
initialize
Initializes the LiquidityVault contract
function initialize(
string memory name,
string memory symbol,
uint8 _decimals,
uint8 _decimalsOffset,
address[] memory _depositableAssets,
address[] memory _redeemableAssets,
address admin
) external virtual initializer;
Parameters
| Name | Type | Description |
|---|---|---|
name | string | The name of the liquidity vault |
symbol | string | The symbol of the liquidity vault |
_decimals | uint8 | The decimals of the liquidity vault |
_decimalsOffset | uint8 | The decimals offset for measuring internal precision of shares |
_depositableAssets | address[] | The addresses of the depositable assets |
_redeemableAssets | address[] | The addresses of the redeemable assets |
admin | address | The address of the admin for the liquidity vault |
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor() ;
supportsInterface
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[ERC 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
virtual
override(AccessControlUpgradeable, ERC165Upgradeable)
returns (bool);
_authorizeUpgrade
Function that should revert when msg.sender is not authorized to upgrade the contract. Called by
{upgradeToAndCall}.
Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
function _authorizeUpgrade(address) internal onlyOwner {}
function _authorizeUpgrade(address newImplementation) internal virtual override onlyRole(DEFAULT_ADMIN_ROLE);
checkWhitelistEnforced
When whitelist is enforced, the sender must have the WHITELIST_ROLE. Otherwise, WHITELIST_ROLE is not required.
modifier checkWhitelistEnforced() ;
whitelistEnforced
Whether the whitelist is enforced.
function whitelistEnforced() public view virtual override returns (bool);
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether the whitelist is enforced. |
setWhitelistEnforced
Enforces the whitelist.
function setWhitelistEnforced(bool enforced) external virtual override onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
enforced | bool | Whether the whitelist is enforced. |
decimals
Returns the decimals places of the token.
function decimals() public view virtual override returns (uint8);
decimalsOffset
The decimals offset. The number of decimals to offset the shares by. Used to protect against inflation attacks.
function decimalsOffset() public view virtual override returns (uint8);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint8 | The decimals offset |
depositableAssets
The address of the depositable asset.
function depositableAssets() public view virtual override returns (address[] memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address[] | The address of the depositable asset. |
redeemableAssets
The addresses of the redeemable assets.
function redeemableAssets() public view virtual override returns (address[] memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address[] | The addresses of the redeemable assets. |
_updateAssets
Updates the assets of the vault
function _updateAssets(address asset, bool isRedeemable, bool add) internal;
Parameters
| Name | Type | Description |
|---|---|---|
asset | address | The address of the asset to update |
isRedeemable | bool | Whether the asset is redeemable |
add | bool | Whether to add the asset or remove the asset |
_totalAssets
Calculates the total assets of the vault
function _totalAssets() internal view virtual returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total assets of the vault |
totalAssets
The total assets of the vault
function totalAssets() public view virtual override returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The total assets of the vault |
_convertToShares
Internal conversion function (from assets to shares) with support for rounding direction.
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | The amount of assets to convert to shares |
rounding | Math.Rounding | The rounding direction |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The amount of shares |
_convertToAssets
Internal conversion function (from shares to assets) with support for rounding direction.
function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256[] memory);
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares to convert to assets |
rounding | Math.Rounding | The rounding direction |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256[] | The amount of assets |
setPaused
Sets the paused state of the vault.
function setPaused(bool paused) external virtual override onlyRole(KEEPER_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
paused | bool | The paused state of the vault. |
deposit
Deposits the specified amount of depositable asset into the vault.
function deposit(address depositableAsset, uint256 assets)
external
virtual
override
whenNotPaused
checkWhitelistEnforced;
Parameters
| Name | Type | Description |
|---|---|---|
depositableAsset | address | The address of the depositable asset to deposit. |
assets | uint256 | The amount of depositable asset to deposit. |
redeem
Redeems the specified amount of shares for the redeemable asset.
No whitelist enforcement for redeeming. This prevents funds from being locked in the vault.
function redeem(uint256 shares) external virtual override whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares to redeem. |
Structs
LiquidityVaultStorage
The storage for the LiquidityVault contract
Note: storage-location: erc7201:buttonwood.storage.LiquidityVault
struct LiquidityVaultStorage {
uint8 _decimals;
uint8 _decimalsOffset;
address[] _depositableAssets;
mapping(address => uint256) _depositableAssetIndex;
address[] _redeemableAssets;
mapping(address => uint256) _redeemableAssetIndex;
bool _whitelistEnforced;
}
Properties
| Name | Type | Description |
|---|---|---|
_decimals | uint8 | The decimals of the vault |
_decimalsOffset | uint8 | The decimals offset for measuring internal precision of shares |
_depositableAssets | address[] | The addresses of the depositable assets |
_depositableAssetIndex | mapping(address => uint256) | The index of the depositable assets (one-indexed) |
_redeemableAssets | address[] | The addresses of the redeemable assets |
_redeemableAssetIndex | mapping(address => uint256) | The index of the redeemable assets (one-indexed) |
_whitelistEnforced | bool | Whether the whitelist is enforced |