GitXplorerGitXplorer
p

dex_pallet

public
1 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
25473f450a585fddce99ae0df43ff11d18fed4b7

add 6551 pallet

ppoppyseedDev committed a year ago
Unverified
0730d4b7b248b4da4ee9aff5f5606e13a7f8962c

add 6551 pallet

ppoppyseedDev committed a year ago
Unverified
bd59582886491bc72203bf0e88c651b3371be8c6

node builds

ppoppyseedDev committed a year ago
Unverified
f261cbf1b71c3fa8ac9ec6726854153e28c4a4cc

change README

ppoppyseedDev committed a year ago
Unverified
c97ef61233a8d9674b762072e6af486ce0aaf5d6

cleaning

ppoppyseedDev committed a year ago
Unverified
04341a202c619be4aec656d70774466c4d890252

first commit

ppoppyseedDev committed a year ago

README

The README file for this repository.

DEX Implementation Overview

This repository implements a decentralized exchange (DEX) inspired by the mechanics of Uniswap V2. The DEX is created on a multi-asset platform, and it leverages the benefits of the included pallet_assets, though you are free to implement your own multi-asset pallet.

Users can trustlessly exchange tokens, incentivized by the fee rewards system which encourages them to create liquidity pools. The implemented API further acts as a "price oracle," drawing data from these existing liquidity pools.

Uniswap Version 2 Mechanics

To be elaborated further

Liquidity Pools

Users can create a liquidity pool by depositing two assets, setting the ratio (K), which is preserved during the swap operations. To regulate the creation of pools, a deposit of the native token is required from the user.

Key functions for managing liquidity pools include:

  • create_pool
  • add_liquidity
  • remove_liquidity
  • remove_pool

Token Swapping

The DEX ensures the constant product (K) remains constant during swaps. If asset A and asset B are swapped, where A is BALANCE_IN_POOL_OF_ASSET_A and B is BALANCE_IN_POOL_OF_ASSET_B, the preservation of K is as follows:

A * B = k
(A + a) * (B - b) = k

The liquidity providers are rewarded with a 5% flat fee drawn from the depositing asset during swaps. The fee is added directly to the pool balance.

Functions handling swapping include:

  • swap_exact_in_for_out
  • swap_in_for_exact_out

For detailed information, please refer to the official Uniswap documentation.

Future Work:

Immediate changes to consider include:

In lib.rs
  • Remove the StorageMap from the storage.
  • Make the fee percentage modifiable by moving the const FEE_PERCENTAGE: u32 = 5; to the config.
In tests.rs
  • Implement tests for various edge cases.
  • Validate event submissions.

TODO

  • Create some kind of asset or marketplace where users can use any token to purchase resources, using the price oracle to make sure users pay enough.
  • Integrate other DeFi utilities on top of your DEX.

A fresh FRAME-based Substrate node, ready for hacking 🚀

Setup

Please first check the latest information on getting starting with Substrate dependencies required to build this project here.

Development Testing

To test while developing, without a full build (thus reduce time to results):

cargo t -p pallet-dex
cargo t -p <other crates>

Build

Build the node without launching it, with release optimizations:

cargo b -r

Run

Build and launch the node, with release optimizations:

cargo r -r -- --dev

CLI Docs

Once the project has been built, the following command can be used to explore all CLI arguments and subcommands:

./target/release/node-template -h