Giter Site home page Giter Site logo

bowswap_ui's Introduction

๐Ÿน Bowswap

Setup

  1. Install the dependencies with yarn
  2. Create a .env file in the root directory with
ALCHEMY_KEY=YOUR_ALCHEMY_KEY
  1. Start the dev project with yarn run dev
  2. Go check the swap

How to generate the paths

Bowswap works by generating a path for each possible swap. Detecting the correct swap from one vault to another require some backtracking to try to find the correct, most optimal path.
Because of the number of possibilities, this is a very expensive operation.
From and To will always be Yearn Vaults, fetched directly from the Yearn API here: https://api.yearn.finance/v1/chains/1/vaults/all.
The possible paths (or listing) correspond to the possible pools from Curve Finance we could use to move from one specific LP token to another until we reach the underlying token of the To vault. The pools used are not limited to the one used in Yearn vaults, but integrates all the pools from Curve Finance, including the factory pools (ibBtc, ibEur for example).
All commands must be run in the root directory of the project.
Here are the steps to generate the paths. This can take a while.

  1. Update the listings we can use. This can be updated every time a new curve pool is created to try to find new paths.
npx hardhat run scripts/detect_listing.js > scripts/detected_listing.json --network localhost

This will create a new json file with the detected listings. This will be used in next scripts.

  1. The first feature of Bowswap is metapool_swaps. This is a way to swap 2 tokens belonging to the same metapool.
npx hardhat run scripts/detect_metapoolSwaps.js > utils/detected_metapoolSwaps.json --network localhost

The paths are generated by fetching all the vaults from Yearn and using the expect function from hardhat to try to perform the swap in a local fork with safe conditions. If the swap is successful, the path is saved in the utils/detected_metapoolSwaps.json file.

  1. The second and main feature of Bowswap is the swap command. This command will try to find the best path to swap the tokens.
npx hardhat run scripts/detect_swaps.js > scripts/detected_swaps.json --network localhost

This is the big backtracking function that will try to find the valid path. Depending on the depth (see Line ~217 : for (let max = 0; max < 7; max++) { where 7 is depth) it can be very slow. A new file will be created in the scripts folder and will be used the next script.

  1. A new feature was introduced to perform actual swap when possible and save 1 operation when possible. You can use this script to update the detected_swaps.json file.
node scripts/upgrade_swaps.js > utils/detected_swaps.json

Tests

You can test the paths with :

  • npx hardhat test tests/00_metapoolswaps.js --network localhost
  • npx hardhat test tests/01_swaps.js --network localhost

Links

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.