()
| 26 | // \ --keys bot1 |
| 27 | |
| 28 | export async function run(): Promise<void> { |
| 29 | if (!Object.keys(args).includes("chainId")) { |
| 30 | throw new Error("Define `chainId` as the chain you want to connect on"); |
| 31 | } |
| 32 | if (!Object.keys(args).includes("amount")) { |
| 33 | throw new Error("Define `amount` as how much you want to unwrap"); |
| 34 | } |
| 35 | const baseSigner = await retrieveSignerFromCLIArgs(); |
| 36 | const signerAddr = await baseSigner.getAddress(); |
| 37 | const chainId = Number(args.chainId); |
| 38 | const connectedSigner = baseSigner.connect(await getProvider(chainId)); |
| 39 | assert(TOKEN_SYMBOLS_MAP.WETH.addresses[chainId], "chainId does not have a defined WETH address"); |
| 40 | const token = TOKEN_SYMBOLS_MAP.WETH.addresses[chainId]; |
| 41 | const weth = new ethers.Contract(token, WETH9.abi, connectedSigner); |
| 42 | const decimals = 18; |
| 43 | const amountFromWei = ethers.utils.formatUnits(args.amount, decimals); |
| 44 | |
| 45 | const wrapping = args.wrap; |
| 46 | if (wrapping) { |
| 47 | console.log("Wrapping WETH 🎁"); |
| 48 | const { provider } = connectedSigner; |
| 49 | assert(isDefined(provider), "Connected signer must have a provider"); |
| 50 | const currentBalance = ethers.utils.formatUnits(await provider.getBalance(signerAddr), decimals); |
| 51 | console.log(`Current ETH balance for account ${signerAddr} on ${getNetworkName(chainId)}: ${currentBalance}`); |
| 52 | if ((await provider.getBalance(signerAddr)).lt(toBN(args.amount))) { |
| 53 | console.log(`ETH balance < ${amountFromWei}, exiting`); |
| 54 | return; |
| 55 | } |
| 56 | console.log(`Wrap ${amountFromWei} ETH`); |
| 57 | // Check the user is ok with the info provided. else abort. |
| 58 | if (!(await askYesNoQuestion("\nConfirm that you want to execute this transaction?"))) { |
| 59 | return; |
| 60 | } |
| 61 | console.log("sending..."); |
| 62 | const tx = await weth.deposit({ value: args.amount }); |
| 63 | const receipt = await tx.wait(); |
| 64 | console.log("Transaction hash:", receipt.transactionHash); |
| 65 | } else { |
| 66 | console.log("Unwrapping WETH 🎊"); |
| 67 | const currentBalance = ethers.utils.formatUnits(await weth.balanceOf(signerAddr), decimals); |
| 68 | console.log(`Current WETH balance for account ${signerAddr} on Mainnet: ${currentBalance}`); |
| 69 | if ((await weth.balanceOf(signerAddr)).lt(toBN(args.amount))) { |
| 70 | console.log(`WETH balance < ${amountFromWei}, exiting`); |
| 71 | return; |
| 72 | } |
| 73 | console.log(`Unwrap ${amountFromWei} WETH`); |
| 74 | // Check the user is ok with the info provided. else abort. |
| 75 | if (!(await askYesNoQuestion("\nConfirm that you want to execute this transaction?"))) { |
| 76 | return; |
| 77 | } |
| 78 | console.log("sending..."); |
| 79 | const tx = await weth.withdraw(args.amount); |
| 80 | const receipt = await tx.wait(); |
| 81 | console.log("Transaction hash:", receipt.transactionHash); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if (require.main === module) { |
no test coverage detected