@@ -71,13 +71,16 @@ export type FillProfit = {
7171 outputAmountUsd : BigNumber ;
7272 grossRelayerFeePct : BigNumber ; // Max of relayerFeePct and newRelayerFeePct from Deposit.
7373 grossRelayerFeeUsd : BigNumber ; // USD value of the relay fee paid by the user.
74+ auxiliaryNativeTokenCost : BigNumber ; // Amount of native tokens forwarded to the user in the units of native token.
75+ auxiliaryNativeTokenCostUsd : BigNumber ; // Same as above, but in USD
7476 nativeGasCost : BigNumber ; // Cost of completing the fill in the units of gas.
7577 tokenGasCost : BigNumber ; // Cost of completing the fill in the relevant gas token.
7678 gasPrice : BigNumber ; // Gas price in wei.
7779 gasPadding : BigNumber ; // Positive padding applied to nativeGasCost and tokenGasCost before profitability.
7880 gasMultiplier : BigNumber ; // Gas multiplier applied to fill cost estimates before profitability.
7981 gasTokenPriceUsd : BigNumber ; // Price paid per unit of gas the gas token in USD.
80- gasCostUsd : BigNumber ; // Estimated cost of completing the fill in USD.
82+ gasCostUsd : BigNumber ; // Estimated gas cost of completing the fill in USD.
83+ nativeTokenFillCostUsd : BigNumber ; // Estimated native token cost of completing the fill in USD: gas + auxiliary
8184 netRelayerFeePct : BigNumber ; // Relayer fee after gas costs as a portion of relayerCapitalUsd.
8285 netRelayerFeeUsd : BigNumber ; // Relayer fee in USD after paying for gas costs.
8386 totalFeePct : BigNumber ; // Total fee as a portion of the fill amount.
@@ -168,11 +171,11 @@ export class ProfitClient {
168171 return isMessageEmpty ( resolveDepositMessage ( deposit ) ) ? this . gasMultiplier : this . gasMessageMultiplier ;
169172 }
170173
171- resolveGasToken ( chainId : number ) : L1Token {
174+ resolveNativeToken ( chainId : number ) : L1Token {
172175 const symbol = getNativeTokenSymbol ( chainId ) ;
173176 const token = TOKEN_SYMBOLS_MAP [ symbol ] ;
174177 if ( ! isDefined ( symbol ) || ! isDefined ( token ) ) {
175- throw new Error ( `Unable to resolve gas token for chain ID ${ chainId } ` ) ;
178+ throw new Error ( `Unable to resolve native token for chain ID ${ chainId } ` ) ;
176179 }
177180
178181 const { decimals, addresses } = token ;
@@ -181,6 +184,11 @@ export class ProfitClient {
181184 return { symbol, address, decimals } ;
182185 }
183186
187+ resolveGasToken ( chainId : number ) : L1Token {
188+ // Note for future: gas token and native token may not always be the same
189+ return this . resolveNativeToken ( chainId ) ;
190+ }
191+
184192 getAllPrices ( ) : { [ address : string ] : BigNumber } {
185193 return this . tokenPrices ;
186194 }
@@ -265,6 +273,10 @@ export class ProfitClient {
265273 }
266274 }
267275
276+ getAuxiliaryNativeTokenCost ( deposit : Deposit ) : BigNumber {
277+ return this . relayerFeeQueries [ deposit . destinationChainId ] . getAuxiliaryNativeTokenCost ( deposit ) ;
278+ }
279+
268280 async getTotalGasCost ( deposit : Deposit ) : Promise < TransactionCostEstimate > {
269281 const { destinationChainId : chainId } = deposit ;
270282
@@ -289,7 +301,19 @@ export class ProfitClient {
289301 // Estimate the gas cost of filling this relay.
290302 async estimateFillCost (
291303 deposit : Deposit
292- ) : Promise < Pick < FillProfit , "nativeGasCost" | "tokenGasCost" | "gasTokenPriceUsd" | "gasCostUsd" | "gasPrice" > > {
304+ ) : Promise <
305+ Pick <
306+ FillProfit ,
307+ | "nativeGasCost"
308+ | "tokenGasCost"
309+ | "gasTokenPriceUsd"
310+ | "gasCostUsd"
311+ | "gasPrice"
312+ | "auxiliaryNativeTokenCost"
313+ | "auxiliaryNativeTokenCostUsd"
314+ | "nativeTokenFillCostUsd"
315+ >
316+ > {
293317 const { destinationChainId : chainId } = deposit ;
294318
295319 const gasToken = this . resolveGasToken ( chainId ) ;
@@ -321,12 +345,23 @@ export class ProfitClient {
321345
322346 const gasCostUsd = tokenGasCost . mul ( gasTokenPriceUsd ) . div ( bn10 . pow ( gasToken . decimals ) ) ;
323347
348+ const auxiliaryNativeTokenCost = this . getAuxiliaryNativeTokenCost ( deposit ) ;
349+ const nativeToken = this . resolveNativeToken ( chainId ) ;
350+ const nativeTokenPriceUsd = this . getPriceOfToken ( nativeToken . symbol ) ;
351+ const auxiliaryNativeTokenCostUsd = auxiliaryNativeTokenCost
352+ . mul ( nativeTokenPriceUsd )
353+ . div ( bn10 . pow ( nativeToken . decimals ) ) ;
354+
355+ const nativeTokenFillCostUsd = gasCostUsd . add ( auxiliaryNativeTokenCostUsd ) ;
324356 return {
325357 nativeGasCost,
326358 tokenGasCost,
327359 gasPrice,
328360 gasTokenPriceUsd,
329361 gasCostUsd,
362+ auxiliaryNativeTokenCost,
363+ auxiliaryNativeTokenCostUsd,
364+ nativeTokenFillCostUsd,
330365 } ;
331366 }
332367
@@ -409,14 +444,23 @@ export class ProfitClient {
409444 ? grossRelayerFeeUsd . mul ( fixedPoint ) . div ( inputAmountUsd )
410445 : bnZero ;
411446
412- // Estimate the gas cost of filling this relay.
413- const { nativeGasCost, tokenGasCost, gasTokenPriceUsd, gasCostUsd, gasPrice } = await this . estimateFillCost (
414- deposit
415- ) ;
447+ const {
448+ // Estimated gas cost of filling this relay
449+ nativeGasCost,
450+ tokenGasCost,
451+ gasTokenPriceUsd,
452+ gasCostUsd,
453+ gasPrice,
454+ // Estimated auxiliary native token cost
455+ auxiliaryNativeTokenCost,
456+ auxiliaryNativeTokenCostUsd,
457+ // Estimated total native token cost in USD
458+ nativeTokenFillCostUsd,
459+ } = await this . estimateFillCost ( deposit ) ;
416460
417461 // Determine profitability. netRelayerFeePct effectively represents the capital cost to the relayer;
418462 // i.e. how much it pays out to the recipient vs. the net fee that it receives for doing so.
419- const netRelayerFeeUsd = grossRelayerFeeUsd . sub ( gasCostUsd ) ;
463+ const netRelayerFeeUsd = grossRelayerFeeUsd . sub ( nativeTokenFillCostUsd ) ;
420464 const netRelayerFeePct = outputAmountUsd . gt ( bnZero )
421465 ? netRelayerFeeUsd . mul ( fixedPoint ) . div ( outputAmountUsd )
422466 : bnZero ;
@@ -433,13 +477,16 @@ export class ProfitClient {
433477 outputAmountUsd,
434478 grossRelayerFeePct,
435479 grossRelayerFeeUsd,
480+ auxiliaryNativeTokenCost,
481+ auxiliaryNativeTokenCostUsd,
436482 nativeGasCost,
437483 tokenGasCost,
438484 gasPrice,
439485 gasPadding : this . gasPadding ,
440486 gasMultiplier : this . resolveGasMultiplier ( deposit ) ,
441487 gasTokenPriceUsd,
442488 gasCostUsd,
489+ nativeTokenFillCostUsd,
443490 netRelayerFeePct,
444491 netRelayerFeeUsd,
445492 profitable,
@@ -493,6 +540,8 @@ export class ProfitClient {
493540 totalFeePct : `${ formatFeePct ( fill . totalFeePct ) } %` ,
494541 lpFeePct : `${ formatFeePct ( lpFeePct ) } %` ,
495542 grossRelayerFeePct : `${ formatFeePct ( fill . grossRelayerFeePct ) } %` ,
543+ auxiliaryNativeTokenCost : fill . auxiliaryNativeTokenCost ,
544+ auxiliaryNativeTokenCostUsd : formatEther ( fill . auxiliaryNativeTokenCostUsd ) ,
496545 nativeGasCost : fill . nativeGasCost ,
497546 tokenGasCost : formatEther ( fill . tokenGasCost ) ,
498547 gasPrice : formatGwei ( fill . gasPrice . toString ( ) ) ,
@@ -501,6 +550,7 @@ export class ProfitClient {
501550 gasTokenPriceUsd : formatEther ( fill . gasTokenPriceUsd ) ,
502551 grossRelayerFeeUsd : formatEther ( fill . grossRelayerFeeUsd ) ,
503552 gasCostUsd : formatEther ( fill . gasCostUsd ) ,
553+ nativeTokenFillCostUsd : formatEther ( fill . nativeTokenFillCostUsd ) ,
504554 netRelayerFeeUsd : formatEther ( fill . netRelayerFeeUsd ) ,
505555 netRelayerFeePct : `${ formatFeePct ( fill . netRelayerFeePct ) } %` ,
506556 minRelayerFeePct : `${ formatFeePct ( minRelayerFeePct ) } %` ,
0 commit comments