@interlay/xopts
v0.2.18
Published
Bitcoin-backed put options on Ethereum.
Downloads
138
Readme
XOPTS
About
In traditional finance, an option enables the owner to buy or sell an underlying asset at a specified conversion rate before an expiration date. XOPTS extends the native capabilities of Ethereum to track and execute PUT Options against BTC. Specifically, we enable sellers to lock DAI collateral in a contract to mint ERC-20 compatible option tokens that can be traded on Uniswap. Buyers can then insure an arbitrary amount of BTC relative to the contract's strike price and pay in an amount of DAI collateral as premium. Finally, options can be exercised once the buyer proves payment to the respective writers of that contract using an on-chain Bitcoin SPV client.
Protocol
- A seller (writer) creates a BTC put option with a strike price (the value of BTC the seller is willing to insure in Dai), an expiry time (the validity of the option), and a premium (the fee paid to the seller for buying an option in Dai).
- A seller writes an option contract previously created by locking a number of Dai into the option contract. This creates a number of option tokens with the specific expiry, premium and strike price that are now available for buyers to obtain. During this process the seller also attaches his BTC address to the option tokens. For example, if the strike price is 10,000 Dai for a BTC and the seller locks 1,000 Dai, he would have generated 1,000 option tokens.
- The buyer then goes ahead and buys a number of option tokens at a specific expiry, premium, and strike price.
- During the expiry time, the buyer can exercise the option. To achieve this, he must send a number of BTC to the seller. Then, he proves that he sent the required number of BTC to the option smart contract. In return, the option tokens are burned and the buyer obtains underlying Dai provided by the seller.
- After the expiry time, the seller can reclaim any unused collateral.
- At any time a buyer can exchange his option tokens on Uniswap in a (Dai/Options) trading pair.
System Overview
You can find more details on how XOpts works in our Guides (buy, sell, exercise, refund options).
Built with
Getting Started
Make sure you have node installed. Generally, we also recommend managing different version of node via version manager like NVM.
Clone this repository and enter into its root folder.
git clone [email protected]:interlay/xopts.git
cd xopts
Install the required node packages.
yarn install
Try it out
Compile the contracts and create the TypeChain interfaces.
yarn build
Start buidlerevm.
yarn buidler
In another terminal, deploy the contracts and create some test data. Execute this from the root folder of the project.
yarn deploy::test --network localhost
Note that you can deploy without specifying the network but this will not persist, hence we start an Ethereum node first.
Go to xopts.io and point your MetaMask wallet to localhost:8545
. On your first setup, you might need to add one of the buidlerevm accounts to your MetaMask list of accounts by importing the private key. You can find the private keys of the buidlerevm accounts in the console output where you started buidler evm (with the yarn buidler
command). It should look like this:
Development
After compiling the contracts as described above, run the tests.
yarn test
Docker
Tests for both smart contracts and frontend can be executed within Docker.
docker build . -t interlay/xopts
docker run -t interlay/xopts yarn test
docker run -t interlay/xopts yarn test-js
Docs
We build our docs using solidity-docgen and docsify.
yarn docs
Point your local browser to ./docs/index.html
or use the docsify-cli
tool to start a live reload development server.
yarn global add docsify-cli
docsify serve ./docs
Releasing
Prior to bumping the package.json
version, first clean and rebuild the project.
yarn clean
yarn build
yarn tsc
yarn publish --access public
Bitcoin Testnet
In order to verify testnet transactions we need to swap out any mocked components.
- Launch a local instance of Ganache via
yarn run ganache
. - Clone the btc-relay-sol repository.
- Deploy using the testnet configuration.
- On
OptionPool
deployment use the live relay address and./lib/TxValidator.sol
.
React UI
Clone the xopts-ui and in a separate terminal window.
git clone [email protected]:interlay/xopts-ui.git
yarn install
yarn start
You can interact with a locally deployed front-end on localhost:3000.
Deployments
Gas Costs
| Function | Gas | Details |
|---------------------|---------|-----------------------------|
| constructor
| 4459604 | Deploy Option Factory |
| createOption
| 3099130 | Create Sell & Buy ERC-20 |
| writeOption
| 241516 | Deposit Collateral |
| transfer
| 119209 | Transfer Unsold Options |
| insureOption
| 221144 | Buy Options At Premium |
| transfer
| 117892 | Transfer Sold Options |
| exerciseOption
| 59380 | Prove BTC Payment |
Ethereum Ropsten Testnet
- Collateral (ERC20): 0xF6832c228552b551aA4Bf6A17Da9cf435D6cC524
- OptionPool: 0x929bcF49ce947535815b3A34ac312D027ec06825
- Interlay's BTC-Relay: 0x78A389B693e0E3DE1849F34e70bf4Bcb57F0F2bb
You can interact with Xopts on xopts.io or run a locally deployed front-end on localhost:3000.
Roadmap
- [x] Put Options
- [ ] Call Options
Contributing
If you would like to contribute, please file an issue on Github or reach out to us.
We are hiring!
License
(C) Copyright 2020 Interlay Ltd
XOPTS is licensed under the terms of the Apache License (Version 2.0). See LICENSE.
Contact
Website: Interlay.io
Twitter: @interlayHQ
Email: [email protected]