Skip to content

A Concentrated Liquidity AMM Decentralized Exchange Engine: Users can swap their tokens for a different one. This CLAMM-DEX can generate it's liquidity providers upto 400% more interest on the same capital when compared to traditional AMM-DEX.

Notifications You must be signed in to change notification settings

yug49/CLAMM-DEX-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLAMM-DEX-Engine

It is a smart contract project written in Solidity using Foundry.

  • It a smart contract I developed leveraging Foundry.
  • It is a CLAMM - Concentrated Liquidity Automated Market Maker Decentralized Engine similar to Uniswap v3, but with some less additional functionalities.
  • Following properties are ommited when compared to the Uniswap v3 engine.
    • Factory
    • Price oracle
    • Protocol fee
    • Flash swap
    • NFT
    • Solidity advanced math libraries
    • Callbacks

Getting Started

  • git: You'll know you did it right if you can run git --version and you see a response like git version x.x.x
  • foundry: You'll know you did it right if you can run forge --version and you see a response like forge 0.2.0 (816e00b 2023-03-16T00:05:26.396218Z)
  • make (optional - either you can install make or you can simply substitute the make commands with forge commands by referring to the Makefile after including your .env file): You'll know you did it right if you can run make --version and you will see a response like GNU Make 3.81...

Installation

  • Install CLAMM-DEX-Engine
    git clone https://github.com/yug49/CLAMM-DEX-Engine
    cd CLAMM-DEX-Engine
  • Make a .env file
    touch .env
  • Open the .env file and fill in the details similar to:
    SEPOLIA_RPC_URL=<YOUR SEPOLIA RPC URL>
    ETHERSCAN_API_KEY=<YOUR ETHERSCAN API KEY>
    SEPOLIA_PRIVATE_KEY=<YOUR PRIVATE KEY>

    # Arguments for Pool Deployment
    TOKEN_A=<ADDRESS OF TOKEN A>
    TOKEN_B=<ADDRESS OF TOKEN B>
    FEE=<FEES IN BASIS POINTS(either 500, 3000 or 10000)>
    INITIAL_SQRT_PRICE_X96=<INTIAL SQUARE ROOT PRICE X96>

    # Arguments for Position Management
    LOWER_TICK=-<LOWER TICK>
    UPPER_TICK=<UPPER TICK> 
    AMOUNT_TO_ADD=<AMOUNT OF LIQUIDITY TO ADD>
    AMOUNT_TO_REMOVE=<AMOUNT OF LIQUIDITY TO REMOVE>

    # Arguments for Collection of Fees or Removed/Burned Liquidity
    AMOUNT0_TO_COLLECT=<AMOUNT OF TOKEN A TO COLLECT>
    AMOUNT1_TO_COLLECT=<AMOUNT OF TOKEN B TO COLLECT>

    # Arguments for Swap Management
    SWAP_AMOUNT=<AMOUNT OF TOKENS TO SWAP>
    SQRT_PRICE_LIMIT_X96=<SQRT PRICE LIMIT X96 WHILE SWAPPING>
  • Remove pre installed cache, unecessary or partially cloned modules modules etc.
    make clean
    make remove
  • Build Project
    make build

Formatting

  • to format all the solidity files:
    make format

Deployment

Deploy On a Local Network (Anvil Testnet)

  • To Deploy on a local network first run anvil on your local terminal in current directory by running coommmand: make anvil.
  • Now open another terminal and let this one run in the background
  • Run the following command:
    make deploy

Deploy on a Sepolia or Any Other Network

  • To Deploy on Sepolia, after successfully creating .env file as mentioned above.
  • Get youself some Sepolia Eth and LINK tokens and then run command:
    make deploy ARGS="--network sepolia"

Interacting with the deployed contract

  • To interact with the deployed smart contract first change the POOL_ADDRESS in the script/Interactions.s.sol file to the address of your deployed contract.
  • Then you can run following commands for respective interactions:

Add Liquidity

    make addLiquidity ARGS="--network sepolia"

Remove Liquidity

    make removeLiquidity ARGS="--network sepolia"

Collect Fees And Removed Liquidity

    make collectFeesAndRemovedLiquidity ARGS="--network sepolia"

Swap Tokens

  • To swap from tokenA to tokenB, knowing only the amount of tokenA to swap:
    make swapTokensZeroForOneExactInput ARGS="--network sepolia"
  • To swap from tokenB to tokenA, knowing only the amount of tokenB to swap:
    make swapTokensOneForZeroExactInput ARGS="--network sepolia"
  • To swap from tokenA to tokenB, knowing only the amount of tokenB to swap:
    make swapTokensZeroForOneExactOutput ARGS="--network sepolia"
  • To swap from tokenB to tokenA, knowing only the amount of tokenA to swap:
    make swapTokensOneForZeroExactOutput ARGS="--network sepolia"

🔗 Links

Loved it? lets connect on:

twitter linkedin

About

A Concentrated Liquidity AMM Decentralized Exchange Engine: Users can swap their tokens for a different one. This CLAMM-DEX can generate it's liquidity providers upto 400% more interest on the same capital when compared to traditional AMM-DEX.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published