OptionsMarket.sol
Last Updated At 20th Jan, 2025
OptionsMarket Interface Documentation
State-Changing Functions
addOptions
function addOptions(
address _underlyingAsset,
uint40 _expiry,
uint48[] memory _strikePrices
) externalAdds new options for a specific underlying asset
Creates options with multiple strike prices
Sets expiration time for the options
addUnderlyingAsset
function addUnderlyingAsset(
address _underlyingAsset,
address _optionsToken
) externalRegisters a new underlying asset for options
Associates the asset with its options token
Assigns a new underlying asset index
removeOptions
function removeOptions(
bytes32[] memory _ids
) externalRemoves multiple options by their IDs
Deactivates the specified options
Updates the active options count
View Functions
activeOptionsCount
function activeOptionsCount(
) external view returns (uint256)Returns the total number of active options
Used for system monitoring
getMainStableAsset
function getMainStableAsset(
) external view returns (address, uint8)Returns the main stable asset address and decimals
Used for price calculations
getOptionDetail
function getOptionDetail(
bytes32 _id
) external view returns (uint16, address, uint40, uint48)Returns details of a specific option
Includes underlying asset index, address, expiry, and strike price
getOptionId
function getOptionId(
uint16 _underlyingAssetIndex,
uint40 _expiry,
uint48 _strikePrice
) external pure returns (bytes32)Generates a unique option ID from parameters
Pure function for consistent ID generation
getOptionTokenId
function getOptionTokenId(
uint16 _underlyingAssetIndex,
uint40 _expiry,
uint8 _length,
bool[4] memory _isBuys,
bytes32[4] memory _optionIds,
bool[4] memory _isCalls,
uint8 _vaultIndex
) external view returns (uint256, bytes32[4] memory)Generates token ID for option combinations
Used for complex option positions
Returns token ID and associated option IDs
getOptionsBatch
function getOptionsBatch(
bytes32[] memory _ids
) external view returns (IOptionsMarket.Option[] memory)Returns details for multiple options in one call
Efficient batch retrieval of option information
getOptionsTokenByIndex
function getOptionsTokenByIndex(
uint16 _underlyingAssetIndex
) external view returns (address)Returns the options token address for an underlying asset index
Used for token management
getUnderlyingAssetByIndex
function getUnderlyingAssetByIndex(
uint16 _underlyingAssetIndex
) external view returns (address, uint8)Returns the underlying asset address and decimals for a given index
Used for asset management and calculations
indexToUnderlyingAsset
function indexToUnderlyingAsset(
uint16
) external view returns (address)Maps an index to its underlying asset address
Used for asset lookup
isOptionAvailable
function isOptionAvailable(
bytes32 _id
) external view returns (bool)Checks if an option is active and available for trading
Used for validation
isUnderlyingAssetActive
function isUnderlyingAssetActive(
address
) external view returns (bool)Checks if an underlying asset is active in the system
Used for asset validation
mainStableAsset
function mainStableAsset(
) external view returns (address)Returns the address of the main stable asset
Used for price calculations and settlements
nextUnderlyingAssetIndex
function nextUnderlyingAssetIndex(
) external view returns (uint16)Returns the next available index for underlying assets
Used when adding new assets
options
function options(
bytes32
) external view returns (
uint16 underlyingAssetIndex,
address underlyingAsset,
uint40 expiry,
uint48 strikePrice,
bool isActive
)Returns complete details of an option
Includes all option parameters and status
optionsTokenToUnderlyingAsset
function optionsTokenToUnderlyingAsset(
address
) external view returns (address)Maps an options token address to its underlying asset
Used for token-asset relationship lookup
registeredOptionsCount
function registeredOptionsCount(
) external view returns (uint256)Returns the total number of registered options
Includes both active and inactive options
underlyingAssetToIndex
function underlyingAssetToIndex(
address
) external view returns (uint16)Maps an underlying asset address to its index
Used for asset management
underlyingAssetToOptionsToken
function underlyingAssetToOptionsToken(
address
) external view returns (address)Maps an underlying asset to its options token
Used for token management
validateOptionIds
function validateOptionIds(
uint8 _length,
bytes32[4] memory _optionIds
) external view returns (
uint16 underlyingAssetIndex,
uint40 expiry,
uint8 availableLength
)Validates a set of option IDs
Checks consistency of underlying asset and expiry
Returns validation details
Administrative Functions
AuthorityUtil_init
function __AuthorityUtil_init__(
address _authority
) externalInitializes the authority utility module
Sets up permission management system
initialize
function initialize(
address _authority
) externalInitializes the options market contract
Sets up initial parameters and authority
renounceOwnership
function renounceOwnership(
) externalAllows owner to renounce their ownership
Security feature for decentralization
setAuthority
function setAuthority(
address _newAuthority
) externalUpdates the contract authority address
Used for permission management updates
setIsUnderlyingAsset
function setIsUnderlyingAsset(
uint16 _underlyingAssetIndex,
bool _isUnderlyingAssetActive
) externalSets the active status of an underlying asset
Controls which assets can be used for options
setMainStableAsset
function setMainStableAsset(
address _mainStableAsset
) externalSets the main stable asset address
Used for price calculations and settlements
transferOwnership
function transferOwnership(
address newOwner
) externalTransfers contract ownership to a new address
Used for administrative control changes
Events
AddUnderlyingAsset
event AddUnderlyingAsset(
uint16 indexed underlyingAssetIndex,
address indexed underlyingAsset,
address optionsToken
)Emitted when a new underlying asset is added
Records the asset index, address, and associated options token
AuthorityUpdated
event AuthorityUpdated(
address indexed authority
)Emitted when the contract authority is updated
Records the new authority address
OptionStatusChanged
event OptionStatusChanged(
bytes32 indexed id,
address indexed underlyingAsset,
uint40 indexed expiry,
uint48 strikePrice,
bool isActive
)Emitted when an option's status changes
Records all relevant option details and new status
OwnershipTransferred
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
)Emitted when contract ownership is transferred
Records both previous and new owner addresses
SetIsUnderlyingAsset
event SetIsUnderlyingAsset(
address indexed underlyingAsset,
bool isUnderlyingAssetActive
)Emitted when an underlying asset's status is changed
Records the asset address and new active status
SetMainStableAsset
event SetMainStableAsset(
address indexed mainStableAsset
)Emitted when the main stable asset is updated
Records the new stable asset address
UpdateOptionsToken
event UpdateOptionsToken(
address indexed underlyingAsset,
address optionsToken
)Emitted when an options token is updated for an asset
Records the underlying asset and new options token address
ABI
[
{
"type": "function",
"name": "__AuthorityUtil_init__",
"inputs": [
{
"name": "_authority",
"type": "address",
"internalType": "contract IOptionsAuthority"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "activeOptionsCount",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "addOptions",
"inputs": [
{
"name": "_underlyingAsset",
"type": "address",
"internalType": "address"
},
{
"name": "_expiry",
"type": "uint40",
"internalType": "uint40"
},
{
"name": "_strikePrices",
"type": "uint48[]",
"internalType": "uint48[]"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "addUnderlyingAsset",
"inputs": [
{
"name": "_underlyingAsset",
"type": "address",
"internalType": "address"
},
{
"name": "_optionsToken",
"type": "address",
"internalType": "address"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "authority",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "contract IOptionsAuthority"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getMainStableAsset",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint8",
"internalType": "uint8"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getOptionDetail",
"inputs": [
{
"name": "_id",
"type": "bytes32",
"internalType": "bytes32"
}
],
"outputs": [
{
"name": "",
"type": "uint16",
"internalType": "uint16"
},
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint40",
"internalType": "uint40"
},
{
"name": "",
"type": "uint48",
"internalType": "uint48"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getOptionId",
"inputs": [
{
"name": "_underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
},
{
"name": "_expiry",
"type": "uint40",
"internalType": "uint40"
},
{
"name": "_strikePrice",
"type": "uint48",
"internalType": "uint48"
}
],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "pure"
},
{
"type": "function",
"name": "getOptionTokenId",
"inputs": [
{
"name": "_underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
},
{
"name": "_expiry",
"type": "uint40",
"internalType": "uint40"
},
{
"name": "_length",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "_isBuys",
"type": "bool[4]",
"internalType": "bool[4]"
},
{
"name": "_optionIds",
"type": "bytes32[4]",
"internalType": "bytes32[4]"
},
{
"name": "_isCall",
"type": "bool[4]",
"internalType": "bool[4]"
},
{
"name": "_sourceVaultIndex",
"type": "uint8",
"internalType": "uint8"
}
],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "",
"type": "bytes32[4]",
"internalType": "bytes32[4]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getOptionsBatch",
"inputs": [
{
"name": "_ids",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"outputs": [
{
"name": "",
"type": "tuple[]",
"internalType": "struct IOptionsMarket.Option[]",
"components": [
{
"name": "underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
},
{
"name": "underlyingAsset",
"type": "address",
"internalType": "address"
},
{
"name": "expiry",
"type": "uint40",
"internalType": "uint40"
},
{
"name": "strikePrice",
"type": "uint48",
"internalType": "uint48"
},
{
"name": "isActive",
"type": "bool",
"internalType": "bool"
}
]
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getOptionsTokenByIndex",
"inputs": [
{
"name": "_underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getUnderlyingAssetByIndex",
"inputs": [
{
"name": "_underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint8",
"internalType": "uint8"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "indexToUnderlyingAsset",
"inputs": [
{
"name": "",
"type": "uint16",
"internalType": "uint16"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "initialize",
"inputs": [
{
"name": "_authority",
"type": "address",
"internalType": "contract IOptionsAuthority"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "isOptionAvailable",
"inputs": [
{
"name": "_id",
"type": "bytes32",
"internalType": "bytes32"
}
],
"outputs": [
{
"name": "",
"type": "bool",
"internalType": "bool"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "isUnderlyingAssetActive",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "bool",
"internalType": "bool"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "mainStableAsset",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "nextUnderlyingAssetIndex",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint16",
"internalType": "uint16"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "options",
"inputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"outputs": [
{
"name": "underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
},
{
"name": "underlyingAsset",
"type": "address",
"internalType": "address"
},
{
"name": "expiry",
"type": "uint40",
"internalType": "uint40"
},
{
"name": "strikePrice",
"type": "uint48",
"internalType": "uint48"
},
{
"name": "isActive",
"type": "bool",
"internalType": "bool"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "optionsTokenToUnderlyingAsset",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "owner",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "registeredOptionsCount",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "removeOptions",
"inputs": [
{
"name": "_ids",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "renounceOwnership",
"inputs": [],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "setAuthority",
"inputs": [
{
"name": "_newAuthority",
"type": "address",
"internalType": "contract IOptionsAuthority"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "setIsUnderlyingAsset",
"inputs": [
{
"name": "_underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
},
{
"name": "_isUnderlyingAssetActive",
"type": "bool",
"internalType": "bool"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "setMainStableAsset",
"inputs": [
{
"name": "_mainStableAsset",
"type": "address",
"internalType": "address"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "transferOwnership",
"inputs": [
{
"name": "newOwner",
"type": "address",
"internalType": "address"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "underlyingAssetToIndex",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "uint16",
"internalType": "uint16"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "underlyingAssetToOptionsToken",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "validateOptionIds",
"inputs": [
{
"name": "_length",
"type": "uint8",
"internalType": "uint8"
},
{
"name": "_optionIds",
"type": "bytes32[4]",
"internalType": "bytes32[4]"
}
],
"outputs": [
{
"name": "underlyingAssetIndex",
"type": "uint16",
"internalType": "uint16"
},
{
"name": "expiry",
"type": "uint40",
"internalType": "uint40"
},
{
"name": "availableLength",
"type": "uint8",
"internalType": "uint8"
}
],
"stateMutability": "view"
},
{
"type": "event",
"name": "AddUnderlyingAsset",
"inputs": [
{
"name": "underlyingAssetIndex",
"type": "uint16",
"indexed": true,
"internalType": "uint16"
},
{
"name": "underlyingAsset",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "optionsToken",
"type": "address",
"indexed": false,
"internalType": "address"
}
],
"anonymous": false
},
{
"type": "event",
"name": "AuthorityUpdated",
"inputs": [
{
"name": "authority",
"type": "address",
"indexed": true,
"internalType": "contract IOptionsAuthority"
}
],
"anonymous": false
},
{
"type": "event",
"name": "OptionStatusChanged",
"inputs": [
{
"name": "id",
"type": "bytes32",
"indexed": true,
"internalType": "bytes32"
},
{
"name": "underlyingAsset",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "expiry",
"type": "uint40",
"indexed": true,
"internalType": "uint40"
},
{
"name": "strikePrice",
"type": "uint48",
"indexed": false,
"internalType": "uint48"
},
{
"name": "isActive",
"type": "bool",
"indexed": false,
"internalType": "bool"
}
],
"anonymous": false
},
{
"type": "event",
"name": "OwnershipTransferred",
"inputs": [
{
"name": "previousOwner",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "newOwner",
"type": "address",
"indexed": true,
"internalType": "address"
}
],
"anonymous": false
},
{
"type": "event",
"name": "SetIsUnderlyingAsset",
"inputs": [
{
"name": "underlyingAsset",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "isUnderlyingAssetActive",
"type": "bool",
"indexed": false,
"internalType": "bool"
}
],
"anonymous": false
},
{
"type": "event",
"name": "SetMainStableAsset",
"inputs": [
{
"name": "mainStableAsset",
"type": "address",
"indexed": true,
"internalType": "address"
}
],
"anonymous": false
},
{
"type": "event",
"name": "UpdateOptionsToken",
"inputs": [
{
"name": "underlyingAsset",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "optionsToken",
"type": "address",
"indexed": false,
"internalType": "address"
}
],
"anonymous": false
}
]Last updated