Skip to content

Commit

Permalink
feat: add custom bridge address for fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
tx-nikola committed Apr 5, 2024
1 parent 47471d0 commit b7dabc8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions composables/zksync/useFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type FeeEstimationParams = {
type: "transfer" | "withdrawal";
from: string;
to: string;
tokenAddress: string;
token: Token;
};

export default (
Expand Down Expand Up @@ -51,15 +51,18 @@ export default (
if (!params) throw new Error("Params are not available");

const provider = getProvider();
const tokenBalance = balances.value.find((e) => e.address === params!.tokenAddress)?.amount || "1";
const tokenBalance = balances.value.find((e) => e.address === params!.token.address)?.amount || "1";
const [price, limit] = await Promise.all([
retry(() => provider.getGasPrice()),
retry(() => {
const isCustomBridge = isExternalBridgeToken(params!.token);
const bridgeAddress = isCustomBridge ? EXTERNAL_BRIDGES[params!.token.address] : "";
return provider[params!.type === "transfer" ? "estimateGasTransfer" : "estimateGasWithdraw"]({
from: params!.from,
to: params!.to,
token: params!.tokenAddress === ETH_TOKEN.address ? ETH_TOKEN.l1Address! : params!.tokenAddress,
token: params!.token.address === ETH_TOKEN.address ? ETH_TOKEN.l1Address! : params!.token.address,
amount: tokenBalance,
...(isCustomBridge ? { bridgeAddress } : {}),
});
}),
]);
Expand Down
2 changes: 1 addition & 1 deletion views/transactions/Transfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ const estimate = async () => {
type: props.type,
from: transaction.value.from.address,
to: transaction.value.to.address,
tokenAddress: selectedToken.value.address,
token: selectedToken.value,
});
};
watch(
Expand Down

0 comments on commit b7dabc8

Please sign in to comment.