diff --git a/src/clients/ProfitClient.ts b/src/clients/ProfitClient.ts index a7a92f272f..a07fb8bf70 100644 --- a/src/clients/ProfitClient.ts +++ b/src/clients/ProfitClient.ts @@ -17,6 +17,7 @@ import { BigNumber, formatFeePct, getCurrentTime, + getNetworkName, isDefined, min, winston, @@ -390,16 +391,26 @@ export class ProfitClient { } // Return USD amount of fill amount for deposited token, should always return in wei as the units. - getFillAmountInUsd(deposit: Deposit, fillAmount = deposit.outputAmount): BigNumber { - const l1TokenInfo = this.hubPoolClient.getTokenInfoForDeposit(deposit); - if (!l1TokenInfo) { - const { inputToken } = deposit; - throw new Error( - `ProfitClient#getFillAmountInUsd missing l1TokenInfo for deposit with origin token: ${inputToken}` - ); + getFillAmountInUsd( + deposit: Pick + ): BigNumber | undefined { + const { destinationChainId, outputToken, outputAmount } = deposit; + let l1Token: L1Token; + + try { + l1Token = this.hubPoolClient.getL1TokenInfoForL2Token(outputToken, destinationChainId); + } catch { + this.logger.info({ + at: "ProfitClient#getFillAmountInUsd", + message: `Cannot resolve output token ${outputToken} on ${getNetworkName(destinationChainId)}.`, + }); + return undefined; } - const tokenPriceInUsd = this.getPriceOfToken(l1TokenInfo.symbol); - return fillAmount.mul(tokenPriceInUsd).div(bn10.pow(l1TokenInfo.decimals)); + + const tokenPriceInUsd = this.getPriceOfToken(l1Token.symbol); + + // The USD amount of a fill must be normalised to 18 decimals, so factor out the token's own decimal promotion. + return outputAmount.mul(tokenPriceInUsd).div(bn10.pow(l1Token.decimals)); } async getFillProfitability( diff --git a/src/relayer/Relayer.ts b/src/relayer/Relayer.ts index 3abd00f517..00eac7fab8 100644 --- a/src/relayer/Relayer.ts +++ b/src/relayer/Relayer.ts @@ -102,6 +102,17 @@ export class Relayer { // Ensure that the individual deposit meets the minimum deposit confirmation requirements for its value. const fillAmountUsd = profitClient.getFillAmountInUsd(deposit); + if (!isDefined(fillAmountUsd)) { + this.logger.debug({ + at: "Relayer::evaluateFill", + message: `Skipping ${srcChain} deposit due to uncertain fill amount.`, + destinationChainId, + outputToken: deposit.outputToken, + transactionHash: deposit.transactionHash, + }); + return false; + } + const { minConfirmations } = minDepositConfirmations[originChainId].find(({ usdThreshold }) => usdThreshold.gte(fillAmountUsd) );