Skip to content

Tutorial on how to rewrite UniswapV2 DEX in Sway on Fuel

Notifications You must be signed in to change notification settings

jecikpo/Tutorial-Sway-UniswapV2

Repository files navigation

Tutorial Sway UniswapV2 (FuniSwapV2)

This tutorial explains implementation of the famous UniswapV2 DEX in Sway. We will see that there is a couple of differences comparing to the original Solidity code that we have to redesign in order to make it fit for the Fuel VM.

Prerequisites:

  1. Knowledge of the Fuel VM and Sway language. You can start with my previous tutorial on SRC20.
  2. Familiarity with UniswapV2 code. Great resource can be found in the UniswapV2 Book.

The tutorial is split into parts:

  1. Part 1 - Pair - the equivalent of UniswapV2 UniswapV2Pair.sol - where the core of the LP and swapping logic resides.
  2. Part 2 - Pair Tests - Tests of the pair contract.
  3. Part 3 - Factory - this is where we define pool creations through the Factory (originally the UniswapV2Factory).
  4. Part 4 - Router - Here we define the periphery contract for interacting safely with different pools.

We call this implementation FuniSwapV2 because it is a Fuel version of UniswapV2.

Running

You can download and launch the code according to the following instructions:

git clone https://github.com/jecikpo/Tutorial-Sway-UniswapV2

Then build the project:

cd Tutorial-Sway-UniswapV2
forc build

Put your secrect key into the tests/utils/setup.rs file here:

pub const SECRECT_KEY: &str = "<YOUR_SECRECT_KEY_HERE>";

and run tests:

cargo test

About

Tutorial on how to rewrite UniswapV2 DEX in Sway on Fuel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published