@@ -21,6 +21,7 @@ import {
21
21
TransactionResponse ,
22
22
ZERO_ADDRESS ,
23
23
Profiler ,
24
+ formatGwei ,
24
25
} from "../utils" ;
25
26
import { RelayerClients } from "./RelayerClientHelper" ;
26
27
import { RelayerConfig } from "./RelayerConfig" ;
@@ -36,6 +37,7 @@ type BatchLPFees = { [depositKey: string]: RepaymentFee[] };
36
37
type RepaymentChainProfitability = {
37
38
gasLimit : BigNumber ;
38
39
gasCost : BigNumber ;
40
+ gasPrice : BigNumber ;
39
41
relayerFeePct : BigNumber ;
40
42
lpFeePct : BigNumber ;
41
43
} ;
@@ -673,7 +675,13 @@ export class Relayer {
673
675
l1Token ,
674
676
lpFees
675
677
) ;
676
- const { relayerFeePct, gasCost, gasLimit : _gasLimit , lpFeePct : realizedLpFeePct } = repaymentChainProfitability ;
678
+ const {
679
+ relayerFeePct,
680
+ gasCost,
681
+ gasLimit : _gasLimit ,
682
+ lpFeePct : realizedLpFeePct ,
683
+ gasPrice,
684
+ } = repaymentChainProfitability ;
677
685
if ( ! isDefined ( repaymentChainId ) ) {
678
686
profitClient . captureUnprofitableFill ( deposit , realizedLpFeePct , relayerFeePct , gasCost ) ;
679
687
} else {
@@ -702,7 +710,7 @@ export class Relayer {
702
710
tokenClient . decrementLocalBalance ( destinationChainId , outputToken , outputAmount ) ;
703
711
704
712
const gasLimit = isMessageEmpty ( resolveDepositMessage ( deposit ) ) ? undefined : _gasLimit ;
705
- this . fillRelay ( deposit , repaymentChainId , realizedLpFeePct , gasLimit ) ;
713
+ this . fillRelay ( deposit , repaymentChainId , realizedLpFeePct , gasPrice , gasLimit ) ;
706
714
}
707
715
} else if ( selfRelay ) {
708
716
// Prefer exiting early here to avoid fast filling any deposits we send. This approach assumes that we always
@@ -720,7 +728,14 @@ export class Relayer {
720
728
// relayer is both the depositor and the recipient, because a deposit on a cheap SpokePool chain could cause
721
729
// expensive fills on (for example) mainnet.
722
730
const { lpFeePct } = lpFees . find ( ( lpFee ) => lpFee . paymentChainId === destinationChainId ) ;
723
- this . fillRelay ( deposit , destinationChainId , lpFeePct ) ;
731
+ // For self-relays, gas price is not a concern because we are bypassing profitability requirements so
732
+ // use profit client's gasprice.
733
+ this . fillRelay (
734
+ deposit ,
735
+ destinationChainId ,
736
+ lpFeePct ,
737
+ this . clients . profitClient . getGasCostsForChain ( destinationChainId ) . gasPrice
738
+ ) ;
724
739
} else {
725
740
// TokenClient.getBalance returns that we don't have enough balance to submit the fast fill.
726
741
// At this point, capture the shortfall so that the inventory manager can rebalance the token inventory.
@@ -973,7 +988,13 @@ export class Relayer {
973
988
this . setFillStatus ( deposit , FillStatus . RequestedSlowFill ) ;
974
989
}
975
990
976
- fillRelay ( deposit : Deposit , repaymentChainId : number , realizedLpFeePct : BigNumber , gasLimit ?: BigNumber ) : void {
991
+ fillRelay (
992
+ deposit : Deposit ,
993
+ repaymentChainId : number ,
994
+ realizedLpFeePct : BigNumber ,
995
+ gasPrice : BigNumber ,
996
+ gasLimit ?: BigNumber
997
+ ) : void {
977
998
const { spokePoolClients } = this . clients ;
978
999
this . logger . debug ( {
979
1000
at : "Relayer::fillRelay" ,
@@ -1005,7 +1026,7 @@ export class Relayer {
1005
1026
] ;
1006
1027
1007
1028
const message = `Filled v3 deposit ${ messageModifier } 🚀` ;
1008
- const mrkdwn = this . constructRelayFilledMrkdwn ( deposit , repaymentChainId , realizedLpFeePct ) ;
1029
+ const mrkdwn = this . constructRelayFilledMrkdwn ( deposit , repaymentChainId , realizedLpFeePct , gasPrice ) ;
1009
1030
const contract = spokePoolClients [ deposit . destinationChainId ] . spokePool ;
1010
1031
const chainId = deposit . destinationChainId ;
1011
1032
const multiCallerClient = this . getMulticaller ( chainId ) ;
@@ -1056,6 +1077,7 @@ export class Relayer {
1056
1077
repaymentChainProfitability : {
1057
1078
gasLimit : bnZero ,
1058
1079
gasCost : bnUint256Max ,
1080
+ gasPrice : bnUint256Max ,
1059
1081
relayerFeePct : bnZero ,
1060
1082
lpFeePct : bnUint256Max ,
1061
1083
} ,
@@ -1086,17 +1108,25 @@ export class Relayer {
1086
1108
const getRepaymentChainProfitability = async (
1087
1109
preferredChainId : number ,
1088
1110
lpFeePct : BigNumber
1089
- ) : Promise < { profitable : boolean ; gasLimit : BigNumber ; gasCost : BigNumber ; relayerFeePct : BigNumber } > => {
1111
+ ) : Promise < {
1112
+ profitable : boolean ;
1113
+ gasLimit : BigNumber ;
1114
+ gasCost : BigNumber ;
1115
+ gasPrice : BigNumber ;
1116
+ relayerFeePct : BigNumber ;
1117
+ } > => {
1090
1118
const {
1091
1119
profitable,
1092
1120
nativeGasCost : gasLimit ,
1093
1121
tokenGasCost : gasCost ,
1122
+ gasPrice,
1094
1123
netRelayerFeePct : relayerFeePct , // net relayer fee is equal to total fee minus the lp fee.
1095
1124
} = await profitClient . isFillProfitable ( deposit , lpFeePct , hubPoolToken , preferredChainId ) ;
1096
1125
return {
1097
1126
profitable,
1098
1127
gasLimit,
1099
1128
gasCost,
1129
+ gasPrice,
1100
1130
relayerFeePct,
1101
1131
} ;
1102
1132
} ;
@@ -1116,10 +1146,11 @@ export class Relayer {
1116
1146
// @dev The following internal function should be the only one used to set `preferredChain` above.
1117
1147
const getProfitabilityDataForPreferredChainIndex = ( preferredChainIndex : number ) : RepaymentChainProfitability => {
1118
1148
const lpFeePct = lpFeePcts [ preferredChainIndex ] ;
1119
- const { gasLimit, gasCost, relayerFeePct } = repaymentChainProfitabilities [ preferredChainIndex ] ;
1149
+ const { gasLimit, gasCost, relayerFeePct, gasPrice } = repaymentChainProfitabilities [ preferredChainIndex ] ;
1120
1150
return {
1121
1151
gasLimit,
1122
1152
gasCost,
1153
+ gasPrice,
1123
1154
relayerFeePct,
1124
1155
lpFeePct,
1125
1156
} ;
@@ -1344,9 +1375,14 @@ export class Relayer {
1344
1375
}
1345
1376
}
1346
1377
1347
- private constructRelayFilledMrkdwn ( deposit : Deposit , repaymentChainId : number , realizedLpFeePct : BigNumber ) : string {
1378
+ private constructRelayFilledMrkdwn (
1379
+ deposit : Deposit ,
1380
+ repaymentChainId : number ,
1381
+ realizedLpFeePct : BigNumber ,
1382
+ gasPrice : BigNumber
1383
+ ) : string {
1348
1384
let mrkdwn =
1349
- this . constructBaseFillMarkdown ( deposit , realizedLpFeePct ) +
1385
+ this . constructBaseFillMarkdown ( deposit , realizedLpFeePct , gasPrice ) +
1350
1386
` Relayer repayment: ${ getNetworkName ( repaymentChainId ) } .` ;
1351
1387
1352
1388
if ( isDepositSpedUp ( deposit ) ) {
@@ -1361,7 +1397,7 @@ export class Relayer {
1361
1397
return mrkdwn ;
1362
1398
}
1363
1399
1364
- private constructBaseFillMarkdown ( deposit : Deposit , _realizedLpFeePct : BigNumber ) : string {
1400
+ private constructBaseFillMarkdown ( deposit : Deposit , _realizedLpFeePct : BigNumber , _gasPriceGwei : BigNumber ) : string {
1365
1401
const { symbol, decimals } = this . clients . hubPoolClient . getTokenInfoForDeposit ( deposit ) ;
1366
1402
const srcChain = getNetworkName ( deposit . originChainId ) ;
1367
1403
const dstChain = getNetworkName ( deposit . destinationChainId ) ;
@@ -1380,7 +1416,9 @@ export class Relayer {
1380
1416
const _outputAmount = createFormatFunction ( 2 , 4 , false , outputTokenDecimals ) ( deposit . outputAmount . toString ( ) ) ;
1381
1417
msg +=
1382
1418
` and output ${ _outputAmount } ${ outputTokenSymbol } , with depositor ${ depositor } .` +
1383
- ` Realized LP fee: ${ realizedLpFeePct } %, total fee: ${ totalFeePct } %.` ;
1419
+ ` Realized LP fee: ${ realizedLpFeePct } %, total fee: ${ totalFeePct } %. Gas price used in profit calc: ${ formatGwei (
1420
+ _gasPriceGwei . toString ( )
1421
+ ) } Gwei.`;
1384
1422
1385
1423
return msg ;
1386
1424
}
0 commit comments