PoolCore

Git Source

Inherits: IPoolCore, PoolInternal, ReentrancyGuard

Functions

constructor

constructor(
    address factory,
    address router,
    address wrappedNativeToken,
    address feeReceiver,
    address referral,
    address settings,
    address vaultRegistry,
    address vxPremia
) PoolInternal(factory, router, wrappedNativeToken, feeReceiver, referral, settings, vaultRegistry, vxPremia);

marketPrice

Get the current market price as normalized price

function marketPrice() external view returns (UD60x18);

Returns

NameTypeDescription
<none>UD60x18The current market price as normalized price

takerFee

Calculates the fee for a trade based on the size and premium of the trade

function takerFee(address taker, UD60x18 size, uint256 premium, bool isPremiumNormalized, bool isOrderbook)
    external
    view
    returns (uint256);

Parameters

NameTypeDescription
takeraddressThe taker of a trade
sizeUD60x18The size of a trade (number of contracts) (18 decimals)
premiumuint256The total cost of option(s) for a purchase (poolToken decimals)
isPremiumNormalizedboolWhether the premium given is already normalized by strike or not (Ex: For a strike of 1500, and a premium of 750, the normalized premium would be 0.5)
isOrderbookboolWhether the fee is for the fillQuoteOB function or not

Returns

NameTypeDescription
<none>uint256The taker fee for an option trade denormalized (poolToken decimals)

_takerFeeLowLevel

Calculates the fee for a trade based on the size and premiumNormalized of the trade.

WARNING: It is recommended to use takerFee instead of this function. This function is a lower level function here to be used when a pool has not yet be deployed, by calling it from the diamond contract directly rather than a pool proxy. If using it from the pool, you should pass the same value as the pool for strike and isCallPool in order to get the accurate takerFee

function _takerFeeLowLevel(
    address taker,
    UD60x18 size,
    UD60x18 premium,
    bool isPremiumNormalized,
    bool isOrderbook,
    UD60x18 strike,
    bool isCallPool
) external view returns (UD60x18);

Parameters

NameTypeDescription
takeraddressThe taker of a trade
sizeUD60x18The size of a trade (number of contracts) (18 decimals)
premiumUD60x18The total cost of option(s) for a purchase (18 decimals)
isPremiumNormalizedboolWhether the premium given is already normalized by strike or not (Ex: For a strike of 1500, and a premium of 750, the normalized premium would be 0.5)
isOrderbookboolWhether the fee is for the fillQuoteOB function or not
strikeUD60x18The strike of the option (18 decimals)
isCallPoolboolWhether the pool is a call pool or not

Returns

NameTypeDescription
<none>UD60x18The taker fee for an option trade denormalized. (18 decimals)

getPoolSettings

Returns all pool parameters used for deployment

function getPoolSettings()
    external
    view
    returns (address base, address quote, address oracleAdapter, UD60x18 strike, uint256 maturity, bool isCallPool);

Returns

NameTypeDescription
baseaddressAddress of base token
quoteaddressAddress of quote token
oracleAdapteraddressAddress of oracle adapter
strikeUD60x18The strike of the option (18 decimals)
maturityuint256The maturity timestamp of the option
isCallPoolboolWhether the pool is for call or put options

ticks

Returns all ticks in the pool, including net liquidity for each tick

function ticks() external view returns (IPoolInternal.TickWithRates[] memory);

Returns

NameTypeDescription
<none>IPoolInternal.TickWithRates[]ticks All pool ticks with the liquidityNet (18 decimals) of each tick

claim

Updates the claimable fees of a position and transfers the claimed fees to the operator of the position. Then resets the claimable fees to zero.

function claim(Position.Key calldata p) external nonReentrant returns (uint256);

Parameters

NameTypeDescription
pPosition.KeyThe position key

Returns

NameTypeDescription
<none>uint256The amount of claimed fees (poolToken decimals)

getClaimableFees

Returns total claimable fees for the position

function getClaimableFees(Position.Key calldata p) external view returns (uint256);

Parameters

NameTypeDescription
pPosition.KeyThe position key

Returns

NameTypeDescription
<none>uint256The total claimable fees for the position (poolToken decimals)

writeFrom

Underwrite an option by depositing collateral. By default the taker fee and referral are applied to the underwriter, if the caller is a registered vault the longReceiver is used instead.

function writeFrom(address underwriter, address longReceiver, UD60x18 size, address referrer) external nonReentrant;

Parameters

NameTypeDescription
underwriteraddressThe underwriter of the option (Collateral will be taken from this address, and it will receive the short token)
longReceiveraddressThe address which will receive the long token
sizeUD60x18The number of contracts being underwritten (18 decimals)
referreraddressThe referrer of the user doing the trade

annihilate

Annihilate a pair of long + short option contracts to unlock the stored collateral.

This function can be called post or prior to expiration.

function annihilate(UD60x18 size) external nonReentrant;

Parameters

NameTypeDescription
sizeUD60x18The size to annihilate (18 decimals)

annihilateFor

Annihilate a pair of long + short option contracts to unlock the stored collateral on behalf of another account. msg.sender must be approved through UserSettings.setAuthorizedAddress by the owner of the long/short contracts.

This function can be called post or prior to expiration.

function annihilateFor(address account, UD60x18 size) external nonReentrant;

Parameters

NameTypeDescription
accountaddress
sizeUD60x18The size to annihilate (18 decimals)

exercise

Exercises all long options held by caller

function exercise() external nonReentrant returns (uint256 exerciseValue, uint256 exerciseFee);

Returns

NameTypeDescription
exerciseValueuint256The exercise value as amount of collateral paid out to long holder (poolToken decimals)
exerciseFeeuint256The fee paid to protocol (poolToken decimals)

exerciseFor

Batch exercises all long options held by each holder, caller is reimbursed with the cost deducted from the proceeds of the exercised options. Only authorized agents may execute this function on behalf of the option holder.

function exerciseFor(address[] calldata holders, uint256 costPerHolder)
    external
    nonReentrant
    returns (uint256[] memory exerciseValues, uint256[] memory exerciseFees);

Parameters

NameTypeDescription
holdersaddress[]The holders of the contracts
costPerHolderuint256The cost charged by the authorized operator, per option holder (poolToken decimals)

Returns

NameTypeDescription
exerciseValuesuint256[]The exercise value as amount of collateral paid out per holder, ignoring costs applied during automatic exercise, but excluding protocol fees from amount (poolToken decimals)
exerciseFeesuint256[]The fees paid to protocol (poolToken decimals)

settle

Settles all short options held by caller

function settle() external nonReentrant returns (uint256 collateral);

Returns

NameTypeDescription
collateraluint256The amount of collateral left after settlement (poolToken decimals)

settleFor

Batch settles all short options held by each holder, caller is reimbursed with the cost deducted from the proceeds of the settled options. Only authorized operators may execute this function on behalf of the option holder.

function settleFor(address[] calldata holders, uint256 costPerHolder)
    external
    nonReentrant
    returns (uint256[] memory collateral);

Parameters

NameTypeDescription
holdersaddress[]The holders of the contracts
costPerHolderuint256The cost charged by the authorized operator, per option holder (poolToken decimals)

Returns

NameTypeDescription
collateraluint256[]The amount of collateral left after settlement per holder, ignoring costs applied during automatic settlement (poolToken decimals)

settlePosition

Reconciles a user's position to account for settlement payouts post-expiration.

function settlePosition(Position.Key calldata p) external nonReentrant returns (uint256 collateral);

Parameters

NameTypeDescription
pPosition.KeyThe position key

Returns

NameTypeDescription
collateraluint256The amount of collateral left after settlement (poolToken decimals)

settlePositionFor

Batch reconciles each position to account for settlement payouts post-expiration. Caller is reimbursed with the cost deducted from the proceeds of the settled position. Only authorized operators may execute this function on behalf of the option holder.

function settlePositionFor(Position.Key[] calldata p, uint256 costPerHolder)
    external
    nonReentrant
    returns (uint256[] memory collateral);

Parameters

NameTypeDescription
pPosition.Key[]The position keys
costPerHolderuint256The cost charged by the authorized operator, per position holder (poolToken decimals)

Returns

NameTypeDescription
collateraluint256[]The amount of collateral left after settlement per holder, ignoring costs applied during automatic settlement (poolToken decimals)

transferPosition

Transfer a LP position to a new owner/operator

function transferPosition(Position.Key calldata srcP, address newOwner, address newOperator, UD60x18 size)
    external
    nonReentrant;

Parameters

NameTypeDescription
srcPPosition.KeyThe position key
newOwneraddressThe new owner
newOperatoraddressThe new operator
sizeUD60x18The size to transfer (18 decimals)

tryCacheSettlementPrice

Attempts to cache the settlement price of the option after expiration. Reverts if a price has already been cached

function tryCacheSettlementPrice() external;

getSettlementPrice

Returns the settlement price of the option.

function getSettlementPrice() external view returns (UD60x18);

Returns

NameTypeDescription
<none>UD60x18The settlement price of the option (18 decimals). Returns 0 if option is not settled yet.

getStrandedArea

Gets the lower and upper bound of the stranded market area when it exists. In case the stranded market area does not exist it will return the stranded market area the maximum tick price for both the lower and the upper, in which case the market price is not stranded given any range order info order.

function getStrandedArea() external view returns (UD60x18 lower, UD60x18 upper);

Returns

NameTypeDescription
lowerUD60x18Lower bound of the stranded market price area (Default : PoolStorage.MAX_TICK_PRICE + ONE = 2e18) (18 decimals)
upperUD60x18Upper bound of the stranded market price area (Default : PoolStorage.MAX_TICK_PRICE + ONE = 2e18) (18 decimals)

getTokenIds

Returns the list of existing tokenIds with non zero balance

function getTokenIds() external view returns (uint256[] memory);

Returns

NameTypeDescription
<none>uint256[]tokenIds The list of existing tokenIds