From 4214a73cd5b504aeb2bf2a1326f4139ea14c25ef Mon Sep 17 00:00:00 2001 From: Layne Haber Date: Fri, 15 Mar 2024 17:23:08 -0600 Subject: [PATCH 1/7] feat: add total cost defaults to getHardcodedGasLimits --- packages/utils/src/constants/gas.ts | 20 ++++++++++++++++++++ packages/utils/src/peripherals/chainData.ts | 3 +++ 2 files changed, 23 insertions(+) diff --git a/packages/utils/src/constants/gas.ts b/packages/utils/src/constants/gas.ts index d8e7465368..3dd57f2953 100644 --- a/packages/utils/src/constants/gas.ts +++ b/packages/utils/src/constants/gas.ts @@ -4,12 +4,26 @@ export const NATIVE_TOKEN = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; export const DEFAULT_GAS_ESTIMATES = { execute: "400000", executeL1: "20000", + // average gas of reconcile tx to L2 / batch size (n=10) + // - 350,000 for 1 tx batch + // - 1,200,000 for 10 tx batch + proveAndProcess: "120000", + // average gas of reconcile tx L1 costs on op + // - 43,000 1 tx batch + // - 220,000 10 tx batch + proveAndProcessL1: "20000", + // monthly costs in weth / monthly transfer count = weth cost per transfer + // weth. chaindata should be updated when switching between op and slow mode + messaging: "4500", gasPriceFactor: "1000000000000000000", }; export type GasEstimates = { execute: string; executeL1: string; + proveAndProcess: string; + proveAndProcessL1: string; + messaging: string; gasPriceFactor: string; }; @@ -23,11 +37,17 @@ export const getHardcodedGasLimits = async ( const execute = chainInfo.gasEstimates?.execute ?? DEFAULT_GAS_ESTIMATES.execute; const executeL1 = chainInfo.gasEstimates?.executeL1 ?? DEFAULT_GAS_ESTIMATES.executeL1; + const proveAndProcess = chainInfo.gasEstimates?.proveAndProcess ?? DEFAULT_GAS_ESTIMATES.proveAndProcess; + const proveAndProcessL1 = chainInfo.gasEstimates?.proveAndProcessL1 ?? DEFAULT_GAS_ESTIMATES.proveAndProcessL1; + const messaging = chainInfo.gasEstimates?.messaging ?? DEFAULT_GAS_ESTIMATES.messaging; const gasPriceFactor = chainInfo.gasEstimates?.gasPriceFactor ?? DEFAULT_GAS_ESTIMATES.gasPriceFactor; const res = { execute, executeL1, gasPriceFactor, + proveAndProcess, + proveAndProcessL1, + messaging, } as GasEstimates; return res; }; diff --git a/packages/utils/src/peripherals/chainData.ts b/packages/utils/src/peripherals/chainData.ts index 907214fc47..adc61e7033 100644 --- a/packages/utils/src/peripherals/chainData.ts +++ b/packages/utils/src/peripherals/chainData.ts @@ -67,6 +67,9 @@ export type ChainData = { execute: string; xcallL1: string; executeL1: string; + proveAndProcess: string; + proveAndProcessL1: string; + messaging: string; gasPriceFactor?: string; }; }; From 7a0c15ce0ca85e664ad99a5ce914117fae7228c8 Mon Sep 17 00:00:00 2001 From: Layne Haber Date: Fri, 15 Mar 2024 17:26:44 -0600 Subject: [PATCH 2/7] feat: add all fees to calculation --- packages/utils/src/peripherals/relayer.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/utils/src/peripherals/relayer.ts b/packages/utils/src/peripherals/relayer.ts index cf3506bced..1f8beb4b21 100644 --- a/packages/utils/src/peripherals/relayer.ts +++ b/packages/utils/src/peripherals/relayer.ts @@ -57,26 +57,32 @@ export const calculateRelayerFee = async ( const { execute: executeGasAmount, executeL1: executeL1GasAmount, + proveAndProcess: proveAndProcessGasAmount, + proveAndProcessL1: proveAndProcessL1GasAmount, + messaging: messagingGasAmount, gasPriceFactor, } = await getHardcodedGasLimits(destinationDomain, chainData); if (logger) { logger.debug("Hardcoded gasLimits", requestContext, methodContext, { execute: executeGasAmount, executeL1: executeL1GasAmount, + proveAndProcess: proveAndProcessGasAmount, + proveAndProcessL1: proveAndProcessL1GasAmount, + messaging: messagingGasAmount, gasPriceFactor, }); } - const totalGasAmount = callDataGasAmount - ? Number(executeGasAmount) + Number(callDataGasAmount) - : Number(executeGasAmount); + const baseGasFees = Number(executeGasAmount) + Number(proveAndProcessGasAmount) + Number(messagingGasAmount); + + const totalGasAmount = callDataGasAmount ? Number(baseGasFees) + Number(callDataGasAmount) : Number(executeGasAmount); const [estimatedRelayerFee, originTokenPrice, destinationTokenPrice] = await Promise.all([ getGelatoEstimatedFee( destinationChainId, constants.AddressZero, Number(totalGasAmount), isHighPriority, - destinationChainId == 10 ? Number(executeL1GasAmount) : undefined, + destinationChainId == 10 ? Number(executeL1GasAmount) + Number(proveAndProcessL1GasAmount) : undefined, ), originNativeTokenPrice ? Promise.resolve(originNativeTokenPrice) From 8924811b498b8258f8907741c796904faff404f3 Mon Sep 17 00:00:00 2001 From: Layne Haber Date: Fri, 15 Mar 2024 17:29:24 -0600 Subject: [PATCH 3/7] chore: fresh install --- packages/adapters/database/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapters/database/package.json b/packages/adapters/database/package.json index ae51dd1a4f..bd23dc4439 100644 --- a/packages/adapters/database/package.json +++ b/packages/adapters/database/package.json @@ -43,4 +43,4 @@ }, "gitHead": "937a7cde93e6ac1e151c6374f48adf83d3fa4ec6", "stableVersion": "2.0.0" -} \ No newline at end of file +} From 57f1a1be3bbf0e0fa10cfe47fffb6f20157dd73f Mon Sep 17 00:00:00 2001 From: Layne Haber Date: Fri, 15 Mar 2024 17:38:08 -0600 Subject: [PATCH 4/7] feat: feature flag messaging --- .../agents/sequencer/src/lib/helpers/relayerfee.ts | 2 ++ packages/utils/src/peripherals/relayer.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/agents/sequencer/src/lib/helpers/relayerfee.ts b/packages/agents/sequencer/src/lib/helpers/relayerfee.ts index 4514da2ce9..9a7842a4fa 100644 --- a/packages/agents/sequencer/src/lib/helpers/relayerfee.ts +++ b/packages/agents/sequencer/src/lib/helpers/relayerfee.ts @@ -55,6 +55,8 @@ export const canSubmitToRelayer = async (transfer: XTransfer): Promise<{ canSubm }, chainData, logger, + requestContext, + true, ); let relayerFeePaidUsd = constants.Zero; diff --git a/packages/utils/src/peripherals/relayer.ts b/packages/utils/src/peripherals/relayer.ts index 1f8beb4b21..1c4214fc4b 100644 --- a/packages/utils/src/peripherals/relayer.ts +++ b/packages/utils/src/peripherals/relayer.ts @@ -27,6 +27,7 @@ export const calculateRelayerFee = async ( chainData: Map, logger?: Logger, _requestContext?: RequestContext, + onlyExecute = false, ): Promise => { const { requestContext, methodContext } = createLoggingContext(calculateRelayerFee.name, _requestContext); @@ -73,7 +74,15 @@ export const calculateRelayerFee = async ( }); } - const baseGasFees = Number(executeGasAmount) + Number(proveAndProcessGasAmount) + Number(messagingGasAmount); + const baseGasFees = + Number(executeGasAmount) + + Number(onlyExecute ? 0 : proveAndProcessGasAmount) + + Number(onlyExecute ? 0 : messagingGasAmount); + + const l1GasLimit = + destinationChainId == 10 + ? Number(executeL1GasAmount) + Number(onlyExecute ? 0 : proveAndProcessL1GasAmount) + : undefined; const totalGasAmount = callDataGasAmount ? Number(baseGasFees) + Number(callDataGasAmount) : Number(executeGasAmount); const [estimatedRelayerFee, originTokenPrice, destinationTokenPrice] = await Promise.all([ @@ -82,7 +91,7 @@ export const calculateRelayerFee = async ( constants.AddressZero, Number(totalGasAmount), isHighPriority, - destinationChainId == 10 ? Number(executeL1GasAmount) + Number(proveAndProcessL1GasAmount) : undefined, + l1GasLimit, ), originNativeTokenPrice ? Promise.resolve(originNativeTokenPrice) From 0c51827aad95b3312e3b29ccf75cc10d396683f3 Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Mon, 18 Mar 2024 11:00:03 +0800 Subject: [PATCH 5/7] chore: just for safe --- packages/utils/src/peripherals/relayer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/peripherals/relayer.ts b/packages/utils/src/peripherals/relayer.ts index 1c4214fc4b..0122e5a5ef 100644 --- a/packages/utils/src/peripherals/relayer.ts +++ b/packages/utils/src/peripherals/relayer.ts @@ -27,7 +27,7 @@ export const calculateRelayerFee = async ( chainData: Map, logger?: Logger, _requestContext?: RequestContext, - onlyExecute = false, + onlyExecute = true, ): Promise => { const { requestContext, methodContext } = createLoggingContext(calculateRelayerFee.name, _requestContext); From a28701c61ce94d89852ee24f87d27166513d1a77 Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Mon, 18 Mar 2024 11:27:10 +0800 Subject: [PATCH 6/7] feat: make onlyExecute configurable --- ops/mainnet/prod/core/config.tf | 1 + packages/agents/sequencer/src/config.ts | 5 +++++ packages/agents/sequencer/src/lib/entities/config.ts | 1 + packages/agents/sequencer/src/lib/helpers/relayerfee.ts | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ops/mainnet/prod/core/config.tf b/ops/mainnet/prod/core/config.tf index be7a0be800..984a31cf1e 100644 --- a/ops/mainnet/prod/core/config.tf +++ b/ops/mainnet/prod/core/config.tf @@ -155,6 +155,7 @@ locals { } ] relayerFeeTolerance = 60 + checkOnlyExecuteFee = true environment = var.stage database = { url = local.default_db_url diff --git a/packages/agents/sequencer/src/config.ts b/packages/agents/sequencer/src/config.ts index 06394c32ef..1541ad3722 100644 --- a/packages/agents/sequencer/src/config.ts +++ b/packages/agents/sequencer/src/config.ts @@ -119,6 +119,11 @@ export const getEnvConfig = ( : configFile.relayerFeeTolerance ? configFile.relayerFeeTolerance : DEFAULT_RELAYER_FEE_TOLERANCE, + checkOnlyExecuteFee: configJson.checkOnlyExecuteFee + ? configJson.checkOnlyExecuteFee + : configFile.checkOnlyExecuteFee + ? configFile.checkOnlyExecuteFee + : true, }; const defaultConfirmations = chainData && (chainData.get("1")?.confirmations ?? 1 + 3); diff --git a/packages/agents/sequencer/src/lib/entities/config.ts b/packages/agents/sequencer/src/lib/entities/config.ts index 720671afab..158be3b637 100644 --- a/packages/agents/sequencer/src/lib/entities/config.ts +++ b/packages/agents/sequencer/src/lib/entities/config.ts @@ -132,6 +132,7 @@ export const SequencerConfigSchema = Type.Object({ ), database: TDatabaseConfig, relayerFeeTolerance: Type.Number({ minimum: 0, maximum: 100 }), + checkOnlyExecuteFee: Type.Boolean(), }); export type SequencerConfig = Static; diff --git a/packages/agents/sequencer/src/lib/helpers/relayerfee.ts b/packages/agents/sequencer/src/lib/helpers/relayerfee.ts index 9a7842a4fa..cf99fa20da 100644 --- a/packages/agents/sequencer/src/lib/helpers/relayerfee.ts +++ b/packages/agents/sequencer/src/lib/helpers/relayerfee.ts @@ -56,7 +56,7 @@ export const canSubmitToRelayer = async (transfer: XTransfer): Promise<{ canSubm chainData, logger, requestContext, - true, + config.checkOnlyExecuteFee, ); let relayerFeePaidUsd = constants.Zero; From a7ffc4530d03a5e4b7534e54f38cb7c63170efca Mon Sep 17 00:00:00 2001 From: wanglonghong Date: Mon, 18 Mar 2024 16:36:03 +0800 Subject: [PATCH 7/7] fix: missing param --- packages/integration/test/constants/testnet/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/integration/test/constants/testnet/index.ts b/packages/integration/test/constants/testnet/index.ts index 85b06baade..4952b7a0cc 100644 --- a/packages/integration/test/constants/testnet/index.ts +++ b/packages/integration/test/constants/testnet/index.ts @@ -330,6 +330,7 @@ export const SEQUENCER_CONFIG: Promise = (async (): Promise