UnderwriterVault
Inherits: IUnderwriterVault, Vault, ReentrancyGuard
State Variables
VAULT_REGISTRY
address internal immutable VAULT_REGISTRY;
FEE_RECEIVER
address internal immutable FEE_RECEIVER;
IV_ORACLE
address internal immutable IV_ORACLE;
FACTORY
address internal immutable FACTORY;
ROUTER
address internal immutable ROUTER;
VX_PREMIA
address internal immutable VX_PREMIA;
POOL_DIAMOND
address internal immutable POOL_DIAMOND;
Functions
constructor
constructor(
address vaultRegistry,
address feeReceiver,
address oracle,
address factory,
address router,
address vxPremia,
address poolDiamond,
address vaultMining
) Vault(vaultMining);
getUtilisation
Returns the utilisation rate of the vault
function getUtilisation() public view override(IVault, Vault) returns (UD60x18);
Returns
Name | Type | Description |
---|---|---|
<none> | UD60x18 | The utilisation rate of the vault |
updateSettings
Updates the vault settings
function updateSettings(bytes memory settings) external;
Parameters
Name | Type | Description |
---|---|---|
settings | bytes | Encoding of the new settings |
getSettings
Return vault abi encoded vault settings
function getSettings() external view returns (bytes memory);
_getBlockTimestamp
Gets the timestamp of the current block.
We are using a virtual internal function to be able to override in Mock contract for testing purpose
function _getBlockTimestamp() internal view virtual returns (uint256);
_totalAssets
get the total quantity of the base asset currently managed by the vault
function _totalAssets() internal view override returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | total managed asset amount |
_getSpotPrice
Gets the spot price at the current time
function _getSpotPrice() internal view virtual returns (UD60x18);
Returns
Name | Type | Description |
---|---|---|
<none> | UD60x18 | The spot price at the current time |
_getTotalLiabilitiesUnexpired
Gets the total liabilities value of the basket of unexpired options underwritten by this vault at the current time
function _getTotalLiabilitiesUnexpired(UnderwriterVaultStorage.Layout storage l) internal view returns (UD60x18);
Returns
Name | Type | Description |
---|---|---|
<none> | UD60x18 | The the total liabilities of the basket of unexpired options underwritten |
_getLockedSpreadInternal
Gets the total locked spread for the vault
function _getLockedSpreadInternal(UnderwriterVaultStorage.Layout storage l)
internal
view
returns (LockedSpreadInternal memory vars);
Returns
Name | Type | Description |
---|---|---|
vars | LockedSpreadInternal | The total locked spread |
_balanceOfUD60x18
_balanceOf returns the balance of the ERC20 share token which is always in 18 decimal places, therefore no further scaling has to be applied
function _balanceOfUD60x18(address owner) internal view returns (UD60x18);
_totalSupplyUD60x18
function _totalSupplyUD60x18() internal view returns (UD60x18);
_availableAssetsUD60x18
Gets the amount of available assets that are available after settlement
function _availableAssetsUD60x18(UnderwriterVaultStorage.Layout storage l) internal view returns (UD60x18);
Returns
Name | Type | Description |
---|---|---|
<none> | UD60x18 | The amount of available assets after calling the settle function |
_getPricePerShareUD60x18
Gets the current price per share for the vault
function _getPricePerShareUD60x18() internal view returns (UD60x18);
Returns
Name | Type | Description |
---|---|---|
<none> | UD60x18 | The current price per share |
_updateState
updates total spread in storage to be able to compute the price per share
function _updateState(UnderwriterVaultStorage.Layout storage l) internal;
_convertToSharesUD60x18
function _convertToSharesUD60x18(UD60x18 assetAmount, UD60x18 pps) internal view returns (UD60x18 shareAmount);
_convertToShares
calculate the quantity of shares received in exchange for a given quantity of assets, not accounting for slippage
function _convertToShares(uint256 assetAmount) internal view override returns (uint256 shareAmount);
Parameters
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets to convert |
Returns
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares calculated |
_convertToAssetsUD60x18
function _convertToAssetsUD60x18(UD60x18 shareAmount, UD60x18 pps) internal view returns (UD60x18 assetAmount);
_convertToAssets
calculate the quantity of assets received in exchange for a given quantity of shares, not accounting for slippage
function _convertToAssets(uint256 shareAmount) internal view virtual override returns (uint256 assetAmount);
Parameters
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares to convert |
Returns
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets calculated |
_deposit
execute a deposit of assets on behalf of given address
function _deposit(
address caller,
address receiver,
uint256 assetAmount,
uint256 shareAmount,
uint256 assetAmountOffset,
uint256 shareAmountOffset
) internal virtual override;
Parameters
Name | Type | Description |
---|---|---|
caller | address | |
receiver | address | recipient of shares resulting from deposit |
assetAmount | uint256 | quantity of assets to deposit |
shareAmount | uint256 | |
assetAmountOffset | uint256 | |
shareAmountOffset | uint256 |
_deposit
execute a deposit of assets on behalf of given address
function _deposit(uint256 assetAmount, address receiver)
internal
virtual
override
nonReentrant
returns (uint256 shareAmount);
Parameters
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets to deposit |
receiver | address | recipient of shares resulting from deposit |
Returns
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares to mint |
_previewMintUD60x18
function _previewMintUD60x18(UD60x18 shareAmount) internal view returns (UD60x18 assetAmount);
_previewMint
simulate a minting of given quantity of shares
function _previewMint(uint256 shareAmount) internal view virtual override returns (uint256 assetAmount);
Parameters
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares to mint |
Returns
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets to deposit |
_mint
execute a minting of shares on behalf of given address
function _mint(uint256 shareAmount, address receiver)
internal
virtual
override
nonReentrant
returns (uint256 assetAmount);
Parameters
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares to mint |
receiver | address | recipient of shares resulting from deposit |
Returns
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets to deposit |
_maxRedeemUD60x18
function _maxRedeemUD60x18(UnderwriterVaultStorage.Layout storage l, address owner, UD60x18 pps)
internal
view
returns (UD60x18 shareAmount);
_maxRedeem
calculate the maximum quantity of shares which may be redeemed by given holder
function _maxRedeem(address owner) internal view virtual override returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
owner | address | holder of shares to be redeemed |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | maxShares maximum share redeem amount |
_redeem
execute a redemption of shares on behalf of given address
function _redeem(uint256 shareAmount, address receiver, address owner)
internal
virtual
override
nonReentrant
returns (uint256 assetAmount);
Parameters
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares to redeem |
receiver | address | recipient of assets resulting from withdrawal |
owner | address | holder of shares to be redeemed |
Returns
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets to withdraw |
_maxWithdrawUD60x18
function _maxWithdrawUD60x18(UnderwriterVaultStorage.Layout storage l, address owner, UD60x18 pps)
internal
view
returns (UD60x18 withdrawableAssets);
_maxWithdraw
calculate the maximum quantity of base assets which may be withdrawn by given holder
function _maxWithdraw(address owner) internal view virtual override returns (uint256 withdrawableAssets);
Parameters
Name | Type | Description |
---|---|---|
owner | address | holder of shares to be redeemed |
Returns
Name | Type | Description |
---|---|---|
withdrawableAssets | uint256 | maxAssets maximum asset mint amount |
_previewWithdrawUD60x18
function _previewWithdrawUD60x18(UnderwriterVaultStorage.Layout storage l, UD60x18 assetAmount, UD60x18 pps)
internal
view
returns (UD60x18 shareAmount);
_previewWithdraw
simulate a withdrawal of given quantity of assets
function _previewWithdraw(uint256 assetAmount) internal view virtual override returns (uint256 shareAmount);
Parameters
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets to withdraw |
Returns
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares to redeem |
_withdraw
execute a withdrawal of assets on behalf of given address
function _withdraw(uint256 assetAmount, address receiver, address owner)
internal
virtual
override
nonReentrant
returns (uint256 shareAmount);
Parameters
Name | Type | Description |
---|---|---|
assetAmount | uint256 | quantity of assets to withdraw |
receiver | address | recipient of assets resulting from withdrawal |
owner | address | holder of shares to be redeemed |
Returns
Name | Type | Description |
---|---|---|
shareAmount | uint256 | quantity of shares to redeem |
_afterDeposit
ERC4626 hook, called deposit and mint actions
function should be overridden and new implementation must call super
function _afterDeposit(address receiver, uint256 assetAmount, uint256 shareAmount) internal virtual override;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | recipient of shares resulting from deposit |
assetAmount | uint256 | quantity of assets being deposited |
shareAmount | uint256 | quantity of shares being minted |
_beforeWithdraw
ERC4626 hook, called before withdraw and redeem actions
function should be overridden and new implementation must call super
function _beforeWithdraw(address owner, uint256 assetAmount, uint256 shareAmount) internal virtual override;
Parameters
Name | Type | Description |
---|---|---|
owner | address | holder of shares to be redeemed |
assetAmount | uint256 | quantity of assets being withdrawn |
shareAmount | uint256 | quantity of shares being redeemed |
_afterTrade
An internal hook inside the trade function that is called after logic inside the trade function is run to update state variables
function _afterTrade(
UnderwriterVaultStorage.Layout storage l,
bool isBuy,
UD60x18 strike,
uint256 maturity,
UD60x18 size,
UD60x18 spread,
UD60x18 premium
) internal;
Parameters
Name | Type | Description |
---|---|---|
l | UnderwriterVaultStorage.Layout | |
isBuy | bool | Whether this is a buy or a sell |
strike | UD60x18 | The strike price of the option. |
maturity | uint256 | The maturity of the option. |
size | UD60x18 | The amount of contracts. |
spread | UD60x18 | The spread added on to the premium due to C-level |
premium | UD60x18 | The base premium that is charged |
_getPoolAddress
Gets the pool address corresponding to the given strike and maturity. Returns zero address if pool is not deployed.
function _getPoolAddress(UnderwriterVaultStorage.Layout storage l, UD60x18 strike, uint256 maturity)
internal
view
returns (address);
Parameters
Name | Type | Description |
---|---|---|
l | UnderwriterVaultStorage.Layout | |
strike | UD60x18 | The strike price for the pool |
maturity | uint256 | The maturity for the pool |
Returns
Name | Type | Description |
---|---|---|
<none> | address | The pool address (zero address if pool is not deployed) |
_computeAssetsAfterSettlementOfExpiredOptions
Computes the totalAssets
and totalLockedAssets
after the settlement of expired options.
The totalAssets
after settlement are the totalAssets
less the exercise value of the call or put
options that were sold. The totalLockedAssets
after settlement are the totalLockedAssets
less
the collateral unlocked by the call or put.
function _computeAssetsAfterSettlementOfExpiredOptions(UnderwriterVaultStorage.Layout storage l)
internal
view
returns (UD60x18 totalAssets, UD60x18 totalLockedAssets);
Returns
Name | Type | Description |
---|---|---|
totalAssets | UD60x18 | the total assets post settlement |
totalLockedAssets | UD60x18 | the total locked assets post settlement |
_getQuoteInternal
Get the variables needed in order to compute the quote for a trade
function _getQuoteInternal(
UnderwriterVaultStorage.Layout storage l,
QuoteArgsInternal memory args,
bool revertIfPoolNotDeployed
) internal view returns (QuoteInternal memory quote);
_truncateTradeSize
Truncates the trade size (18 decimals) by the number of significant digits in the strike price
function _truncateTradeSize(UD60x18 size, UD60x18 strike) internal pure returns (UD60x18);
getQuote
Returns the trade quote premium
function getQuote(IPoolFactory.PoolKey calldata poolKey, UD60x18 size, bool isBuy, address taker)
external
view
returns (uint256 premium);
Parameters
Name | Type | Description |
---|---|---|
poolKey | IPoolFactory.PoolKey | The option pool key |
size | UD60x18 | The size of the trade |
isBuy | bool | Whether the trade is a buy or sell |
taker | address | The address of the taker |
Returns
Name | Type | Description |
---|---|---|
premium | uint256 | The trade quote premium |
trade
Executes a trade with the vault
function trade(IPoolFactory.PoolKey calldata poolKey, UD60x18 size, bool isBuy, uint256 premiumLimit, address referrer)
external
override
nonReentrant;
Parameters
Name | Type | Description |
---|---|---|
poolKey | IPoolFactory.PoolKey | The option pool key |
size | UD60x18 | The size of the trade |
isBuy | bool | Whether the trade is a buy or sell |
premiumLimit | uint256 | The premium limit of the trade |
referrer | address | The address of the referrer |
_settleMaturity
Settles all options that are on a single maturity
function _settleMaturity(UnderwriterVaultStorage.Layout storage l, uint256 maturity) internal;
Parameters
Name | Type | Description |
---|---|---|
l | UnderwriterVaultStorage.Layout | |
maturity | uint256 | The maturity that options will be settled for |
_settle
Settles all options that are expired
function _settle(UnderwriterVaultStorage.Layout storage l) internal;
settle
Settles all expired option positions.
function settle() external override nonReentrant;
onERC1155Received
function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4);
onERC1155BatchReceived
function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
external
pure
returns (bytes4);
_computeManagementFee
Computes and returns the management fee in shares that have to be paid by vault share holders for using the vault.
function _computeManagementFee(UnderwriterVaultStorage.Layout storage l, uint256 timestamp)
internal
view
returns (UD60x18 managementFeeInShares);
Parameters
Name | Type | Description |
---|---|---|
l | UnderwriterVaultStorage.Layout | Contains stored parameters of the vault, including the managementFeeRate and the lastManagementFeeTimestamp |
timestamp | uint256 | The block's current timestamp. |
Returns
Name | Type | Description |
---|---|---|
managementFeeInShares | UD60x18 | Returns the amount due in management fees in terms of shares (18 decimals). |
_chargeManagementFees
Charges the management fees from by liquidity providers.
function _chargeManagementFees() internal;
_claimFees
Transfers fees to the FEE_RECEIVER.
function _claimFees(UnderwriterVaultStorage.Layout storage l) internal;
_revertIfNotRegistryOwner
function _revertIfNotRegistryOwner(address addr) internal view;
_revertIfZeroSize
Ensures that an option is tradeable with the vault.
function _revertIfZeroSize(UD60x18 size) internal pure;
Parameters
Name | Type | Description |
---|---|---|
size | UD60x18 | The amount of contracts |
_revertIfZeroShares
Ensures that a share amount is non zero.
function _revertIfZeroShares(uint256 shares) internal pure;
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The amount of shares |
_revertIfZeroAsset
Ensures that an asset amount is non zero.
function _revertIfZeroAsset(uint256 amount) internal pure;
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of assets |
_revertIfAddressZero
Ensures that an address is non zero.
function _revertIfAddressZero(address addr) internal pure;
Parameters
Name | Type | Description |
---|---|---|
addr | address | The address to check |
_revertIfMaximumAmountExceeded
Ensures that an amount is not above maximum
function _revertIfMaximumAmountExceeded(UD60x18 maximum, UD60x18 amount) internal pure;
Parameters
Name | Type | Description |
---|---|---|
maximum | UD60x18 | The maximum amount |
amount | UD60x18 | The amount to check |
_revertIfNotTradeableWithVault
Ensures that an option is tradeable with the vault.
function _revertIfNotTradeableWithVault(bool isCallVault, bool isCallOption) internal pure;
Parameters
Name | Type | Description |
---|---|---|
isCallVault | bool | Whether the vault is a call or put vault. |
isCallOption | bool | Whether the option is a call or put. |
_revertIfOptionInvalid
Ensures that an option is valid for trading.
function _revertIfOptionInvalid(UD60x18 strike, uint256 maturity) internal view;
Parameters
Name | Type | Description |
---|---|---|
strike | UD60x18 | The strike price of the option. |
maturity | uint256 | The maturity of the option. |
_revertIfInsufficientFunds
Ensures there is sufficient funds for processing a trade.
function _revertIfInsufficientFunds(UD60x18 strike, UD60x18 size, UD60x18 availableAssets) internal view;
Parameters
Name | Type | Description |
---|---|---|
strike | UD60x18 | The strike price. |
size | UD60x18 | The amount of contracts. |
availableAssets | UD60x18 | The amount of available assets currently in the vault. |
_revertIfOutOfDTEBounds
Ensures that a value is within the DTE bounds.
function _revertIfOutOfDTEBounds(UD60x18 value, UD60x18 minimum, UD60x18 maximum) internal pure;
Parameters
Name | Type | Description |
---|---|---|
value | UD60x18 | The observed value of the variable. |
minimum | UD60x18 | The minimum value the variable can be. |
maximum | UD60x18 | The maximum value the variable can be. |
_revertIfOutOfDeltaBounds
Ensures that a value is within the delta bounds.
function _revertIfOutOfDeltaBounds(UD60x18 value, UD60x18 minimum, UD60x18 maximum) internal pure;
Parameters
Name | Type | Description |
---|---|---|
value | UD60x18 | The observed value of the variable. |
minimum | UD60x18 | The minimum value the variable can be. |
maximum | UD60x18 | The maximum value the variable can be. |
_revertIfAboveTradeMaxSlippage
Ensures that a value is within the delta bounds.
function _revertIfAboveTradeMaxSlippage(UD60x18 totalPremium, UD60x18 premiumLimit, bool isBuy) internal pure;
Parameters
Name | Type | Description |
---|---|---|
totalPremium | UD60x18 | The total premium of the trade |
premiumLimit | UD60x18 | The premium limit of the trade |
isBuy | bool | Whether the trade is a buy or a sell. |
_revertIfInsufficientShorts
Ensures there is sufficient shorts for processing a sell trade.
function _revertIfInsufficientShorts(
UnderwriterVaultStorage.Layout storage l,
uint256 maturity,
UD60x18 strike,
UD60x18 size
) internal view;
Parameters
Name | Type | Description |
---|---|---|
l | UnderwriterVaultStorage.Layout | |
maturity | uint256 | The maturity. |
strike | UD60x18 | The strike price. |
size | UD60x18 | The amount of contracts. |
_revertIfSellIsDisabled
Ensures that the vault can't buy-to-close unless it is enabled.
function _revertIfSellIsDisabled(bool enableSell) internal pure;
Parameters
Name | Type | Description |
---|---|---|
enableSell | bool | Whether sell is enabled or not. |