Add and remove liquidity to the USDC - DAI pool.
- Swap your USDC for DAI
- Provide liquidity to the USDC-DAI pool to receive Liquidity Provider Tokens (LP Tokens)
- Redeem your LP Tokens to receive USD and DAI from the liquidity pool
- Forked network for testing -> Arbitrum.
- RPC Server Address -> https://arb1.arbitrum.io/rpc.
- Uniswap V2 Swap Router Address (Arbitrum)-> 0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24.
- Uniswap Factory Address (Arbitrum) -> 0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9.
- Framework CLI -> Foundry.
- Forge version -> 1.1.0-stable.
- Solidity compiler version -> 0.8.24.
- Clone the GitHub repository.
- Open Visual Studio Code (you should already have Foundry installed).
- Select "File" > "Open Folder", select the cloned repository folder.
- In the project navigation bar, open the "swapApp.t.sol" file located in the "test" folder.
- On line 19 ("Address with USDC in Arbitrum Mainnet") enter the address of your wallet with USDC in the Arbitrum network. Note: Verify that you have at least 6 USDC on the Arbitrum network.
- In the toolbar above, select "Terminal" > "New Terminal".
- Select the "Git bash" terminal (previously installed).
- Run the command
forge test -vvvv --fork-url https://arb1.arbitrum.io/rpc --match-testfollowed by the name of a test function to test it and verify the smart contract functions are working correctly. For example, runforge test -vvvv --fork-url https://arb1.arbitrum.io/rpc --match-test testHasBeenDeployedCorrectlyto test thetestHasBeenDeployedCorrectlyfunction. - Run
forge test -vvvv --fork-url https://arb1.arbitrum.io/rpc --match-test testSwapTokensCorrectlyto swap your 6 USDC for DAI. This is just a test on the forked Arbitrum network, so your USDC will remain in your wallet after this. - Run
forge test -vvvv --fork-url https://arb1.arbitrum.io/rpc --match-test testCanAddLiquidityCorrectlyto swap half of the USDC tokens. In this case, the contract takes 6 of your USDC, so a 3 USDC swap would be made. As a reward for providing liquidity to the USDC-DAI pool, you will be awarded Liquidity Provider Tokens. - Run
forge test -vvvv --fork-url https://arb1.arbitrum.io/rpc --match-test testCanRemoveLiquidityCorrectlyto redeem your Liquidity Provider Tokens for USDC and DAI from the liquidity pool. - Run
forge coverage --fork-url https://arb1.arbitrum.io/rpcto generate a code coverage report, which allows you to verify which parts of the "swapApp.sol" script code (in the "src" folder) are executed by the tests. This helps identify areas outside the coverage that could be exposed to errors/vulnerabilities.
swapTokens()-> Swap USDC for DAI.addLiquidity()-> Contribute USDC and DAI to the USDC-DAI liquidity pool to receive Liquidity Provider Tokens.removeLiquidity()-> Redeem your Liquidity Provider Tokens to receive USDC and DAI from the USDC-DAI liquidity pool.
testHasBeenDeployedCorrectly()-> Verify that the swap app has been correctly initialized with the correct router address (uniswapV2SwapRouterAddress).testSwapTokensCorrectly()-> Verify that the 6 USDC to DAI swap was successful. Note: The amount of DAI you receive will vary depending on the liquidity in the USDC -> DAI liquidity pool.testCanAddLiquidityCorrectly()-> Verify that half of your USDC is swapped for DAI, that the USDC and DAI are contributed to the liquidity pool, and that you successfully obtain your Liquidity Provider Tokens.testCanRemoveLiquidityCorrectly()-> Verify that your Liquidity Provider Tokens are redeemed and that you are successfully receiving USDC and DAI from the liquidity pool.
CODE IS LAW!
