Gains.farm is a decentralized leveraged trading platform that uses a custom oracle architecture enabled by Chainlink.
Nobody should ever let the oracle be the weakness of their decentralized architecture — let it become a strength. Whether you want to integrate the most reliable price feeds of the industry with only a few lines of code, or need to create your own oracle network and handle specific APIs, Chainlink offers countless ways to enhance your product with both existing and custom solutions.
With that in mind, Gains.farm — a decentralized leveraged trading platform on Polygon — has built the first hybrid architecture that combines the widely used Chainlink Price Feeds with their own custom-built Chainlink decentralized oracle network (DON) to provide real-time, aggregated prices for their leveraged trading products.
Their oracle architecture uses a custom DON to supply on-demand prices to an aggregator contract while the official Chainlink Price Feeds serve as anchors, meaning if their price differs by more than 1.5% from Chainlink Price Feeds, a circuit breaker is triggered.
Gains.farm has already been running live on the Polygon mainnet for a few months, with everything described in this article already implemented.
Gains.farm’s Use Case for Chainlink Oracles
Decentralized leveraged trading platforms typically generate their own prices as part of their derivatives and futures contracts. They often use Chainlink Price Feeds as reference spot prices in order to compute the funding rate by looking at the difference between the spot price and the price of the futures contract.
Since Chainlink Price Feeds, or generally any price feeds, on Polygon are not updated every time a trade is made on our platform, we built an on-demand, real-time Chainlink DON that allows our users to trigger new oracle price updates on-chain and execute trading orders.
With trades on our platform executed using the real spot prices of listed assets, we don’t generate our own prices, and we don’t charge a funding fee.
How Gains.farm’s Oracle Architecture Works
Whenever an order needs to be executed on the platform, the trading contract requests the current spot price of the asset from our aggregator contract. The aggregator contract then requests the current price from our eight on-demand Chainlink nodes. Each of the Chainlink nodes take the median price from seven exchange APIs and send the result to the aggregator contract. For each median price it receives from our nodes, the aggregator contract double-checks with the corresponding Chainlink Price Feed to filter for outliers.
If there is a difference of more than 1.5% from the Chainlink Price Feed, it rejects the node answer and waits for the next answer. Once the minimum number of three answers is reached, the aggregator takes the median again and sends the final result to the trading contract to execute the order.
As you can see, each step of the process is decentralized, and there isn’t any single point of failure:
- There are seven APIs in total, and we only need a minimum of three to work.
- There are eight on-demand Chainlink nodes, making it impossible for a single person to manipulate the price.
- Our Chainlink nodes have redundant setups and do not depend on a single Polygon node for their WebSocket connection.
- Each on-demand Chainlink node answer is compared to the corresponding Chainlink Price Feed price to filter any outlier.
We anchored the entire security to Chainlink Price Feeds because they are built to provide maximum security, reliability, and accuracy. Most notably by using a multitude of premium data aggregators to achieve wide market coverage on each price point, as well as a decentralized architecture of professional node operators to ensure high availability and tamper-resistance.
Combining Chainlink’s wide collection of price feeds across numerous asset classes and time-tested reliability makes the creation of high-leveraged decentralized trading pairs on our platform a reality.
“Chainlink has certainly the most experienced and helpful team in the oracle space, and their open-source tools are cutting-edge, reliable, and easy to work with. It’s hard to envision DeFi without them.” — Seb, founder of Gains.farm
Chainlink is the industry standard oracle network for powering hybrid smart contracts. Chainlink Decentralized Oracle Networks provide developers with the largest collection of high-quality data sources and secure off-chain computations to expand the capabilities of smart contracts on any blockchain. Managed by a global, decentralized community, Chainlink currently secures billions of dollars in value for smart contracts across decentralized finance (DeFi), insurance, gaming, and other major industries.
Chainlink is trusted by hundreds of organizations, from global enterprises to projects at the forefront of the blockchain economy, to deliver definitive truth via secure, reliable oracle networks. To learn more about Chainlink, visit chain.link and subscribe to the Chainlink newsletter. To understand the full vision of the Chainlink Network, read the Chainlink 2.0 whitepaper. Want to discuss an integration? Talk to an expert.
Gains.farm is a decentralized leveraged trading platform and DeFi ecosystem integrated with Chainlink to leverage the official price feeds and its own on-demand oracle network for real-time prices, and with the Polygon Layer 2 to benefit from fast transactions and negligible fees.
Trade the median spot price of cryptocurrencies (and soon other assets) with up to 150x leverage, infinite liquidity (no market impact), and no funding fee.