Skip to main content

LiquidityVault

Git Source

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

NameTypeDescription
$LiquidityVaultStorageThe 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

NameTypeDescription
namestringThe name of the liquidity vault
symbolstringThe symbol of the liquidity vault
_decimalsuint8The decimals of the liquidity vault
_decimalsOffsetuint8The decimals offset for measuring internal precision of shares
_depositableAssetsaddress[]The addresses of the depositable assets
_redeemableAssetsaddress[]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

NameTypeDescription
_decimalsuint8The decimals of the liquidity vault
_decimalsOffsetuint8The decimals offset for measuring internal precision of shares
_depositableAssetsaddress[]The addresses of the depositable assets
_redeemableAssetsaddress[]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

NameTypeDescription
namestringThe name of the liquidity vault
symbolstringThe symbol of the liquidity vault
_decimalsuint8The decimals of the liquidity vault
_decimalsOffsetuint8The decimals offset for measuring internal precision of shares
_depositableAssetsaddress[]The addresses of the depositable assets
_redeemableAssetsaddress[]The addresses of the redeemable assets
adminaddressThe 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

NameTypeDescription
<none>boolWhether the whitelist is enforced.

setWhitelistEnforced

Enforces the whitelist.

function setWhitelistEnforced(bool enforced) external virtual override onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
enforcedboolWhether 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

NameTypeDescription
<none>uint8The decimals offset

depositableAssets

The address of the depositable asset.

function depositableAssets() public view virtual override returns (address[] memory);

Returns

NameTypeDescription
<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

NameTypeDescription
<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

NameTypeDescription
assetaddressThe address of the asset to update
isRedeemableboolWhether the asset is redeemable
addboolWhether to add the asset or remove the asset

_totalAssets

Calculates the total assets of the vault

function _totalAssets() internal view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The total assets of the vault

totalAssets

The total assets of the vault

function totalAssets() public view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
assetsuint256The amount of assets to convert to shares
roundingMath.RoundingThe rounding direction

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
sharesuint256The amount of shares to convert to assets
roundingMath.RoundingThe rounding direction

Returns

NameTypeDescription
<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

NameTypeDescription
pausedboolThe 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

NameTypeDescription
depositableAssetaddressThe address of the depositable asset to deposit.
assetsuint256The 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

NameTypeDescription
sharesuint256The 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

NameTypeDescription
_decimalsuint8The decimals of the vault
_decimalsOffsetuint8The decimals offset for measuring internal precision of shares
_depositableAssetsaddress[]The addresses of the depositable assets
_depositableAssetIndexmapping(address => uint256)The index of the depositable assets (one-indexed)
_redeemableAssetsaddress[]The addresses of the redeemable assets
_redeemableAssetIndexmapping(address => uint256)The index of the redeemable assets (one-indexed)
_whitelistEnforcedboolWhether the whitelist is enforced