Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 14, 2024
1 parent 3f3e5ad commit 23fb660
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
"@zetachain/protocol-contracts": "10.0.0-rc10",
"@zetachain/toolkit": "13.0.0-rc5"
}
}
}
7 changes: 6 additions & 1 deletion examples/swap/tasks/swapFromEVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
30 changes: 15 additions & 15 deletions examples/swap/tasks/swapFromZetaChain.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
Expand All @@ -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
);

0 comments on commit 23fb660

Please sign in to comment.