This repository showcases the migration of Uniswap V2 to the =nil; We have adapted Uniswap’s core contracts — Factory, Pair, and Router — to work seamlessly with the unique capabilities of =nil; By using this example, developers can learn how to migrate dApps from Ethereum compatible networks to the =nil; and take advantage of its features, such as:
- Multi-Currency Support: Learn how =nil; supports multiple currencies natively and how they replace the ERC20 standard
- Async/Sync Calls: Discover how to effectively utilize async and sync messaging between shards, making the protocol both scalable and performant
- Load Distribution: Understand how to distribute operations across multiple shards, enhancing parallel processing and scalability
This repository also aims to spark discussion on the potential of running DeFi protocols on sharded architectures, demonstrating their feasibility and advantages
Before working with this repository, ensure that you have properly set up your environment:
-
.env Configuration: Make sure to create a
.env
file in the root directory. All required environment variables are listed in the.env.example
file, which you can use as a reference. Link to.env.example
-
Getting an RPC Endpoint: To request an RPC endpoint:
- Join our Telegram chat: https://t.me/nilfoundation
- Request access, and our DevRel team will assist you.
-
Obtaining a Private Key and Wallet:
- Download the
nil
CLI: https://github.com/NilFoundation/nil_cli - Follow the setup instructions in our documentation: nil CLI Docs
- Download the
To help you get started quickly, we provide two demo tasks that showcase the full lifecycle from deployment to execution. These tasks cover deploying and initializing all necessary contracts, as well as performing operations like minting, swapping, and burning
-
Using Factory and Pair Contracts Only This demo handles deploying the Factory and Pair contracts and executing a complete flow of operations View the demo task
Important:
- Calculations are processed on the user's side.
- Both the currency address and its ID are stored in the pair contract.
-
Using Factory, Pair, and Router Contracts This demo includes an additional layer by utilizing the Router contract along with Factory and Pair View the demo-router task
Important:
- The
UniswapV2Factory
is used for creating new pairs.UniswapV2Router01
calls already deployed pair contracts. UniswapV2Router01
can be deployed on a different shard.- Vulnerability: no checks are performed during adding/removing liquidity and swaps. Rates and output amounts are entirely calculated on the user side.
- The
-
Using Router with Sync Calls (1 shard) This demo task shows how to deploy the
UniswapV2Router01
contract and use it as a proxy for adding/removing liquidity and swaps via sync calls. It allows checks on amounts before pair calls and maintains currency rates. View the demo-router taskImportant:
UniswapV2Router01
should be deployed on the same shard as the pair contract.- It maintains the currency exchange rate when adding/removing liquidity.
- It supports limit checks for currency amounts.
- Compile the Project:
npx hardhat compile
- Run the Demo Tasks:
- For the core demo (Factory and Pair):
npx hardhat demo
- For the demo with Router (Factory, Pair, and Router):
npx hardhat demo-router
- For the demo with Router (Sync calls):
npx hardhat demo-router-sync
- For the core demo (Factory and Pair):
If you prefer to run everything manually, we provide Ignition modules for each contract: Ignition Modules
Additionally, all crucial contract methods have corresponding tasks: Tasks
Each subdirectory contains a README explaining the details of the tasks
We welcome contributions from the community to make this project even better! If you have suggestions, improvements, or find any bugs, please feel free to submit a pull request or open an issue.
Check out our open issues and improvements in the GitHub Issues section. If you're new to the project, look for issues labeled as good first issue
— they're a great place to start.
Your input and contributions are greatly appreciated!
This project is licensed under the GPL-3.0 License. See the LICENSE file for more details. Portions of this project are derived from Uniswap V2 and are also subject to the GPL-3.0 License.