Introduction to Opium

Restrictions

Security and Audits

For users

FOR DEVELOPERS

SyntheticId examples

The financial logic of a product built on top of the Opium Protocol is encoded in a SyntheticId.

A SyntheticId must inherit the IDerivativeLogic interface as the Opium Protocol SyntheticAggregator expects to call some of the functions defined in the IDerivativeLogic contract throughout the lifecycle of the derivative. Specifically, these core functions are:

- validateInput
- getMargin
- getExecutionPayout
- getAuthorAddress
- getAuthorCommission
- thirdPartyExecutionAllowed
- allowThirdPartyExecution

The core function of a SyntheticId is the getExecutionPayout. It allows a SyntheticId author to describe the payout logic of their financial product. Hence, whether a financial product is a traditional call option or put option, a CDO or some more exotic derivative, that’s the function where the logic needs to be encoded.

The following is an example of a getExecutionPayout implementation for a CALL option:

1

function getExecutionPayout(Derivative memory _derivative, uint256 _result)

2

public

3

view

4

returns (uint256 buyerPayout, uint256 sellerPayout)

5

{

6

uint256 ppt;

7

8

uint256 strikePrice = _derivative.params[0];

9

10

if (_derivative.params.length == 2) {

11

ppt = _derivative.params[1];

12

} else {

13

ppt = BASE_PPT;

14

}

15

16

if (_result > strikePrice) {

17

uint256 profit = _result.sub(strikePrice);

18

profit = profit.mul(ppt).div(BASE_PPT);

19

20

if (profit < _derivative.margin) {

21

buyerPayout = profit;

22

sellerPayout = _derivative.margin.sub(profit);

23

} else {

24

buyerPayout = _derivative.margin;

25

sellerPayout = 0;

26

}

27

} else {

28

buyerPayout = 0;

29

sellerPayout = _derivative.margin;

30

}

31

}

Copied!

In the above example, in case the option is in the money and its intrinsic value is greater than the allocated margin, then the difference between the underlying's market price and the strike price represents the buyer's profit and the seller's loss. However, if the option is in the money and the profit is greater than the allocated collateral, then the buyer's profit is equal to the entire margin.

Conversely, the following is an example of a PUT option:

1

function getExecutionPayout(LibDerivative.Derivative memory _derivative, uint256 _result)

2

public

3

view

4

override

5

returns (uint256 buyerPayout, uint256 sellerPayout)

6

{

7

uint256 ppt;

8

9

uint256 strikePrice = _derivative.params[0];

10

11

if (_derivative.params.length == 2) {

12

ppt = _derivative.params[1];

13

} else {

14

ppt = BASE_PPT;

15

}

16

17

if (_result < strikePrice) {

18

uint256 profit = strikePrice.sub(_result);

19

profit = profit.mul(ppt).div(BASE_PPT);

20

21

if (profit < _derivative.margin) {

22

buyerPayout = profit;

23

sellerPayout = _derivative.margin.sub(profit);

24

} else {

25

buyerPayout = _derivative.margin;

26

sellerPayout = 0;

27

}

28

} else {

29

buyerPayout = 0;

30

sellerPayout = _derivative.margin;

31

}

32

}

Copied!

Last modified 6mo ago

Copy link