From 8af4b05e062533fc490cbfb46d41bfee6ec94e64 Mon Sep 17 00:00:00 2001 From: Dong-Ha Kim Date: Fri, 6 Sep 2024 14:32:45 +0700 Subject: [PATCH] fixup --- api/_utils.ts | 8 +++++--- api/limits.ts | 18 ++++++------------ api/suggested-fees.ts | 13 +++++++++---- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/api/_utils.ts b/api/_utils.ts index 19411d5b1..31bee72e6 100644 --- a/api/_utils.ts +++ b/api/_utils.ts @@ -613,10 +613,10 @@ export const getRelayerFeeDetails = async ( originChainId: number; destinationChainId: number; recipientAddress: string; + message?: string; + relayerAddress?: string; }, tokenPrice?: number, - message?: string, - relayerAddress?: string, gasPrice?: sdk.utils.BigNumberish, gasUnits?: sdk.utils.BigNumberish ): Promise => { @@ -627,6 +627,8 @@ export const getRelayerFeeDetails = async ( originChainId, destinationChainId, recipientAddress, + message, + relayerAddress, } = deposit; const relayFeeCalculator = getRelayerFeeCalculator(destinationChainId, { relayerAddress, @@ -646,7 +648,7 @@ export const getRelayerFeeDetails = async ( sdk.utils.isMessageEmpty(message), relayerAddress, tokenPrice, - gasPrice, // FIXME: We need properly cache the gas price before this can be used reliably + gasPrice, gasUnits ); } catch (err: unknown) { diff --git a/api/limits.ts b/api/limits.ts index 7c8fe4b5f..677416e1d 100644 --- a/api/limits.ts +++ b/api/limits.ts @@ -112,6 +112,10 @@ const handler = async ( }, ]; + const relayerAddress = getDefaultRelayerAddress( + destinationChainId, + l1Token.symbol + ); const depositArgs = { amount: ethers.BigNumber.from("10").pow(l1Token.decimals), inputToken: inputToken.address, @@ -119,11 +123,8 @@ const handler = async ( recipientAddress: DEFAULT_SIMULATED_RECIPIENT_ADDRESS, originChainId: computedOriginChainId, destinationChainId, + relayerAddress, }; - const relayerAddress = getDefaultRelayerAddress( - destinationChainId, - l1Token.symbol - ); const [tokenPriceNative, _tokenPriceUsd, latestBlock, gasPrice, gasUnits] = await Promise.all([ @@ -147,14 +148,7 @@ const handler = async ( transferRestrictedBalances, fullRelayerMainnetBalances, ] = await Promise.all([ - getRelayerFeeDetails( - depositArgs, - tokenPriceNative, - undefined, - getDefaultRelayerAddress(destinationChainId, l1Token.symbol), - gasPrice, - gasUnits - ), + getRelayerFeeDetails(depositArgs, tokenPriceNative, gasPrice, gasUnits), callViaMulticall3(provider, multiCalls, { blockTag: latestBlock.number, }), diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts index 7adcfe701..f31f5b8cc 100644 --- a/api/suggested-fees.ts +++ b/api/suggested-fees.ts @@ -213,6 +213,8 @@ const handler = async ( recipientAddress: recipient, originChainId: computedOriginChainId, destinationChainId, + message, + relayerAddress: relayer, }; const [ @@ -221,6 +223,7 @@ const handler = async ( tokenPriceUsd, limits, gasPrice, + gasUnits, ] = await Promise.all([ callViaMulticall3(provider, multiCalls, { blockTag: quoteBlockNumber }), getCachedTokenPrice(l1Token.address, baseCurrency), @@ -232,7 +235,10 @@ const handler = async ( destinationChainId ), getCachedGasPrice(destinationChainId), - getCachedFillGasUsage(depositArgs, { relayerAddress: relayer }), + // Only use cached fill gas usage if message is empty + sdk.utils.isMessageEmpty(message) + ? undefined + : getCachedFillGasUsage(depositArgs, { relayerAddress: relayer }), ]); const quoteTimestamp = parseInt(_quoteTimestamp.toString()); @@ -266,9 +272,8 @@ const handler = async ( const relayerFeeDetails = await getRelayerFeeDetails( depositArgs, tokenPrice, - message, - relayer, - gasPrice + gasPrice, + gasUnits ); const skipAmountLimitEnabled = skipAmountLimit === "true";