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: 59.78%(-0.04%/24h)
ETH Dominance: 12.65%(-0.14%/24h)
Defi Market Cap: $83.03B(-25.69%/24h)
Total Market Cap: $2950.96B(-1.94%/24h)
Total Trading Volume 24h: $219.1B(-27.77%/24h)
ETH Market Cap: $372.92B
Defi to ETH Ratio: 22.26%
Defi Dominance: 2.69%
Altcoin Market Cap: $1186.8B
Altcoin Volume 24h: $133.88B
Total Cryptocurrencies: 32219
Active Cryptocurrencies: 10060
Active Market Pairs: 89353
Active Exchanges: 760
Total Exchanges: 9575
BTC: 89177.86$(-0.12%/1H)
ETH: 3098.96$(-0.13%/1H)
AVAX: 32.24$(-0.59%/1H)
BNB: 622.88$(-0.2%/1H)
MATIC: 0.36$(0.02%/1H)
FTM: 0.7$(-0.02%/1H)
ADA: 0.62$(3.4%/1H)
DOT: 4.93$(0.06%/1H)
UNI: 8.27$(-0.49%/1H)
CAKE: 1.8$(-0.44%/1H)
SUSHI: 0.72$(-0.25%/1H)
ONE: 0.01$(-1.07%/1H)