Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fix to handle withdraw #39

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions packages/localnet/src/handleOnZEVMWithdrawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,39 @@ export const handleOnZEVMWithdrawn = async ({
logs.forEach((data) => {
log("EVM", `Event from contract: ${JSON.stringify(data)}`);
});
} else {
const zrc20Contract = new ethers.Contract(zrc20, ZRC20.abi, deployer);
const coinType = await zrc20Contract.COIN_TYPE();
if (coinType === 1n) {
const tx = await tss.sendTransaction({
to: receiver,
value: amount,
...deployOpts,
});
await tx.wait();
log(
"EVM",
`Transferred ${ethers.formatEther(
amount
)} native gas tokens from TSS to ${receiver}`
);
} else if (coinType === 2n) {
const foreignCoin = foreignCoins.find(
(coin: any) => coin.zrc20_contract_address === zrc20
);
if (!foreignCoin) {
logErr("EVM", `Foreign coin not found for ZRC20 address: ${zrc20}`);
return;
}
const erc20 = foreignCoin.asset;
const tx = await protocolContracts.custody
.connect(tss)
.withdraw(receiver, erc20, amount, deployOpts);
await tx.wait();
log(
"EVM",
`Transferred ${amount} ERC-20 tokens from Custody to ${receiver}`
);
}
const zrc20Contract = new ethers.Contract(zrc20, ZRC20.abi, deployer);
const coinType = await zrc20Contract.COIN_TYPE();
if (coinType === 1n) {
const tx = await tss.sendTransaction({
to: receiver,
value: amount,
...deployOpts,
});
await tx.wait();
log(
"EVM",
`Transferred ${ethers.formatEther(
amount
)} native gas tokens from TSS to ${receiver}`
);
} else if (coinType === 2n) {
const foreignCoin = foreignCoins.find(
(coin: any) => coin.zrc20_contract_address === zrc20
);
if (!foreignCoin) {
logErr("EVM", `Foreign coin not found for ZRC20 address: ${zrc20}`);
return;
}
const erc20 = foreignCoin.asset;
const tx = await protocolContracts.custody
.connect(tss)
.withdraw(receiver, erc20, amount, deployOpts);
await tx.wait();
log(
"EVM",
`Transferred ${amount} ERC-20 tokens from Custody to ${receiver}`
);
}
} catch (e) {
const revertOptions = args[9];
Expand Down
Loading