OptionPS

Git Source

Inherits: ERC1155Base, ERC1155Enumerable, ERC165Base, IOptionPS, ReentrancyGuard

State Variables

FEE_RECEIVER

address internal immutable FEE_RECEIVER;

FEE

UD60x18 internal constant FEE = UD60x18.wrap(0.003e18);

Functions

constructor

constructor(address feeReceiver);

name

Returns the name of the physically settled option token

function name() external view returns (string memory);

symbol

Returns the symbol of the physically settled option token

function symbol() external view returns (string memory);

_symbol

function _symbol(OptionPSStorage.Layout storage l) internal view returns (string memory);

getSettings

Returns the pair infos for this option

function getSettings() external view returns (address base, address quote, bool isCall);

underwrite

Underwrite an option by depositing collateral

function underwrite(UD60x18 strike, uint64 maturity, address longReceiver, UD60x18 contractSize)
    external
    nonReentrant;

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
maturityuint64the option maturity timestamp
longReceiveraddressthe address that will receive the long tokens
contractSizeUD60x18number of long tokens to mint (18 decimals)

annihilate

Burn longs and shorts, to recover collateral of the option

function annihilate(UD60x18 strike, uint64 maturity, UD60x18 contractSize) external nonReentrant;

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
maturityuint64the option maturity timestamp
contractSizeUD60x18number of contracts to annihilate (18 decimals)

getExerciseCost

Returns the amount of exerciseToken to pay to exercise the given amount of contracts

function getExerciseCost(UD60x18 strike, UD60x18 contractSize)
    public
    view
    returns (uint256 totalExerciseCost, uint256 fee);

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
contractSizeUD60x18number of long tokens to exercise (18 decimals)

Returns

NameTypeDescription
totalExerciseCostuint256the total amount of exerciseToken to pay, including fee (exerciseToken decimals)
feeuint256the amount of exerciseToken to pay as fee (exerciseToken decimals)

getExerciseValue

Returns the amount of collateral that would be received for a given amount of long tokens

function getExerciseValue(UD60x18 strike, UD60x18 contractSize) public view returns (uint256);

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
contractSizeUD60x18number of long tokens to exercise (18 decimals)

Returns

NameTypeDescription
<none>uint256the amount of collateral (collateral decimals)

exercise

Pay the exercise cost for a given amount contracts. The exercise value will be claimable after maturity.

function exercise(UD60x18 strike, uint64 maturity, UD60x18 contractSize) external nonReentrant;

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
maturityuint64the option maturity timestamp
contractSizeUD60x18amount of long tokens to exercise (18 decimals)

cancelExercise

Cancel an exercise before maturity, and recover the exerciseToken paid. (The fee paid during exercise is not recovered.

function cancelExercise(UD60x18 strike, uint64 maturity, UD60x18 contractSize) external nonReentrant;

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
maturityuint64the option maturity timestamp
contractSizeUD60x18amount of long tokens for which cancel exercise (18 decimals)

settleLong

Settle the exercised long options held by the caller.

function settleLong(UD60x18 strike, uint64 maturity, UD60x18 contractSize)
    external
    nonReentrant
    returns (uint256 exerciseValue);

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
maturityuint64the option maturity timestamp
contractSizeUD60x18number of long tokens to settle (18 decimals)

Returns

NameTypeDescription
exerciseValueuint256the amount of tokens transferred to the caller

settleShort

Settles the short options held by the caller.

function settleShort(UD60x18 strike, uint64 maturity, UD60x18 contractSize)
    external
    nonReentrant
    returns (uint256 collateralAmount, uint256 exerciseTokenAmount);

Parameters

NameTypeDescription
strikeUD60x18the option strike price (18 decimals)
maturityuint64the option maturity timestamp
contractSizeUD60x18number of short tokens to settle (18 decimals)

Returns

NameTypeDescription
collateralAmountuint256the amount of collateral transferred to the caller (base for calls, quote for puts)
exerciseTokenAmountuint256the amount of exerciseToken transferred to the caller (quote for calls, base for puts)

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

_mintUD60x18

_mint wrapper, converts UD60x18 to uint256

function _mintUD60x18(address account, uint256 tokenId, UD60x18 amount) internal;

_burnUD60x18

_burn wrapper, converts UD60x18 to uint256

function _burnUD60x18(address account, uint256 tokenId, UD60x18 amount) internal;

_revertIfOptionExpired

Revert if option has expired

function _revertIfOptionExpired(uint64 maturity) internal view;

_revertIfOptionNotExpired

Revert if option has not expired

function _revertIfOptionNotExpired(uint64 maturity) internal view;

_beforeTokenTransfer

_beforeTokenTransfer wrapper, updates tokenIds set

function _beforeTokenTransfer(
    address operator,
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
) internal virtual override(ERC1155BaseInternal, ERC1155EnumerableInternal);