Opium Protocol V2
Introduction
Opium v2 is a permissionless smart financial escrow protocol that allows its users to create fully customizable financial products. Its primary use-case is the management of derivatives, which are represented as a pair of LONG and SHORT ERC20 Opium position tokens. As a financial engineer, you can easily create a derivative contract with Opium v2 and be rewarded a portion of the reserves accrued by the protocol for each successful settlement of your own financial products. As a seller and buyer, you can partake in (for example) PUT or CALL options on an underlying by holding a specific Opium position token, you can exchange them on an AMM, exercise them at expiry or redeem them for initial margin if you hold an equal amount of LONG and SHORT positions. The focus of the design is to be as lean as possible as to enable the greatest flexibility and interoperability with other financial primitives.
Changelog from Opium Protocol v1
Completely removed
pooled derivative
logicChanged
ERC721o
toERC20
:LONG
andSHORT
position tokens and removedTokenMinter
contractRemoved all Matching contracts, as ERC20 positions are compatible with protocols like
1inch Limit Order Protocol
and0x
Changed Solidity version to latest with best practices refactoring
Changed
create
to supportamounts
instead ofquantities
(fractional derivatives)Separated
create
process intocreate
andmint
to reduce gas costsChanged
execute
to supportamounts
instead ofquantities
(fractional derivatives)Added
redeem
derivatives function to burnLONG
+SHORT
in return ofinitial margin
Added upgradability
Added emergency mechanisms
Added governance and roles
Performed additional refactoring and optimizations
Core protocol modules
Derivative author fees and protocol reserves
Execution
Derivatives authors can set a fee (limited) on the profit that trades make from execution. Part of this fee goes to protocol execution reserves and the rest goes to the derivative author.
Example:
Redemption
Security measures
Derivative data cache
Since all syntheticId’s (derivative logic contracts) are third party contracts that are being consumed by the protocol, protocol MUST consider them as potentially malicious and act accordingly. This is why all data consumption calls (except derivative parameters validation) are only made once and are stored in cache thereafter.
P2P Vaults
As an additional security measure there was introduced a so-called “P2P Vault”, which’s only purpose is a bookkeeping of cash flows for each particular derivative (ticker). It’s being increased on every incoming cash flow and deceased on every outcoming cash flow. It’s decreasing by greater value that it counts at the moment will result in transaction’s reverting.
This bookkeeping helps to prevent any potentially (not yet known) malicious derivatives from stealing funds withheld for other derivatives settlement.
ACL
Upgradability
All the core contracts of the Opium Protocol are upgradeable. The upgradeability is ensured by the openzeppelin’s “@openzeppelin/contracts-upgradeable” library which uses the unstructured storage proxies pattern and it is assumed that it safely protects from storage clashes between the proxy contract and the implementation contract. However, in order to avoid storage layout collisions between different implementation contract versions we have added a fixed length uint256 array (with 50 as length everywhere except for the OpiumPositionToken) which is assumed that will allow up to 50 storage slots (or 30 storage slots for the OpiumPositionToken) to add new variable/modify the contract without shifting down the storage layout and cause clashes.
Roles
Last updated