Skip to content

Commit

Permalink
Merge pull request #200 from zkLinkProtocol/fix/decode_failed_deposit
Browse files Browse the repository at this point in the history
fix decode exception for failed tx
  • Loading branch information
haymond-ZK authored Apr 26, 2024
2 parents faf2c46 + 914a22c commit 3b126db
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions store/zksync/failedDepositHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,48 @@ export const useFailedDepositHistoryStore = defineStore("failedDepositHistory",
const mappedTransfers = response.items;

const l2Provider = await providerStore.requestProvider();
const tokens = mappedTransfers.map((tx) => {
const l2BridgeAddress = tx.to;
const l2Bridge = IL2BridgeFactory.connect(l2BridgeAddress, l2Provider);
let calldata;
try {
calldata = l2Bridge.interface.decodeFunctionData("finalizeDepositToMerge", tx.data); // we know only these two cases for failed deposit
} catch (e) {
calldata = l2Bridge.interface.decodeFunctionData("finalizeDeposit", tx.data);
}

console.log("calldata: ", calldata);
const amount = calldata._amount as BigNumberish;
const token = calldata._l1Token as Address;
return {
amount,
token,
networkKey: tx.networkKey,
};
});
const tokens = mappedTransfers
.map((tx) => {
const l2BridgeAddress = tx.to;
const l2Bridge = IL2BridgeFactory.connect(l2BridgeAddress, l2Provider);
let calldata;
try {
calldata = l2Bridge.interface.decodeFunctionData("finalizeDepositToMerge", tx.data); // we know only these two cases for failed deposit
} catch (e) {
//do nothing
}
if (!calldata) {
try {
calldata = l2Bridge.interface.decodeFunctionData("finalizeDeposit", tx.data);
} catch (e) {
//do nothing
}
}
if (!calldata) {
return;
}
console.log("calldata: ", calldata);
const amount = calldata._amount as BigNumberish;
const token = calldata._l1Token as Address;
return {
hash: tx.hash,
amount,
token,
networkKey: tx.networkKey,
};
})
.filter((item) => !!item);
const tokenDatas = await Promise.all(tokens.map((item) => formatErc20(item.token, item.amount, item.networkKey)));
mappedTransfers.forEach((transfer, index) => {
transfer.token = tokenDatas[index];
});
transfers.value = [...mappedTransfers];
const result = [];
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
const transfer = mappedTransfers.find((item) => item.hash === token!.hash);
if (transfer) {
transfer.token = tokenDatas[i];
result.push(transfer);
}
}
transfers.value = [...result];
},
{ cache: 30000 }
);
Expand Down

0 comments on commit 3b126db

Please sign in to comment.