Inspiration

On every blockchain mainnet, liquidity is dispersed across multiple DEXes. Whenever traders swap token A for token B, huge price impact occurs due to the lack of liquidity. Data shows that over 90% of trades with slippage in the interval [0.49%, 0.5%] were MEV attacked. Also, total profit from malignant MEV, also known as sandwich attack, exceeds $1.2B, and net profit from arbitrage MEV other than sandwich attacks profit is $297M since August 2020. As a result, demands for swap decrease, which in turn decreases liquidity providers’ profit. Hence, they become more reluctant to provide liquidity to the pools, and this decreased liquidity makes the price impact bigger, falling into a vicious cycle. Building our own DEX aggregator, LinkSwap, was motivated by our willingness to end this vicious cycle and improve market efficiency.

What it does

Linkswap finds the optimal route possible in the current block by searching all DEXes and executes the swap. It then provides MEV protection and minimize the slippage by cyclic arbitrage using flashloans whenever possible. For high-frequency DeFi quant trading firm whose trading lot size is larger than $500k, only 0.02% improvement in output can save about $1k in 10 swaps.

How we built it

We fetched block data from solidity viewer codes and built the search algorithm to find the optimal swap route. We investigated AMMs of all DEXes and made optimal engine using rust. We executed transactions by deploying contracts in the hardhat framework. For user UI/UX, we used typescript and nestjs to interact with server(go) and web app. We accumulated time-series data by using Redis to provide a robust price oracle(time-weighted / liquidity-weighted pricing) using our optimal engine. We deployed web-app, server for app service, using argocd & amazon service in the mainnet environment. We used Quicknode and allthatnode API for executing transactions and fetching the blockchain data.

Challenges we ran into

Adapting the interface for each DEX was one of the biggest obstacles, as there was little technical documentation and information on the contract address. Integrating the front-end & back-end was difficult to build due to the time difference.

Accomplishments that we're proud of

Our main accomplishment is aggregating separated liquidities and maximizing users' outputs by using routing engine combined with cyclic arbitrage logic, thereby minimizing users’ slippage. By doing so, we could solve the big huddle of low swap willingness problem. When cyclic arbitrage didn’t start from the native tokens of the blockchain, the profitability of cyclic arbitrage had to be reevaluated considering the price of the native token for paying the gas fee. At this point, Chainlink oracle played a key role in feeding our protocol the accurate price of the native token.

What we learned

We investigated ERC20 token specs as tax tokens made a lot of problems in the DEX Aggregating router. Also, we went through many DEX interfaces and AMM modeling. We integrated curveV1, Balancer, and UniV2 models but it would be expanded to any other AMMs such as curveV2, UniV3.

What's next for LinkSwap

Our roadmap of Linkswap is as follows. In this hackathon, Linkswap provides a Polygon & BNB chain DEX aggregator V2. Afterwards, we will provide a swapping function and an order book trade matching solution with Multichain and CEX integration. Eventually, we will expand our product to a multichain cross-swapping function, aggregating both EVM compatible and EVM incompatible mainnets. This will contribute to decreasing the price impact and slippage and maximizing DeFi traders’ experience.

Built With

Share this project:

Updates