Skip to content

Commit

Permalink
Populate revert context with correct data
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 15, 2024
1 parent d7f050f commit 54caf43
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/localnet/src/createToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const createToken = async ({

foreignCoins.push({
zrc20_contract_address: zrc20.target,
asset: isGasToken ? "" : (erc20 as any).target,
asset: isGasToken ? ethers.ZeroAddress : (erc20 as any).target,
foreign_chain_id: "1",
decimals: 18,
name: `ZetaChain ZRC-20 ${symbol}`,
Expand Down
2 changes: 2 additions & 0 deletions packages/localnet/src/handleOnEVMCalled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export const handleOnEVMCalled = async ({
return await handleOnRevertEVM({
revertOptions,
err,
amount: 0,
asset: ethers.ZeroAddress,
tss,
provider,
protocolContracts,
Expand Down
11 changes: 6 additions & 5 deletions packages/localnet/src/handleOnEVMDeposited.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ export const handleOnEVMDeposited = async ({
exitOnError: boolean;
}) => {
log("EVM", "Gateway: 'Deposited' event emitted");
const receiver = args[1];
const amount = args[2];
const asset = args[3];
const message = args[4];
try {
const receiver = args[1];
const amount = args[2];
const asset = args[3];
const message = args[4];

let foreignCoin;
if (asset === ethers.ZeroAddress) {
foreignCoin = foreignCoins.find((coin) => coin.coin_type === "Gas");
Expand Down Expand Up @@ -87,6 +86,8 @@ export const handleOnEVMDeposited = async ({
const revertOptions = args[5];
return await handleOnRevertEVM({
revertOptions,
asset,
amount,
err,
tss,
provider,
Expand Down
8 changes: 6 additions & 2 deletions packages/localnet/src/handleOnRevertEVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ethers, NonceManager } from "ethers";

export const handleOnRevertEVM = async ({
revertOptions,
asset,
amount,
err,
provider,
tss,
Expand All @@ -12,6 +14,8 @@ export const handleOnRevertEVM = async ({
}: {
revertOptions: any;
err: any;
asset: any;
amount: any;
provider: any;
tss: any;
protocolContracts: any;
Expand All @@ -21,8 +25,8 @@ export const handleOnRevertEVM = async ({
const revertAddress = revertOptions[0];
const revertMessage = revertOptions[3];
const revertContext = {
asset: ethers.ZeroAddress,
amount: 0,
asset,
amount, // this should deduct the gas costs
revertMessage,
};
if (callOnRevert) {
Expand Down
8 changes: 6 additions & 2 deletions packages/localnet/src/handleOnRevertZEVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { logErr } from "./log";
export const handleOnRevertZEVM = async ({
revertOptions,
err,
asset,
amount,
provider,
tss,
log,
Expand All @@ -14,6 +16,8 @@ export const handleOnRevertZEVM = async ({
}: {
revertOptions: any;
err: any;
asset: any;
amount: any;
provider: any;
fungibleModuleSigner: any;
tss: NonceManager;
Expand All @@ -26,8 +30,8 @@ export const handleOnRevertZEVM = async ({
const revertAddress = revertOptions[0];
const revertMessage = revertOptions[3];
const revertContext = {
asset: ethers.ZeroAddress,
amount: 0,
asset,
amount,
revertMessage,
};

Expand Down
2 changes: 2 additions & 0 deletions packages/localnet/src/handleOnZEVMCalled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const handleOnZEVMCalled = async ({
return await handleOnRevertZEVM({
revertOptions,
err,
amount: 0,
asset: ethers.ZeroAddress,
provider,
fungibleModuleSigner,
tss,
Expand Down
27 changes: 14 additions & 13 deletions packages/localnet/src/handleOnZEVMWithdrawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ export const handleOnZEVMWithdrawn = async ({
exitOnError: boolean;
}) => {
log("ZetaChain", "Gateway: 'Withdrawn' event emitted");
const getERC20ByZRC20 = (zrc20: string) => {
const foreignCoin = foreignCoins.find(
(coin: any) => coin.zrc20_contract_address === zrc20
);
if (!foreignCoin) {
logErr("EVM", `Foreign coin not found for ZRC20 address: ${zrc20}`);
return;
}
return foreignCoin.asset;
};
const zrc20 = args[3];
const amount = args[4];
try {
const receiver = args[2];
const zrc20 = args[3];
const amount = args[4];
const message = args[7];
(tss as NonceManager).reset();
const zrc20Contract = new ethers.Contract(zrc20, ZRC20.abi, deployer);
const coinType = await zrc20Contract.COIN_TYPE();
const isGasToken = coinType === 1n;
const isERC20orZETA = coinType === 2n;
const getERC20ByZRC20 = (zrc20: string) => {
const foreignCoin = foreignCoins.find(
(coin: any) => coin.zrc20_contract_address === zrc20
);
if (!foreignCoin) {
logErr("EVM", `Foreign coin not found for ZRC20 address: ${zrc20}`);
return;
}
return foreignCoin.asset;
};
if (message !== "0x") {
// The message is not empty, so this is a withdrawAndCall operation
log("EVM", `Calling ${receiver} with message ${message}`);
Expand All @@ -54,7 +54,6 @@ export const handleOnZEVMWithdrawn = async ({
.execute(receiver, message, { value: amount, ...deployOpts });
await executeTx.wait();
} else {
console.log("!!!");
const erc20 = getERC20ByZRC20(zrc20);
const executeTx = await protocolContracts.custody
.connect(tss)
Expand Down Expand Up @@ -102,6 +101,8 @@ export const handleOnZEVMWithdrawn = async ({
err,
provider,
tss,
asset: getERC20ByZRC20(zrc20),
amount,
log,
fungibleModuleSigner,
protocolContracts,
Expand Down

0 comments on commit 54caf43

Please sign in to comment.