Skip to content

Commit

Permalink
Small fix to handle withdraw (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichJamo authored Sep 23, 2024
1 parent 401d803 commit 8e62457
Showing 1 changed file with 32 additions and 33 deletions.
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

0 comments on commit 8e62457

Please sign in to comment.