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: 52.65%(-0.39%/24h)
ETH Dominance: 16.28%(-0.21%/24h)
Defi Market Cap: $81.19B(-5.76%/24h)
Total Market Cap: $2156.46B(+1.26%/24h)
Total Trading Volume 24h: $99.24B(+1.15%/24h)
ETH Market Cap: $351.31B
Defi to ETH Ratio: 23.11%
Defi Dominance: 3.58%
Altcoin Market Cap: $1021B
Altcoin Volume 24h: $53.32B
Total Cryptocurrencies: 29493
Active Cryptocurrencies: 9864
Active Market Pairs: 82577
Active Exchanges: 761
Total Exchanges: 8438
BTC: 57663.28$(0.17%/1H)
ETH: 2923.72$(0.18%/1H)
AVAX: 32.77$(0.35%/1H)
BNB: 549.51$(0.27%/1H)
MATIC: 0.69$(0.52%/1H)
FTM: 0.67$(1.06%/1H)
ADA: 0.44$(0.09%/1H)
DOT: 6.85$(-0.18%/1H)
UNI: 6.97$(0.32%/1H)
CAKE: 2.47$(0.75%/1H)
SUSHI: 0.96$(0.37%/1H)
ONE: 0.02$(0.51%/1H)