Uniswap
Uniswap V3 is deployed on the Lens Testnet, allowing developers to create and interact with liquidity pools. Deployed contract addresses can be found here.
Creating a Liquidity Pool
A ready-to-use script for creating Uniswap V3 pools is available here.
Steps to Run the Script
Clone the repository
git clone https://github.com/defispartan/echofi-deploy.gitcd echofi-deploy
Install dependencies
yarn install
Configure the script
Open src/scripts/createUniswapPools.ts
Set the required pool and deployer details at the top of the script.
Deploy the pool
yarn hardhat run src/scripts/createUniswapPools.ts --no-compile
Interacting with pools
Once a pool is deployed, you can interact with it using a library like ethers.js or viem. Common interactions include:
Querying Pool Information
import {ethers} from "ethers";
const provider = new ethers.JsonRpcProvider("<LENS_TESTNET_RPC>");const poolAddress = "<DEPLOYED_POOL_ADDRESS>";const poolContract = new ethers.Contract( poolAddress, UNISWAP_V3_POOL_ABI, provider);
async function getPoolState() { const slot0 = await poolContract.slot0(); console.log("Current price sqrtX96:", slot0.sqrtPriceX96.toString());}
getPoolState();
Swapping Tokens
const swapRouterAddress = "<UNISWAP_V3_SWAP_ROUTER>";const swapRouterContract = new ethers.Contract( swapRouterAddress, SWAP_ROUTER_ABI, signer);
async function swapTokens() { const tx = await swapRouterContract.exactInputSingle({ tokenIn: "<TOKEN_IN_ADDRESS>", tokenOut: "<TOKEN_OUT_ADDRESS>", fee: 3000, recipient: signer.address, deadline: Math.floor(Date.now() / 1000) + 60 * 10, amountIn: ethers.parseUnits("1", 18), amountOutMinimum: 0, sqrtPriceLimitX96: 0, }); await tx.wait(); console.log("Swap executed successfully");}
swapTokens();
For additional resources on integrating Uniswap V3 contracts, refer to the Uniswap V3 docs.