|
2 | 2 |
|
3 | 3 | import { task } from "hardhat/config";
|
4 | 4 | import { ethers } from "hardhat";
|
| 5 | +import { getFirstSigner } from "../../helpers/utilities/signer"; |
| 6 | +import { getMintableERC20 } from "../../helpers/contract-getters"; |
5 | 7 |
|
6 |
| -// Usage: npx hardhat init-uniswap-mock-router --network <network> --router <router-address> |
| 8 | +// Usage: npx hardhat init-uniswap-mock-router --network <network> --router <router-address> --type <uniswap|paraswap> |
7 | 9 |
|
8 |
| -task("init-uniswap-mock-router", "Initialize the Uniswap mock router for testing swaps") |
9 |
| - .addParam("router", "The address of the Uniswap mock router contract") |
10 |
| - .setAction(async ({ router }, hre) => { |
11 |
| - if (!ethers.utils.isAddress(router)) { |
12 |
| - throw new Error("Invalid router address provided."); |
| 10 | +task("init-uniswap-mock-router", "Initialize the Uniswap or Paraswap Mock Router for testing swaps") |
| 11 | + .addParam("router", "Address of the Router") |
| 12 | + .addParam("type", "Type of the Router (paraswap, uniswap)") |
| 13 | + .setAction(async ({ router, type }, hre) => { |
| 14 | + const signer = await getFirstSigner(); |
| 15 | + const signerAddress = await signer.getAddress(); |
| 16 | + |
| 17 | + // Use ethers.Contract as a generic fallback for the router |
| 18 | + let contract: any; |
| 19 | + if (type === "paraswap" || type === "uniswap") { |
| 20 | + contract = new hre.ethers.Contract(router, [], signer); // ABI can be added if needed |
| 21 | + } else { |
| 22 | + throw new Error("Unknown router type. Use 'uniswap' or 'paraswap'."); |
13 | 23 | }
|
14 |
| - const [signer] = await hre.ethers.getSigners(); |
15 |
| - const mockRouter = await ethers.getContractAt("UniswapV2Router02Mock", router, signer); |
16 |
| - // Example: set up initial liquidity or configuration if needed |
17 |
| - // await mockRouter.addLiquidity(...) |
18 |
| - console.log(`Uniswap mock router at ${router} is ready for use.`); |
| 24 | + |
| 25 | + // List of tokens to approve/transfer to the router (update as needed) |
| 26 | + const tokenAddresses = [ |
| 27 | + // USDC |
| 28 | + "0x1c9b6337b001704d54B13FBA5C06Fe5D43061a8E", |
| 29 | + // USDT |
| 30 | + "0x2516196DA3849e85a6887B78edcb48C1eeF2eb89", |
| 31 | + // WBTC |
| 32 | + "0x4647044B0B264C771510FdB2764587B1fc7B599B", |
| 33 | + // WETH |
| 34 | + "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14", |
| 35 | + // ZBU |
| 36 | + "0x6098Bc6CA2fDFDa186847878726AFBad1d01f13D", |
| 37 | + ]; |
| 38 | + |
| 39 | + for (let address of tokenAddresses) { |
| 40 | + const token = await getMintableERC20(address); |
| 41 | + const balance = await token.balanceOf(signerAddress); |
| 42 | + console.log(`Token ${address} has ${balance} tokens for ${signerAddress}`); |
| 43 | + console.log(`Approving ${balance} tokens for router ${router} for token ${address}`); |
| 44 | + await token.approve(router, balance); |
| 45 | + console.log(`Transferring ${balance} tokens to the router for token ${address}`); |
| 46 | + await token.transfer(router, balance); |
| 47 | + } |
| 48 | + |
| 49 | + console.log(`All tokens approved and transferred to the router at ${router} for type ${type}.`); |
19 | 50 | });
|
0 commit comments