Derivatives are endlessly useful in the financial world, but they are quite difficult to replicate on a blockchain. One of the reasons is that the value of a financial derivative must be reliant on the price of an underlying asset, and such information is not readily available in a typical decentralized setting. With the introduction of native oracle services into Neo N3, retrieving data from a reliable off-chain source has never been easier, thus making it possible for us to model one of the simplest derivatives there is: a binary option.
What it does
NeoOps allows its users to speculate on the price of a trading pair on Binance. They can do so by joining pools opened by managers as either a long position or a short position. A pool specifies its expiry time, its required margin and token, its underlying asset, say, 'BTCUSDT', and the asset's strike price. Then at expiry, the pool owner invokes the oracle call to feed in the external price data of the asset and distribute the payout. All of which are automated by an N3 smart contract. Hash of the contract: 0x3d2824ad4bbdf36dd2511c4a16c666317765d84a
How we built it
NeoOps has basically two components: a smart contract deployed on Neo N3 blockchain responsible for the backend logic: creating pools, taking long or short positions, making oracle calls and distributing payouts, etc., and a frontend interface as an entry point for our less experienced users to interact with the contract. We wrote our contract logic with python, with the help of the Neo3-boa compiler and deployed it on Neo N3 TestNet. We used Vue.js as our front-end framework and incorporated the NeoLine wallet into our design. All of our invocation transactions are made through NeoLine dAPIs.
Challenges we ran into
One big issue we kept running into was type conversions: between ByteArrays, Addresses, Hash256s and Hash160s and sometimes it's really confusing what type of parameters needed to be passed in to make a correct RPC call and what type of parameters we should keep inside smart contracts.
Another issue is that we were not quite familiar with asynchronous programming, but dealing with blockchain data required many 'async's and 'await's. So it was a little difficult for us in the beginning to query the NeoLine dAPI and perform the correct error handling. Luckily, soon enough, we got used to the syntax and finished the frontend logic.
Accomplishments that we're proud of
- deploying a full-fledged web application
- deploying a functioning smart contract on Neo N3 Testnet
What we learned
- the basic structure of a smart contract on Neo N3
- how smart contracts can be invoked and transactions can be settled
- how the Oracle service works on Neo
- how to make an RPC call
What's next for NeoOps
There are a couple of features we would like to include in our UI design:
- add searching mechanisms to the various pages so that users will be able to search for a particular symbol, status or expiry, etc.
- add a recent price chart to each underlying Binance symbol so that users will be able to investigate price fluctuations easier
- implement automatic refreshing and transaction confirmation
- shorten response time and improve performance in general