PoolStorage

Git Source

State Variables

SHORT

uint256 internal constant SHORT = 0;

LONG

uint256 internal constant LONG = 1;

TOKEN_VERSION

uint8 internal constant TOKEN_VERSION = 1;

MIN_TICK_DISTANCE

UD60x18 internal constant MIN_TICK_DISTANCE = UD60x18.wrap(0.001e18);

MIN_TICK_PRICE

UD60x18 internal constant MIN_TICK_PRICE = UD60x18.wrap(0.001e18);

MAX_TICK_PRICE

UD60x18 internal constant MAX_TICK_PRICE = UD60x18.wrap(1e18);

STORAGE_SLOT

bytes32 internal constant STORAGE_SLOT = keccak256("premia.contracts.storage.Pool");

Functions

layout

function layout() internal pure returns (Layout storage l);

getPoolTokenDecimals

Returns the token decimals for the pool token

function getPoolTokenDecimals(Layout storage l) internal view returns (uint8);

toPoolTokenDecimals

Adjust decimals of a value with 18 decimals to match the pool token decimals

function toPoolTokenDecimals(Layout storage l, uint256 value) internal view returns (uint256);

toPoolTokenDecimals

Adjust decimals of a value with 18 decimals to match the pool token decimals

function toPoolTokenDecimals(Layout storage l, int256 value) internal view returns (int256);

toPoolTokenDecimals

Adjust decimals of a value with 18 decimals to match the pool token decimals

function toPoolTokenDecimals(Layout storage l, UD60x18 value) internal view returns (uint256);

toPoolTokenDecimals

Adjust decimals of a value with 18 decimals to match the pool token decimals

function toPoolTokenDecimals(Layout storage l, SD59x18 value) internal view returns (int256);

fromPoolTokenDecimals

Adjust decimals of a value with pool token decimals to 18 decimals

function fromPoolTokenDecimals(Layout storage l, uint256 value) internal view returns (UD60x18);

fromPoolTokenDecimals

Adjust decimals of a value with pool token decimals to 18 decimals

function fromPoolTokenDecimals(Layout storage l, int256 value) internal view returns (SD59x18);

roundDown

Scales the decimals places from UD60x18 to the pool token decimals.

function roundDown(Layout storage l, UD60x18 value) internal view returns (uint256);

Parameters

NameTypeDescription
lLayout
valueUD60x18The value that should be rounded down

Returns

NameTypeDescription
<none>uint256Returns the scaled value in uint256

roundDownUD60x18

Scales the decimals places from UD60x18 to the pool token decimals and casts it back to UD60x18.

function roundDownUD60x18(Layout storage l, UD60x18 value) internal view returns (UD60x18);

Parameters

NameTypeDescription
lLayout
valueUD60x18The value that should be rounded down

Returns

NameTypeDescription
<none>UD60x18Returns the scaled value in UD60x18

roundDownSD59x18

Scales the decimals places from SD59x18 to the pool token decimals and casts it back to SD59x18.

function roundDownSD59x18(Layout storage l, SD59x18 value) internal view returns (SD59x18);

Parameters

NameTypeDescription
lLayout
valueSD59x18The value that should be rounded down

Returns

NameTypeDescription
<none>SD59x18Returns the scaled value in SD59x18

roundUp

Scales the decimals places from UD60x18 to the pool token decimals and rounds up any residuals.

function roundUp(Layout storage l, UD60x18 value) internal view returns (uint256);

Parameters

NameTypeDescription
lLayout
valueUD60x18The value that should be rounded up

Returns

NameTypeDescription
<none>uint256Returns the rounded up value in uint256

roundUpUD60x18

Scales the decimals places from UD60x18 to the pool token decimals and casts it back to UD60x18. Any residuals are rounded up.

function roundUpUD60x18(Layout storage l, UD60x18 value) internal view returns (UD60x18);

Parameters

NameTypeDescription
lLayout
valueUD60x18The value that should be rounded up

Returns

NameTypeDescription
<none>UD60x18Returns the rounded up value in UD60x18

getPoolToken

Get the token used as options collateral and for payment of premium. (quote for PUT pools, base for CALL pools)

function getPoolToken(Layout storage l) internal view returns (address);

formatTokenId

calculate ERC1155 token id for given option parameters

function formatTokenId(address operator, UD60x18 lower, UD60x18 upper, Position.OrderType orderType)
    internal
    pure
    returns (uint256 tokenId);

Parameters

NameTypeDescription
operatoraddressThe current operator of the position
lowerUD60x18The lower bound normalized option price (18 decimals)
upperUD60x18The upper bound normalized option price (18 decimals)
orderTypePosition.OrderType

Returns

NameTypeDescription
tokenIduint256token id

parseTokenId

derive option maturity and strike price from ERC1155 token id

function parseTokenId(uint256 tokenId)
    internal
    pure
    returns (uint8 version, address operator, UD60x18 lower, UD60x18 upper, Position.OrderType orderType);

Parameters

NameTypeDescription
tokenIduint256token id

Returns

NameTypeDescription
versionuint8The version of LP token, used to know how to decode it, if upgrades are made
operatoraddressThe current operator of the position
lowerUD60x18The lower bound normalized option price (18 decimals)
upperUD60x18The upper bound normalized option price (18 decimals)
orderTypePosition.OrderType

approve

Converts value to pool token decimals and approves spender

function approve(IERC20 token, address spender, UD60x18 value) internal;

safeTransferFrom

Converts value to pool token decimals and transfers token

function safeTransferFrom(IERC20Router router, address token, address from, address to, UD60x18 value) internal;

safeTransferIgnoreDust

Transfers token amount to recipient. Ignores if dust is missing on the exchange level, i.e. if the pool balance is 0.01% less than the amount that should be sent, then the pool balance is transferred instead of the amount. If the relative difference is larger than 0.01% then the transaction will revert.

function safeTransferIgnoreDust(IERC20 token, address to, uint256 value) internal;

Parameters

NameTypeDescription
tokenIERC20IERC20 token that is intended to be sent.
toaddressRecipient address of the tokens.
valueuint256The amount of tokens that are intended to be sent (poolToken decimals).

safeTransferIgnoreDust

Transfers token amount to recipient. Ignores if dust is missing on the exchange level, i.e. if the pool balance is 0.01% less than the amount that should be sent, then the pool balance is transferred instead of the amount. If the relative difference is larger than 0.01% then the transaction will revert.

function safeTransferIgnoreDust(IERC20 token, address to, UD60x18 value) internal;

Parameters

NameTypeDescription
tokenIERC20IERC20 token that is intended to be sent.
toaddressRecipient address of the tokens.
valueUD60x18The amount of tokens that are intended to be sent. (18 decimals)

Structs

Layout

struct Layout {
    address base;
    address quote;
    address oracleAdapter;
    uint8 baseDecimals;
    uint8 quoteDecimals;
    uint256 maturity;
    bool isCallPool;
    DoublyLinkedList.Bytes32List tickIndex;
    mapping(UD60x18 normalizedPrice => IPoolInternal.Tick) ticks;
    UD50x28 marketPrice;
    UD50x28 globalFeeRate;
    UD60x18 protocolFees;
    UD60x18 strike;
    UD50x28 liquidityRate;
    UD50x28 longRate;
    UD50x28 shortRate;
    UD60x18 currentTick;
    UD60x18 settlementPrice;
    mapping(bytes32 key => Position.Data) positions;
    mapping(address provider => mapping(bytes32 hash => UD60x18 amountFilled)) quoteOBAmountFilled;
    bool __deprecated_initFeeDiscountRemoved;
    EnumerableSet.UintSet tokenIds;
}