From 23fb660a7fe75b7d316d7e352a59718f48e0fad9 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Mon, 14 Oct 2024 14:25:14 +0300 Subject: [PATCH] wip --- examples/swap/package.json | 2 +- examples/swap/tasks/swapFromEVM.ts | 7 +++++- examples/swap/tasks/swapFromZetaChain.ts | 30 ++++++++++++------------ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/examples/swap/package.json b/examples/swap/package.json index da960e00..c1a6e365 100644 --- a/examples/swap/package.json +++ b/examples/swap/package.json @@ -59,4 +59,4 @@ "@zetachain/protocol-contracts": "10.0.0-rc10", "@zetachain/toolkit": "13.0.0-rc5" } -} +} \ No newline at end of file diff --git a/examples/swap/tasks/swapFromEVM.ts b/examples/swap/tasks/swapFromEVM.ts index e32836c8..6aae193b 100644 --- a/examples/swap/tasks/swapFromEVM.ts +++ b/examples/swap/tasks/swapFromEVM.ts @@ -74,4 +74,9 @@ task("swap-from-evm", "Swap tokens from EVM", evmDepositAndCall) .addOptionalParam("erc20", "ERC-20 token address") .addParam("target", "ZRC-20 address of the token to swap for") .addParam("recipient", "Recipient address") - .addFlag("withdraw", "Withdraw to destination or keep token on ZetaChain"); + .addOptionalParam( + "withdraw", + "Withdraw to destination or keep token on ZetaChain", + true, + types.boolean + ); diff --git a/examples/swap/tasks/swapFromZetaChain.ts b/examples/swap/tasks/swapFromZetaChain.ts index d21f3906..a98fc0ea 100644 --- a/examples/swap/tasks/swapFromZetaChain.ts +++ b/examples/swap/tasks/swapFromZetaChain.ts @@ -1,4 +1,4 @@ -import { task } from "hardhat/config"; +import { task, types } from "hardhat/config"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import { parseEther } from "@ethersproject/units"; import { ethers } from "ethers"; @@ -10,24 +10,19 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => { const factory = await hre.ethers.getContractFactory("SwapToAnyToken"); const contract = factory.attach(args.contract); - const amount = parseEther(args.amount); - const inputToken = args.inputToken; - const targetToken = args.targetToken; - const recipient = ethers.utils.arrayify(args.recipient); - const withdraw = JSON.parse(args.withdraw); + const zrc20 = new ethers.Contract(args.zrc20, ZRC20.abi, signer); - const zrc20 = new ethers.Contract(args.inputToken, ZRC20.abi, signer); - // const inputTokenContract = zrc20.attach(args.inputToken); + const amount = parseEther(args.amount); const approval = await zrc20.approve(args.contract, amount); await approval.wait(); const tx = await contract.swap( - inputToken, + args.zrc20, amount, - targetToken, - recipient, - withdraw + args.target, + ethers.utils.arrayify(args.recipient), + JSON.parse(args.withdraw) ); await tx.wait(); @@ -38,7 +33,12 @@ task("swap-from-zetachain", "Swap tokens from ZetaChain", main) .addFlag("json", "Output JSON") .addParam("contract", "Contract address") .addParam("amount", "Token amount to send") - .addParam("inputToken", "Input token address") - .addParam("targetToken", "Target token address") + .addParam("zrc20", "Input token address") + .addParam("target", "Target token address") .addParam("recipient", "Recipient address") - .addParam("withdraw", "Withdraw flag (true/false)"); + .addOptionalParam( + "withdraw", + "Withdraw tokens to destination chain", + true, + types.boolean + );