UnderwriterVault

Git Source

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

NameTypeDescription
<none>UD60x18The utilisation rate of the vault

updateSettings

Updates the vault settings

function updateSettings(bytes memory settings) external;

Parameters

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

NameTypeDescription
<none>uint256total managed asset amount

_getSpotPrice

Gets the spot price at the current time

function _getSpotPrice() internal view virtual returns (UD60x18);

Returns

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

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

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

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

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

NameTypeDescription
assetAmountuint256quantity of assets to convert

Returns

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

NameTypeDescription
shareAmountuint256quantity of shares to convert

Returns

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

NameTypeDescription
calleraddress
receiveraddressrecipient of shares resulting from deposit
assetAmountuint256quantity of assets to deposit
shareAmountuint256
assetAmountOffsetuint256
shareAmountOffsetuint256

_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

NameTypeDescription
assetAmountuint256quantity of assets to deposit
receiveraddressrecipient of shares resulting from deposit

Returns

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

NameTypeDescription
shareAmountuint256quantity of shares to mint

Returns

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

NameTypeDescription
shareAmountuint256quantity of shares to mint
receiveraddressrecipient of shares resulting from deposit

Returns

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

NameTypeDescription
owneraddressholder of shares to be redeemed

Returns

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

NameTypeDescription
shareAmountuint256quantity of shares to redeem
receiveraddressrecipient of assets resulting from withdrawal
owneraddressholder of shares to be redeemed

Returns

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

NameTypeDescription
owneraddressholder of shares to be redeemed

Returns

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

NameTypeDescription
assetAmountuint256quantity of assets to withdraw

Returns

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

NameTypeDescription
assetAmountuint256quantity of assets to withdraw
receiveraddressrecipient of assets resulting from withdrawal
owneraddressholder of shares to be redeemed

Returns

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

NameTypeDescription
receiveraddressrecipient of shares resulting from deposit
assetAmountuint256quantity of assets being deposited
shareAmountuint256quantity 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

NameTypeDescription
owneraddressholder of shares to be redeemed
assetAmountuint256quantity of assets being withdrawn
shareAmountuint256quantity 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

NameTypeDescription
lUnderwriterVaultStorage.Layout
isBuyboolWhether this is a buy or a sell
strikeUD60x18The strike price of the option.
maturityuint256The maturity of the option.
sizeUD60x18The amount of contracts.
spreadUD60x18The spread added on to the premium due to C-level
premiumUD60x18The 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

NameTypeDescription
lUnderwriterVaultStorage.Layout
strikeUD60x18The strike price for the pool
maturityuint256The maturity for the pool

Returns

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

NameTypeDescription
totalAssetsUD60x18the total assets post settlement
totalLockedAssetsUD60x18the 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

NameTypeDescription
poolKeyIPoolFactory.PoolKeyThe option pool key
sizeUD60x18The size of the trade
isBuyboolWhether the trade is a buy or sell
takeraddressThe address of the taker

Returns

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

NameTypeDescription
poolKeyIPoolFactory.PoolKeyThe option pool key
sizeUD60x18The size of the trade
isBuyboolWhether the trade is a buy or sell
premiumLimituint256The premium limit of the trade
referreraddressThe address of the referrer

_settleMaturity

Settles all options that are on a single maturity

function _settleMaturity(UnderwriterVaultStorage.Layout storage l, uint256 maturity) internal;

Parameters

NameTypeDescription
lUnderwriterVaultStorage.Layout
maturityuint256The 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

NameTypeDescription
lUnderwriterVaultStorage.LayoutContains stored parameters of the vault, including the managementFeeRate and the lastManagementFeeTimestamp
timestampuint256The block's current timestamp.

Returns

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

NameTypeDescription
sizeUD60x18The amount of contracts

_revertIfZeroShares

Ensures that a share amount is non zero.

function _revertIfZeroShares(uint256 shares) internal pure;

Parameters

NameTypeDescription
sharesuint256The amount of shares

_revertIfZeroAsset

Ensures that an asset amount is non zero.

function _revertIfZeroAsset(uint256 amount) internal pure;

Parameters

NameTypeDescription
amountuint256The amount of assets

_revertIfAddressZero

Ensures that an address is non zero.

function _revertIfAddressZero(address addr) internal pure;

Parameters

NameTypeDescription
addraddressThe address to check

_revertIfMaximumAmountExceeded

Ensures that an amount is not above maximum

function _revertIfMaximumAmountExceeded(UD60x18 maximum, UD60x18 amount) internal pure;

Parameters

NameTypeDescription
maximumUD60x18The maximum amount
amountUD60x18The amount to check

_revertIfNotTradeableWithVault

Ensures that an option is tradeable with the vault.

function _revertIfNotTradeableWithVault(bool isCallVault, bool isCallOption) internal pure;

Parameters

NameTypeDescription
isCallVaultboolWhether the vault is a call or put vault.
isCallOptionboolWhether 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

NameTypeDescription
strikeUD60x18The strike price of the option.
maturityuint256The 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

NameTypeDescription
strikeUD60x18The strike price.
sizeUD60x18The amount of contracts.
availableAssetsUD60x18The 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

NameTypeDescription
valueUD60x18The observed value of the variable.
minimumUD60x18The minimum value the variable can be.
maximumUD60x18The 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

NameTypeDescription
valueUD60x18The observed value of the variable.
minimumUD60x18The minimum value the variable can be.
maximumUD60x18The 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

NameTypeDescription
totalPremiumUD60x18The total premium of the trade
premiumLimitUD60x18The premium limit of the trade
isBuyboolWhether 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

NameTypeDescription
lUnderwriterVaultStorage.Layout
maturityuint256The maturity.
strikeUD60x18The strike price.
sizeUD60x18The amount of contracts.

_revertIfSellIsDisabled

Ensures that the vault can't buy-to-close unless it is enabled.

function _revertIfSellIsDisabled(bool enableSell) internal pure;

Parameters

NameTypeDescription
enableSellboolWhether sell is enabled or not.