Git Product home page Git Product logo

swapr-sdk's Introduction

Swapr SDK

Getting Started

First clone the repository:

git clone https://github.com/levelkdev/swapr-sdk.git

Move into the dxswap-sdk working directory

cd swapr-sdk

Install dependencies

yarn install

Generate GraphQL

yarn codegen

Build

yarn build

Connect package an app to sdk locally

yarn link

And on the app repo

yarn link "../swapr-sdk/" #e.g. path to sdk

Running tests

To run the tests, follow these steps. You must have at least node v16 installed.

Run tests

yarn test

Eco Router Trades

Swapr uses multiple trades to find best protocol and route for traders. Currently supported DEXs are

Protocol Ethereum Arbitrum One Gnosis Chain Polygon BNB Chain Optimism ZkSync Era
0x βœ… βœ… ❌ βœ… βœ… βœ… ❌
1Inch βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Baoswap ❌ ❌ βœ… ❌ ❌ ❌ ❌
BiSwap ❌ ❌ ❌ ❌ βœ… ❌ ❌
CoW Protocol βœ… ❌ βœ… ❌ ❌ ❌ ❌
Curve βœ… βœ… βœ… ❌ ❌ ❌ ❌
DFYN ❌ ❌ ❌ βœ… ❌ ❌ ❌
Honeyswap ❌ ❌ βœ… ❌ ❌ ❌ ❌
Levinswap ❌ ❌ βœ… ❌ ❌ ❌ ❌
Pancakeswap ❌ ❌ ❌ ❌ βœ… ❌ ❌
Quickswap ❌ ❌ ❌ βœ… ❌ ❌ ❌
SushiSwap βœ… βœ… βœ… βœ… βœ… ❌ ❌
Swapr βœ… βœ… βœ… ❌ ❌ ❌ ❌
Uniswap v2 βœ… βœ… βœ… βœ… ❌ βœ… ❌
Velodrome ❌ ❌ ❌ ❌ ❌ βœ… ❌

The Trade class is extendable. New DEXs can be added to the SDK by extending the Trade and adding required methods.

How To Add Routable Platforms

For UniV2 Forks

First, open the file UniswapV2RoutablePlatform.ts. Here, you'll find several examples of already integrated DEXs.

Next, you need to search for the following information about the platform you want to integrate:

  • Supported chains by the DEX.
  • Factory Address: You can find it in the protocol docs.
  • Router Address: You can find it in the protocol docs.
  • Init Code Hash: Looking at the Factory Address in a blockchain explorer, you can go to the Contract tab > Read Contract > INIT_CODE_HASH.
  • Default Swap Fee: You may find it in the protocol official docs or in the Factory Address code.
  • Subgraph Endpoint (optional).

Once you have this information, you can create an instance of UniswapV2RoutablePlatform for the DEX you're trying to integrate and then consume it from the file entities/pair.ts so you can add it to the PAIR_ADDRESS_CACHE.

swapr-sdk's People

Contributors

0xvenky avatar adamazad avatar berteotti avatar denciu avatar dependabot[bot] avatar diogomartf avatar elrodrigote avatar jorgedclopes avatar jpkcambridge avatar mi-lan avatar moodysalem avatar mwiniarsk avatar noahzinsmeister avatar seibelj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

swapr-sdk's Issues

Add support for xDAI in Curve trade

Curve does not support the native xDAI token on Gnosis Chain. It only works with ERC20 stable tokens: WXDAI, USDC, and USDT.

AC

  • Curve Trade can return a quote for trading XDAI to/from USDC and USDT.
  • A multicall interceptor should wrap the XDAI before sending it to the Curve 3CRV pool.

Fix Uniswap support on Polygon

Uniswap underlying Ether implementation does not support MATIC. The solution is creating another NativeCurrecny called MaticNativeCurrency. This is what Uniswap interfaces use internally.

AC

UniswapTrade supports Polygon's Matic.

Compute Uniswap v2 common pairs from The Graph

common pairs list is a collection of pairs that could link currencyA to currencyB. For instance, I trade from WETH to CRV. A possible trade route would be:

WETH > WETH-USDC > USDC-CRV > CRV

WETH-USDC and USDC-CRV are the common pairs between WETH and CRV. This is list is computed in the SDK by assuming that every token will have a pool of the token and a stablecoin or the native token of the given chain. For example, CRV will likely to have a pair of CRV-WETH and CRV-USDC. This approach discriminates against less known tokens by skipping potential pairs that would be more liquid and given better rates.

The solution is to utilize The Graph and find these pairs by running such query with the following conditions:

where token0 = tokenA OR token1 = tokenA OR token0 = tokenB OR token1 = tokenB

This yields all the pairs that have either currencyA or currencyB. The above query can include reserves, which leads to a slight gain in performance.

AC

The common pairs list is computed from the subgraph. If the subgraph query fails due to network, default to the current SDK implementation.

Add factory pools to Curve

Description

Curve v2 has a factory contract to deploy new Curve pools.

Acceptance Criteria

  • CurveTrade can find and get quotes from Curve v2 pools

Curve Router not going through ETH pools

Description
When users tries to route through eth/seth, eth/steth, reth/eth etc...Router doesn't pick them up

Definition of done

  • All eth pools mentioned should return a quote from curve since they are liquid and existing

  • Swapr
    Screenshot 2022-07-28 at 17 47 07

  • Curve
    Screenshot 2022-07-28 at 17 48 07

Upgrade to Multicall3

Currently, the SDK uses Multicall2. Upgrade to Multicall3 and add a factory function.

Remove JSBI in favor of BigNumber

Jumping between JSBI and BigNumber/parseUnits from ethers.js is not ideal.

AC

  • JSBI is replaced with BigNumber instance and parseUnit/formatUnits

`Pair` class bug with default parameters

The Pair constructor parameter uses Swapr as the default platform:

https://github.com/levelkdev/swapr-sdk/blob/dae13a9fcd8aa7a6a05edaa298ce21e44ae64c74/src/entities/pair.ts#L114-L134

Pair.getOutputAmount and Pair.getInputAmount do not pass the same platform back to the construct when calling creating new Pair instances

https://github.com/levelkdev/swapr-sdk/blob/dae13a9fcd8aa7a6a05edaa298ce21e44ae64c74/src/entities/pair.ts#L205-L231

https://github.com/levelkdev/swapr-sdk/blob/dae13a9fcd8aa7a6a05edaa298ce21e44ae64c74/src/entities/pair.ts#L233-L263

When the wrong platform (Swapr for example on Polygon) is used, the Pair.getAddress throws an unsupported platform error:

https://github.com/levelkdev/swapr-sdk/blob/dae13a9fcd8aa7a6a05edaa298ce21e44ae64c74/src/entities/pair.ts#L84-L92

The fix is to pass back the instance platform property in Pair.getOutputAmount and Pair.getInputAmount.

This logic error affects any EVM chain where Swapr is not supported and potentially leads to calculating the wrong UniswapV2Pair address using keccak256 method.

AC

  • Pair.getOutputAmount and Pair.getInputAmount pass back the current instance's platform.
  • Platforms, where Swapr is not deployed, should return a trade list.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.