ERC20-compatible Option Contracts
Option contracts as ERC20-compatible tokens
UPDATE
You can try the DAPP on the http://www.erc20-options.com
Preface
In the crypto-currency world the number of traded tokens and their trading volume increased dramatically since the last time. The volatility of the market and increased trading activity implies significant demand for the derivative instruments. There are several projects which are active in the creation of them, but there are still not many production-ready solutions. Failure to find some instrument similar to "normal" call/put options was a motivation for me (along with the desire to "dive in" into Smart Contract world) to create one.As a result I implemented creation ERC20-compatible option contracts (which allows them, contrary to other implementations, relatively easily to be traded via numerous Ethereum based exchanges and protocols).
General information about "normal", "off-chain" option contracts one can read in Wikipedia Option (finance) article. Below there are some specific things about implementation, based on Ethereum smart contracts.
Main Contracts
Option Contract. Gives its owner the right to get the specified amount of underlying (ERC20) tokens in exchange for basis ERC20 tokens during the period before expiration at the specified price (strike price). The transaction, which uses this right, is called "exercise"
Anti-Option Contract. Gives a right to get "non-exercised" part of deposited underlying and “exercised” part of basis token after the expiration date, or, if combined with Option Contract, to get the corresponding token amount before the expiration date.
Actors
- Option House: owner the generating contracts, defines the fee policy.
- Option Pair Creator: creates the 2 ERC20 compatible token contracts
- Option Writer. Deposits the "underlying" ERC20-compatible tokens with minimum amount specified by by Option Line. in exchange she gets ERC20-compatible option contract as well as ERC20-compatible “anti-option” contract (s. later). For this transaction Option Writer pays fee.
- Option Buyer. Buys Option Contracts e.g. on exchanges (the Option Contracts are fully ERC20-compatible), via 0x protocol etc.
- Anti-Option Buyer. As Option Writer side of contracts is tokenized, one can sell / buy the Option Writer right to withdraw the deposit after expiration time too.
Use Cases
- Creation Option Token Contracts:
- Option Writing
- Option Exercise:
- Withdraw:
- Annihilate:
Example
Ann creates 2 (Option and Anti-Option) ERC20-compatible contracts which specify as underlying WETH (wrapped Ethereum, to make it ERC20-compatible) and basis DAI tokens, with the strike price 3000 and expiration date 31.12.2018 (current price at the time of writing is about 900 DAI per WETH).
Bob "writes" 10 option contracts. That is he deposits 10 WETH and get (or mint) 10 Option (OPTWETHDAI20181231) and 10 Anti-Option contracts (AOPTWETHDAI201812_31). At this point the fee could be taken. Note in the tables below the fees are not considered!
| Options | Anti-Options | WETH | DAI | |
| Meta-Option Contract | 10 | 0 | ||
| Bob | 10 | 10 | 0 | 0 |
| Clair | 0 | 0 | 0 | 350 |
Bob sells 7 OPTWETHDAI3112_2018 contracts to Clair for 50 DAI (actually could be any asset)
| Options | Anti-Options | WETH | DAI | |
| Meta-Option Contract | 10 | 0 | ||
| Bob | 3 | 10 | 0 | 350 |
| Clair | 7 | 0 | 0 | 0 |
At 01.09.2018 Bob will get back some WETH. He "annihilates" the remaining 3 OPT1WETH3000DAI20181231 with 3 anti-option contracts (AOPT1WETH3000DAI201812_31) and gets 3 from WETH back
| Options | Anti-Options | WETH | DAI | |
| Meta-Option Contract | 7 | 0 | ||
| Bob | 0 | 7 | 3 | 350 |
| Clair | 7 | 0 | 0 | 0 |
The price of Ethereum went up and per 2018-11-01 the price reaches 4000 DAI per WETH. Clair decides to exercise 5 of her options. So she borrows and transfers 5 3000 (strike price) to meta-option contract and get back 5 WETH. These 5 WETH she sells on exchange at 4000 to make 5000 (5 (4000 - 3000) ) DAI. Another possibility is to exercise option with exchange. In this case Clair does not need basis token at all. The corresponding amount of underlying is exchanged by the smart contract. As a result she gets DAI (exceed amount above corresponding "strike" amount) directly. Two option contracts she would like to hold for further growth.
| Options | Anti-Options | WETH | DAI | |
| Meta-Option Contract | 2 | 15000 | ||
| Bob | 0 | 7 | 3 | 350 |
| Clair | 2 | 0 | 5 | 0 |
| Options | Anti-Options | WETH | DAI | |
| Meta-Option Contract | 2 | 15000 | ||
| Bob | 0 | 7 | 3 | 350 |
| Clair | 2 | 0 | 0 | 5000 |
Suddenly the price drops for 2000 DAI (below strike) per WETH and remains below the strike price till expiration date. After expiration date Bob can withdraw the remaining 2 WETH (10 initial - 3 annihilated - 5 exercised) and 15000 DAI (from exercised part)
| Options | Anti-Options | WETH | DAI | |
| Meta-Option Contract | 0 | 0 | ||
| Bob | 0 | 0 | 5 | 15350 |
| Clair | 2 (expired) | 0 | 0 | 5000 |
Exercise with exchange
The operations are displayed on the sequence diagram.
As it can be seen it allows for option holders exercise options without holding basis tokens at all. The smart contract exchange the requested amount of options and transfer excess amount above strike of basis token to option seller.
E.g. Clair has 10 Option contracts for WETH as underlying at strike 300 DAI per 1 WETH. Current price of WETH at exchange is 350 DAI. By selling 10 contracts with exchange, the smart contract sells 10 WETH and gets 3500 DAI. From this amount 500 DAI goes to Clair, the 3000 DAI (strike * 10 contracts) remain at the smart contract for further withdraw by "anti-option" holders
Monetisation: Option Series Creation and Fees
The main idea of monetisation is collection the fees during option writing. The right to withdraw fees belongs to a ERC721 "option serie" token owner.An user can create option serie and write options just after that. During the creation a ERC721 token is minting to a specific account. Besides this specific "fee collector" contract is created. From this contract the collected fees can be withdrawn only by a corresponding ERC721 token owner. The ERC721 token can be directly transferred to an auction for sale (currently it goes to the owner of the corresponding contract)

Others
- Put option contract
- Differences to "normal" option contract
Naked Options*: cannot be created
Installation, Testing
Pre-requisite: truffle installation. To install run:npm install -g truffle
To test clone repo and run tests with the help of truffle run the next snippet
git clone https://github.com/mxn/eth_option.git
cd eth_option
npm install
truffle test
The example of usage of the smart contracts can be seen under test/ directory
The web frontend is currently being developed in https://github.com/mxn/ethoptionui.git repository.
Current State
MVP version of the contracts with the web-frontend deployed on the http://www.erc20-options.com.The implementation is being made in my spare time. Generally I would be glad to find some support to proceed with the things further with more dedicated time for the development (I have a couple other ideas to monetise the solution).
If you are interesting in supporting the project, please use the contact form