Gains.farm Using Chainlink to Power Decentralized Leveraged Trading

Published on: 27.07.2021

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

Try our platform | Tutorial | Docs | More from Gains.farm

About Chainlink

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.

Solutions | Docs | Twitter | Discord | Reddit | YouTube | Telegram | GitHub

About Gains.farm

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.

Telegram Twitter Discord Docs

SOURCE: https://gainsfarm.medium.com/gains-farm-using-chainlink-to-power-decentralized-leveraged-trading-fe954b37eb97

Market Stats:
BTC Dominance: 56.8%(-0.21%/24h)
ETH Dominance: 12.19%(+0.01%/24h)
Defi Market Cap: $118.72B(+4.36%/24h)
Total Market Cap: $3366.42B(+1.47%/24h)
Total Trading Volume 24h: $124.4B(+3.62%/24h)
ETH Market Cap: $410.48B
Defi to ETH Ratio: 28.92%
Defi Dominance: 3.38%
Altcoin Market Cap: $1454.44B
Altcoin Volume 24h: $77.15B
Total Cryptocurrencies: 33049
Active Cryptocurrencies: 10502
Active Market Pairs: 95069
Active Exchanges: 772
Total Exchanges: 9811
BTC: 96549.02$(-0.17%/1H)
ETH: 3409.65$(-0.15%/1H)
AVAX: 38.31$(-0.35%/1H)
BNB: 705.61$(0.09%/1H)
MATIC: 0.5$(-0.12%/1H)
FTM: 0.9$(-0.58%/1H)
ADA: 0.9$(-0.32%/1H)
DOT: 7.18$(-0.36%/1H)
UNI: 13.96$(-0.69%/1H)
CAKE: 2.52$(0.51%/1H)
SUSHI: 1.49$(-0.1%/1H)
ONE: 0.03$(-0.88%/1H)