sID - Derivative recipe
1
pragma solidity 0.5.16;
2
pragma experimental ABIEncoderV2;
3
4
/// @title Opium.Lib.LibDerivative contract should be inherited by contracts that use Derivative structure and calculate derivativeHash
5
contract LibDerivative {
6
// Opium derivative structure (ticker) definition
7
struct Derivative {
8
// Margin parameter for syntheticId
9
uint256 margin;
10
// Maturity of derivative
11
uint256 endTime;
12
// Additional parameters for syntheticId
13
uint256[] params;
14
// oracleId of derivative
15
address oracleId;
16
// Margin token address of derivative
17
address token;
18
// syntheticId of derivative
19
address syntheticId;
20
}
21
22
/// @notice Calculates hash of provided Derivative
23
/// @param _derivative Derivative Instance of derivative to hash
24
/// @return derivativeHash bytes32 Derivative hash
25
function getDerivativeHash(Derivative memory _derivative) public pure returns (bytes32 derivativeHash) {
26
derivativeHash = keccak256(abi.encodePacked(
27
_derivative.margin,
28
_derivative.endTime,
29
_derivative.params,
30
_derivative.oracleId,
31
_derivative.token,
32
_derivative.syntheticId
33
));
34
}
35
}
36
Copied!
1
pragma solidity 0.5.16;
2
pragma experimental ABIEncoderV2;
3
4
import "../Lib/LibDerivative.sol";
5
6
/// @title Opium.Interface.IDerivativeLogic contract is an interface that every syntheticId should implement
7
contract IDerivativeLogic is LibDerivative {
8
/// @notice Validates ticker
9
/// @param _derivative Derivative Instance of derivative to validate
10
/// @return Returns boolean whether ticker is valid
11
function validateInput(Derivative memory _derivative) public view returns (bool);
12
13
/// @notice Calculates margin required for derivative creation
14
/// @param _derivative Derivative Instance of derivative
15
/// @return buyerMargin uint256 Margin needed from buyer (LONG position)
16
/// @return sellerMargin uint256 Margin needed from seller (SHORT position)
17
function getMargin(Derivative memory _derivative) public view returns (uint256 buyerMargin, uint256 sellerMargin);
18
19
/// @notice Calculates payout for derivative execution
20
/// @param _derivative Derivative Instance of derivative
21
/// @param _result uint256 Data retrieved from oracleId on the maturity
22
/// @return buyerPayout uint256 Payout in ratio for buyer (LONG position holder)
23
/// @return sellerPayout uint256 Payout in ratio for seller (SHORT position holder)
24
function getExecutionPayout(Derivative memory _derivative, uint256 _result) public view returns (uint256 buyerPayout, uint256 sellerPayout);
25
26
/// @notice Returns syntheticId author address for Opium commissions
27
/// @return authorAddress address The address of syntheticId address
28
function getAuthorAddress() public view returns (address authorAddress);
29
30
/// @notice Returns syntheticId author commission in base of COMMISSION_BASE
31
/// @return commission uint256 Author commission
32
function getAuthorCommission() public view returns (uint256 commission);
33
34
/// @notice Returns whether thirdparty could execute on derivative's owner's behalf
35
/// @param _derivativeOwner address Derivative owner address
36
/// @return Returns boolean whether _derivativeOwner allowed third party execution
37
function thirdpartyExecutionAllowed(address _derivativeOwner) public view returns (bool);
38
39
/// @notice Returns whether syntheticId implements pool logic
40
/// @return Returns whether syntheticId implements pool logic
41
function isPool() public view returns (bool);
42
43
/// @notice Sets whether thirds parties are allowed or not to execute derivative's on msg.sender's behalf
44
/// @param _allow bool Flag for execution allowance
45
function allowThirdpartyExecution(bool _allow) public;
46
47
// Event with syntheticId metadata JSON string (for DIB.ONE derivative explorer)
48
event MetadataSet(string metadata);
49
}
50
Copied!
Last modified 1yr ago
Copy link