Option Contract

Option Contract

Interface

pragma solidity ^0.6.7;
interface OptionV2 {
	    function buyOption(
        uint256 _indexNo,
        uint8 _poolId,
        uint256 _position,
        bool _isCall,
        uint256 _price,
        uint256 _datetime,
        bytes calldata _signData
    ) external returns (uint256, uint256);

    function sellOption(
        uint256 _orderNo,
        uint256 _position,
        uint256 _price,
        uint256 _datetime,
        bytes calldata _signData
    ) external returns (uint256);

    function userExercise(
        uint256 _orderNo
    ) external returns (uint256);

    function userKnockout(
        uint256 _orderNo
    ) external returns (uint256);
	event BuyOption(uint256 orderNo, uint256[3] inData, address buyer);
	event SellOption(uint256 orderNo, uint256[3] outData, address seller);
    event UserExercise(uint256 orderNo,uint256[3] outData,bool isKnockout,address user);
    event ExercisePrice(uint256[] indexNo, uint256[] price, uint256 time);
	event MakerKnockOut(uint256[] orderNoArr);
    event MakerExercise(uint256[] orderNoArr);
}

Events

  • event BuyOption(uint256 orderNo, uint256[3] inData, address buyer)

    **Users buy options **

param
description

order_no

order_no

inData[0]

position

inData[1]

buy amount

inData[2]

fee

buyer

buyer address

  • SellOption(uint256 orderNo, uint256[3] outData, address seller)

    Users sell options

param
description

order_no

order_no

outData[0]

position

outData[1]

sell amount

outData[2]

fee

seller

seller address

  • UserExercise(uint256 orderNo,uint256[3] outData,bool isKnockout,address user)

    Users exercise or knockout liquidation

param
description

order_no

order_no

outData[0]

position

outData[1]

user profit

outData[2]

fee

isKnockout

Exercise or knockout liquidation at maturity

user

user address

  • MakerKnockOut(uint256[] orderNoArr)

    The order of Market maker liquidation

param
description

orderNoArr

The list of liquidation

  • MakerExercise(uint256[] orderNoArr)

    The order of market maker exercise at expiration

param
description

orderNoArr

The list of exercise at expiration

Methods(Read Contract)

1.KnockOut Rebake

uint256 public knockOutRebake

After knockout, users can get the percentage of rebake for the purchase price, rate=knockOutRebake/10000*100%

2.Base PoolsInfo

Get the knockout scale and exercise cycle for the specified poolId

uint256[2][16] public basePoolsInfo;

node

    //- get the exercise cycle of pool_id=1
	let exerciseDay = await contract.basePoolsInfo(pool_id,0);
	//- get the knockout scale of  pool_id=1
	let knockoutRatio = await contract.basePoolsInfo(pool_id,1);
	console.log({
		knockoutRatio:knockoutRatio/10000*100+"%",
		exerciseDay
	})

3. Pay Token

IERC20 public immutable payToken;

**Address of payment token ** node

	let payToken = await contract.payToken();
	console.log({payToken});

4. Pay Token Decimals

uint256 public immutable payTokenDecimals

the accuracy of token,e.g., usdt is 1e6

5. Sign Data Public

address public signDataPublic

The sign address when users buy and sell options

6. Sign Valid Time

uint256 public signValidTime

** The maximum validity period for a signature **

5. fee receiver

address public feeReceiver

**Developers' address to receive platform fees **

6. Sell Price Rate

uint256 public sellPriceRate

When you sell an option, multiply ratio on the basis of the quantitative price model, the initial ratio is 70%,ratio=sellPriceRate/10000*100%

7.Orders

struct Order {
		uint256 indexNo;
        uint8 poolId;
        address payToken;
        uint256 startPrice;
        uint256 exerciseTime;
        bool isCall;
        uint256 balance;
        uint256 margin;
        uint256 makerIncome;
        uint256 price;
        uint8 status;
		uint256 knockoutRebate;
    }
    //index_no => pool_id=> order[]
	Order[] public orders;

**View options details **

param
type
description

order_no

uint256

order_no

return
type
description

indexNo

uint256

index no

poolId

uint8

pool id

payToken

address

pay token

startPrice

uint256

Start price,is also strike price

exerciseTime

uint256

option exercise time

isCall

bool

is call option

balance

uint256

The balance of option contract

margin

uint256

Margin of market maker

makerIncome

uint256

Income of market maker

price

uint256

Price of open positions

status

uint8

0:Opened position, 1: Exercised,2:Knockouted

node

let order = await contract.orders(index_no, pool_id, order_no);
console.log({
	position: order.position.toString(),
	exerciseTime: order.exerciseTime.toString(),
	startPrice: order.startPrice.toString(),
	price: order.price.toString(),
});

8.Exercise Price

mapping(uint256 => mapping(uint256 => uint256)) public exercisePrice

param
type
description

index_no

uint256

index_no

exerciseTime

uint256

option exercise time

return
type
description

index_price

uint256

index price at exercise time

9. User Rate

uint256[5] public userRate

User buy and sell options rate

node

	let rate = await contract.userRate(index);

userRate[0]:Open put position rate userRate[1]:Option call position rate userRate[2]:Close put positon rate userRate[3]:Close call position rate userRate[4]:Exercise rate

Methods(Write Contract)

1. Buy Option

function buyOption(
		address _payToken
        uint256 _indexNo,
        uint8 _poolId,
        uint256 _position,
        bool _isCall,
        uint256 _price,
        uint256 _datetime,
        bytes calldata _signData
    ) external  returns (uint256 buyAmount, uint256 _orderNo)

Buy options Please refer to Reference

2. Sell Option

function sellOption(
        uint256 _orderNo,
        uint256 _position,
        uint256 _price,
        uint256 _datetime,
        bytes calldata _signData
    ) external  returns (uint256 amount)

Sell option

Please refer to Reference

3. UserExercise

function userExercise(
        uint256 _orderNo
    ) external  returns (uint256)

User exercise

4. User Knockout

function userKnockout(
        uint256 _orderNo
    ) external returns(uint256);

User Knockout

Last updated