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.
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.
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
- User interacts with smart contract on Ethereum network as usual
- Contract processes method and emits an event
- LCSwap listens to events and execute orders on L2
Deposit assets (Ethereum / Token)
Orders (Swap, Liquidity pool management)
Withdraw process
Legend
This project contains some configuration files to help get started 🛠️
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 contracts repo:
git clone https://github.com/MikaelLazarev/layer-cake-swap-client/
- Run hardhat blockchain:
npx hardhat node
. Do not close this tab, hardhat node should work in background - Deploy smartcontract:
yarn deploy-local
- Run frontend:
yarn start
- Clone this repo:
git clone [email protected]:MikaelLazarev/layer-cake-swap-node.git
- Go to
src
folder in your frontend folder and openenv.local
file. - 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
- Copy
REACT_APP_VAULT_ADDRESS
andREACT_APP_TOKEN_ADDRESS
, we will need them to configure substrate node. - Go back to Substrate node directory
- Copy
.env_example
to.env
file and set web3 provider. For dev pruposes it would be hardhat address:
WEB3PROVIDER=http://localhost:8545
- Go to
polkaswap
pallet directory (it's former name of layer-cake-swap project):cd pallets/polkaswap/src
- Open
lib.rs
file and insert vault contract address & token address there without0x
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";
- Return to root directory and run substrate node in dev mode:
make dev
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.
Thanks Anthony Beaumont for inspiration and Dan Forbes for tech support & naming idea.
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.