Chainlink: Build a Custom Chainlink DON | Gains Network on DeFi
Primer: Find out more about Gains Network custom hybrid Decentralized Oracle Network (DON) in this interview with host Andy Boyan and guest Seb, the founder at Gains Network. Here, we go deep into the architectural difference between a default Chainlink price feed and the custom on-demand DON.
What is Gains Network?
A suite of DeFi products building on Polygon
The first product is gTrade - a decentralized leverage trading platform
Allows up to 150x leverage for trades on cryptocurrencies
43 cryptocurrencies listed with 10 forex pairs
One of the unique features is that they had built their own custom Chainlink Decentralized Oracle Network (DON)
Why build a custom on-demand Chainlink DON?
The goal is to allow a very high amount of leverage, hence they need very accurate price feeds that updates every second
The problem with default price feed is that they are not meant to be updated every second
Default price feed is good enough for lending platforms but is not designed for a very high leverage platform
If they want a price feed to be updated every second, they would have to spend a lot of gas
Having a custom DON will allow parameters to be set that fits the protocol’s requirements
The architecture for the default DON is also built differently
The default nodes take a median price and they sent only 1 answer on-chain
Gains network own custom DON will work only on-demand in a custom aggregator contract
“The cool thing that almost nobody knows for some reason is that Chainlink is a technical solution to listen to events on the blockchain and then send a price or really any data. It’s not just the price feeds; price feeds is just one use case of this technology and we leverage this technology by doing another use case.”
- Seb
Hence they invented an on-demand Chainlink DON
How does the custom DOM work?
When a trade order is sent on the platform, a request is made on Gains Network’s Chainlink nodes which will ‘listen’ to the blockchain for this event to happen
Their 8 nodes will each send the median price from the APIs of 7 exchanges back to the blockchain to their own aggregator contract
The Aggregator contract takes a minimum of 3 answers, finds the median price again so there is no single point of failure
Will not fail from either the APIs side or from the side of the nodes
It will take this median price to execute the trading order at the real-time price, which is updated every second
Recruiting operators for the custom DON
Time and effort to build a custom DON
Two aspects require a lot of work
The first is to find a good team of Chainlink node operators
Need to recruit and then work with them to build a trusting relationship
What they are doing requires a high level of tech skills, so they need to find skilled Chainlink node operators
Difficult lies in finding and recruiting
The second is finding the right APIs for setting the on-demand price feeds
For the cryptocurrencies price feed, it is connected directly to exchanges that are in the top 7 in volume, like Binance, Coinbase etc
For the forex price feed, selecting the APIs was a challenge because the data is not as easily accessible as crypto data. They need to pay for the APIs
How did he recruit the Chainlink node operators?
Found most of them on the Chainlink Discord. Worked together for a few months and did lots of tests
Took 3 to 4 months to get all the parameters right, so it is natural progress to see which has the right fit
💡 Market.link is a great place to find nodes. This is a marketplace for nodes and external adapters, which are ways that nodes can connect to outside data resources. One can use this resource to look at active nodes, their past work and their reputation. Another source is Reputation.link.
What specific skills are they looking for in their nodes?
Most important is being available almost 24/7 to monitor for problems as they arise
Connection to the blockchain to see if there are requests, like an event triggered in the smart contract to execute a trade
Needs connection to a polygon node - important because sometimes the polygon node can go out of sync. Needs to be live all the time
Needs an automatic switch in case the node goes down
The Difference between a Chainlink node and a DON?
A Chainlink node is just a single individual node but a DON is a bunch of nodes that communicate with each other to aggregate data off-chain and put that aggregated data on chain
DON is a far more decentralised and robust solution than using an individual centralized node
If you’re trading on 150x leverage on Gains Network based on one single node, someone can manipulate the price of that one exchange with a flash loan that can affect the leveraged position
The main value proposition of DON is that you can get the price from multiple different nodes from many different exchanges aggregated so that the price is more stable
Spot prices in gTrade
They are the only leveraged trading platform offering spot price because gTrade is a synthetic platform that can use any price feed or any API that they want
Found it better to use spot prices because it better reflects the true price of an asset
The spot price is derived from the median price of several exchanges, which is good to filter out outlier prices coming from a single exchange
Different exchanges will have different spot prices because each exchange has a different volume of trades, with different demand and supply in their own order books. All these factors will affect the prices
Prices stay nearly the same but not exactly the same due to arbitrageurs who will buy the asset from a cheaper exchange to sell to another exchange
Other platforms use derivative contracts that are used to track the price of the underlying asset
This means you trade the contract rather than the spot price of the assets
Even though the contract is meant to follow the price, it’s not the same
This will prevent big wicks in prices that will liquidate a lot of people
What is the core innovation behind this to allow Gains Network to use spot prices?
They can use spot prices because they are a synthetic platform so they don’t have order books from each pair listed on the platform
No generation of own prices
The core innovation behind being a synthetic platform is the minting/burning of the native GNS token to handle trading profits and losses
Minting/burning of GNS
💡 TLDR: If a trader wins, it’ll mint GNS tokens to pay for the wins. Conversely, if a trader loses, it’ll burn the tokens. Since in the long run, there will be more trading losses and wins, this will create a deflationary effect on the GNS supply
All the traders interact with the platform using DAI, so they need a GNS/DAI pool
In the past, the traders have to buy GNS to trade, so trading with DAI is a better user experience
When a trader opens a trade using DAI as collateral, the DAI goes to a DAI vault
When the position is closed, the DAI collateral plus the profit or loss will come out of this vault
At the point of the interview, there are about 2 million in the DAI vault
If the balance of the vault goes below 2 million, it can be refilled by minting and selling GNS in small amounts over time to spread the selling pressure
If the balance goes above a certain threshold (currently above 10% of the initial balance), it will buy and burn GNS on the market over time using the excess DAI
Hence the DAI vault is backed by the GNS-DAI liquidity
Link rewards for nodes in custom DON
To incentivise Chainlink nodes to fetch the price, LINK rewards have to be given to them. How does Gain Network ensure that the nodes always have LINK tokens to fund their work?
A small fee is charged on every trade and a portion of that fee goes to their Chainlink nodes
This incentivizes them by paying for the gas cost and also making a profit
Their custom Chainlink DON is sustainable and profitable for the nodes
The 8 nodes earn a total of $35k per month on average
About 4-5k per month for each node
What’s coming next for Gains Network?
A lot of optimizations
Partial closing, partial adding to positions
Will bring stocks, commodities, indices and any cross pairs like DOGE/TSLA to the platform
The custom architecture will guarantee the stop loss price
If the price goes fast below the stop loss, the platform can trigger the stop loss at the price it was set
All information presented above is for educational purposes only and should not be taken as investment advice. Summaries are prepared by The Reading Ape. While reasonable efforts are made to provide accurate content, any errors in interpreting and summarising the source material are ours alone. We disclaim any liability associated with the use of our content.