Skip to content

🍰 DEX protocol that consumes 7 times less gas in comparison with UniSwap, based on L2 network 🚀

License

Notifications You must be signed in to change notification settings

0xmikko/layer-cake-swap-node

Repository files navigation

title_white

LayerCakeSwap

LayerCakeSwap is a DEX protocol which consumes 7 times less gas1 in comparison with UniSwap, based on L2 network. It solves following problems:

  • High gas rates make DeFi expensive for users 
~$12-18 USD per swap (@ 1,000 USD/Eth)
  • DeFi users prefer and trust Ethereum and aren’t willing to migrate to side chains solutions (like Binance Smart Chain, POA, etc.) for gas efficiency

Users interact with LayerCakeSwap smart contract on Ethereum using familiar interface, no additional setup required. Even more, LayerCakeSwap contract API is accessible for other smart contract on Ethereum.

Smart contract emits events to manage operations on L2 network based on Polkadot (Substrate). Gas efficiency comes from executing calculations & data storage on L2 network.

advanages

This version implements business logic for trading a pair ETH - ERC20 Token. Ethereum contract & frontend is located at https://github.com/MikaelLazarev/layer-cake-swap-client/

Demo video: https://youtu.be/4ittQwgjaEQ
Live demo: https://lcswap.dltxperts.com

This project was developed for Encode Hackathon'2021.

Gas consumption comparison

Operation UniSwap LayerCakeSwap
Deposit Eth - 22,656
Deposit token - 48,628
Swap token to Eth2 165,969 22,656
AddToLiquidity pool in research 22,656
Withdraw from liquidity pool in research 22,656
Withdraw ETH - no data yet
Withdraw token - no data yet

1 - for swap operation. UniSwap gas consumption was measured for ETH/DAI pair.
2 - gas for UniSwap was measured for ETH/DAI Swap

How it works

how_it_works

  1. User interacts with smart contract on Ethereum network as usual
  2. Contract processes method and emits an event
  3. LCSwap listens to events and execute orders on L2

Supported operations:

Deposit assets (Ethereum / Token)

deposit_process

Orders (Swap, Liquidity pool management)

order_process

Withdraw process

withdraw_process

Legend

legend

How to install (dev mode)

This project contains some configuration files to help get started 🛠️

Rust Setup

Setup instructions for working with the Rust programming language can be found at the Substrate Developer Hub. Follow those steps to install rustup and configure the Rust toolchain to default to the latest stable version.

Clone contract repo & deploy ethereum smartcontract

  1. Clone contracts repo: git clone https://github.com/MikaelLazarev/layer-cake-swap-client/
  2. Run hardhat blockchain: npx hardhat node. Do not close this tab, hardhat node should work in background
  3. Deploy smartcontract: yarn deploy-local
  4. Run frontend: yarn start

Clone Substrate node repo & config it

  1. Clone this repo: git clone git@github.com:MikaelLazarev/layer-cake-swap-node.git
  2. Go to src folder in your frontend folder and open env.local file.
  3. It would contain something like that:
REACT_APP_BACKEND_ADDR=http://localhost:8000
REACT_APP_VAULT_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
REACT_APP_TOKEN_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
REACT_APP_CHAIN_ID=1337
  1. Copy REACT_APP_VAULT_ADDRESS and REACT_APP_TOKEN_ADDRESS, we will need them to configure substrate node.
  2. Go back to Substrate node directory
  3. Copy .env_example to .env file and set web3 provider. For dev pruposes it would be hardhat address:
WEB3PROVIDER=http://localhost:8545
  1. Go to polkaswap pallet directory (it's former name of layer-cake-swap project): cd pallets/polkaswap/src
  2. Open lib.rs file and insert vault contract address & token address there without 0x prefix:
/// Vault contract address
pub const VAULT_CONTRACT_ADDRESS: &'static str = "e7f1725E7734CE288F8367e1Bb143E90bb3F0512";

/// Token contract agaist Eth erc20 contract address
/// DAI on our case
pub const TOKEN_CONTRACT_ADDRESS: &'static str = "5FbDB2315678afecb367f032d93F642f64180aa3";
  1. Return to root directory and run substrate node in dev mode: make dev

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Credits

Thanks Anthony Beaumont for inspiration and Dan Forbes for tech support & naming idea.

Disclaimer

This application is provided "as is" and "with all faults." Me as developer makes no representations or warranties of any kind concerning the safety, suitability, lack of viruses, inaccuracies, typographical errors, or other harmful components of this software. There are inherent dangers in the use of any software, and you are solely responsible for determining whether this software product is compatible with your equipment and other software installed on your equipment. You are also solely responsible for the protection of your equipment and backup of your data, and THE PROVIDER will not be liable for any damages you may suffer in connection with using, modifying, or distributing this software product.

About

🍰 DEX protocol that consumes 7 times less gas in comparison with UniSwap, based on L2 network 🚀

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published