Skip to content

Commit

Permalink
improve(relayFeeCalculator): Skip redundant decimals lookup
Browse files Browse the repository at this point in the history
getFeePercent() already obtains the destination token decimals via a
call to getTokenInformationFromAddress(), so there's no need for a
separate lookup via getTokenDecimals().
  • Loading branch information
pxrl committed Jan 9, 2024
1 parent 79190cc commit bfdaec8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/relayFeeCalculator/relayFeeCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ export class RelayFeeCalculator {
relayerAddress = DEFAULT_SIMULATED_RELAYER_ADDRESS,
_tokenPrice?: number
): Promise<BigNumber> {
const tokenInformation = getTokenInformationFromAddress(deposit.originToken);
if (!isDefined(tokenInformation)) {
const token = getTokenInformationFromAddress(deposit.originToken);
if (!isDefined(token)) {
throw new Error(`Could not find token information for ${deposit.originToken}`);
}

Expand All @@ -247,7 +247,7 @@ export class RelayFeeCalculator {
});
throw error;
});
const getTokenPrice = this.queries.getTokenPrice(tokenInformation.symbol).catch((error) => {
const getTokenPrice = this.queries.getTokenPrice(token.symbol).catch((error) => {
this.logger.error({
at: "sdk-v2/gasFeePercent",
message: "Error while fetching token price",
Expand All @@ -261,8 +261,7 @@ export class RelayFeeCalculator {
getGasCosts,
_tokenPrice !== undefined ? _tokenPrice : getTokenPrice,
]);
const decimals = this.queries.getTokenDecimals(tokenInformation.symbol);
const gasFeesInToken = nativeToToken(tokenGasCost, tokenPrice, decimals, this.nativeTokenDecimals);
const gasFeesInToken = nativeToToken(tokenGasCost, tokenPrice, token.decimals, this.nativeTokenDecimals);
return percent(gasFeesInToken, amountToRelay.toString());
}

Expand Down

0 comments on commit bfdaec8

Please sign in to comment.