diff --git a/aggregator/.env.example b/aggregator/.env.example index d0476405..b2d1f336 100644 --- a/aggregator/.env.example +++ b/aggregator/.env.example @@ -42,3 +42,5 @@ PREVIOUS_BASE_FEE_PERCENT_INCREASE=2 BUNDLE_CHECKING_CONCURRENCY=8 IS_OPTIMISM=false +OPTIMISM_GAS_PRICE_ORACLE_ADDRESS=0x420000000000000000000000000000000000000F +OPTIMISM_L1_BASE_FEE_PERCENT_INCREASE=2 diff --git a/aggregator/README.md b/aggregator/README.md index d679252c..8c629061 100644 --- a/aggregator/README.md +++ b/aggregator/README.md @@ -89,32 +89,35 @@ commands. #### Environment Variables -| Name | Example Value | Description | -| ---------------------------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| RPC_URL | https://localhost:8545 | The RPC endpoint for an EVM node that the BLS Wallet contracts are deployed on | -| RPC_POLLING_INTERVAL | 4000 | How long to wait between retries, when needed (used by ethers when waiting for blocks) | -| USE_TEST_NET | false | Whether to set all transaction's `gasPrice` to 0. Workaround for some networks | -| ORIGIN | http://localhost:3000 | The origin for the aggregator client. Used only in manual tests | -| PORT | 3000 | The port to bind the aggregator to | -| NETWORK_CONFIG_PATH | ../contracts/networks/local.json | Path to the network config file, which contains information on deployed BLS Wallet contracts | -| PRIVATE_KEY_AGG | 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 | Private key for the EOA account used to submit bundles on chain. Transactions are paid by the account linked to PRIVATE_KEY_AGG. By default, bundles must pay for themselves by sending funds to tx.origin or the aggregator’s onchain address | -| PRIVATE_KEY_ADMIN | 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d | Private key for the admin EOA account. Used only in tests | -| TEST_BLS_WALLETS_SECRET | test-bls-wallets-secret | Secret used to seed BLS Wallet private keys during tests | -| DB_PATH | aggregator.sqlite | File path of the sqlite db | -| BUNDLE_QUERY_LIMIT | 100 | Maximum number of bundles returned from sqlite | -| MAX_GAS_PER_BUNDLE | 2000000 | Limits the amount of user operations which can be bundled together by using this value as the approximate limit on the amount of gas in an aggregate bundle | -| MAX_AGGREGATION_DELAY_MILLIS | 5000 | Maximum amount of time in milliseconds aggregator will wait before submitting bundles on chain. A higher number will allow more time for bundles to fill, but may result in longer periods before submission. A lower number allows more frequent L2 submissions, but may result in smaller bundles | -| MAX_UNCONFIRMED_AGGREGATIONS | 3 | Maximum unconfirmed bundle aggregations that will be submitted on chain | -| LOG_QUERIES | false | Whether to print sqlite queries in event log. When running tests, `TEST_LOGGING` must also be enabled | -| TEST_LOGGING | false | Whether to print aggregator server events to stdout during tests. Useful for debugging & logging | -| REQUIRE_FEES | true | Whether to require that user bundles pay the aggregator a sufficient fee | -| BREAKEVEN_OPERATION_COUNT | 4.5 | The aggregator must pay an overhead to submit a bundle regardless of how many operations it contains. This parameter determines how much each operation must contribute to this overhead | -| ALLOW_LOSSES | true | Even if each user bundle pays the required fee, the aggregate bundle may not be profitable if it is too small. Setting this to true makes the aggregator submit these bundles anyway | -| FEE_TYPE | ether OR token:0xabcd...1234 | The fee type the aggregator will accept. Either `ether` for ETH/chains native currency or `token:0xabcd...1234` (token contract address) for an ERC20 token | -| AUTO_CREATE_INTERNAL_BLS_WALLET | false | An internal BLS wallet is used to calculate bundle overheads. Setting this to true allows creating this wallet on startup, but might be undesirable in production (see `programs/createInternalBlsWallet.ts` for manual creation) | -| PRIORITY_FEE_PER_GAS | 0 | The priority fee used when submitting bundles (and passed on as a requirement for user bundles) | -| PREVIOUS_BASE_FEE_PERCENT_INCREASE | 2 | Used to determine the max basefee attached to aggregator transaction (and passed on as a requirement for user bundles)s | -| BUNDLE_CHECKING_CONCURRENCY | 8 | The maximum number of bundles that are checked concurrently (getting gas usage, detecting fees, etc) | +| Name | Example Value | Description | +| ------------------------------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| RPC_URL | https://localhost:8545 | The RPC endpoint for an EVM node that the BLS Wallet contracts are deployed on | +| RPC_POLLING_INTERVAL | 4000 | How long to wait between retries, when needed (used by ethers when waiting for blocks) | +| USE_TEST_NET | false | Whether to set all transaction's `gasPrice` to 0. Workaround for some networks | +| ORIGIN | http://localhost:3000 | The origin for the aggregator client. Used only in manual tests | +| PORT | 3000 | The port to bind the aggregator to | +| NETWORK_CONFIG_PATH | ../contracts/networks/local.json | Path to the network config file, which contains information on deployed BLS Wallet contracts | +| PRIVATE_KEY_AGG | 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 | Private key for the EOA account used to submit bundles on chain. Transactions are paid by the account linked to PRIVATE_KEY_AGG. By default, bundles must pay for themselves by sending funds to tx.origin or the aggregator’s onchain address | +| PRIVATE_KEY_ADMIN | 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d | Private key for the admin EOA account. Used only in tests | +| TEST_BLS_WALLETS_SECRET | test-bls-wallets-secret | Secret used to seed BLS Wallet private keys during tests | +| DB_PATH | aggregator.sqlite | File path of the sqlite db | +| BUNDLE_QUERY_LIMIT | 100 | Maximum number of bundles returned from sqlite | +| MAX_GAS_PER_BUNDLE | 2000000 | Limits the amount of user operations which can be bundled together by using this value as the approximate limit on the amount of gas in an aggregate bundle | +| MAX_AGGREGATION_DELAY_MILLIS | 5000 | Maximum amount of time in milliseconds aggregator will wait before submitting bundles on chain. A higher number will allow more time for bundles to fill, but may result in longer periods before submission. A lower number allows more frequent L2 submissions, but may result in smaller bundles | +| MAX_UNCONFIRMED_AGGREGATIONS | 3 | Maximum unconfirmed bundle aggregations that will be submitted on chain | +| LOG_QUERIES | false | Whether to print sqlite queries in event log. When running tests, `TEST_LOGGING` must also be enabled | +| TEST_LOGGING | false | Whether to print aggregator server events to stdout during tests. Useful for debugging & logging | +| REQUIRE_FEES | true | Whether to require that user bundles pay the aggregator a sufficient fee | +| BREAKEVEN_OPERATION_COUNT | 4.5 | The aggregator must pay an overhead to submit a bundle regardless of how many operations it contains. This parameter determines how much each operation must contribute to this overhead | +| ALLOW_LOSSES | true | Even if each user bundle pays the required fee, the aggregate bundle may not be profitable if it is too small. Setting this to true makes the aggregator submit these bundles anyway | +| FEE_TYPE | ether OR token:0xabcd...1234 | The fee type the aggregator will accept. Either `ether` for ETH/chains native currency or `token:0xabcd...1234` (token contract address) for an ERC20 token | +| AUTO_CREATE_INTERNAL_BLS_WALLET | false | An internal BLS wallet is used to calculate bundle overheads. Setting this to true allows creating this wallet on startup, but might be undesirable in production (see `programs/createInternalBlsWallet.ts` for manual creation) | +| PRIORITY_FEE_PER_GAS | 0 | The priority fee used when submitting bundles (and passed on as a requirement for user bundles) | +| PREVIOUS_BASE_FEE_PERCENT_INCREASE | 2 | Used to determine the max basefee attached to aggregator transaction (and passed on as a requirement for user bundles)s | +| BUNDLE_CHECKING_CONCURRENCY | 8 | The maximum number of bundles that are checked concurrently (getting gas usage, detecting fees, etc) | +| IS_OPTIMISM | false | Optimism's strategy for charging for L1 fees requires special logic in the aggregator. In addition to gasEstimate * gasPrice, we need to replicate Optimism's calculation and pass it on to the user | +| OPTIMISM_GAS_PRICE_ORACLE_ADDRESS | 0x420000000000000000000000000000000000000F | Address for the Optimism gas price oracle contract. Required when IS_OPTIMISM is true | +| OPTIMISM_L1_BASE_FEE_PERCENT_INCREASE | 2 | Similar to PREVIOUS_BASE_FEE_PERCENT_INCREASE, but for the L1 basefee for the optimism-specific calculation. This gets passed on to users. Required when IS_OPTIMISM is true | ## Running diff --git a/aggregator/src/app/OptimismGasPriceOracle.ts b/aggregator/src/app/OptimismGasPriceOracle.ts index 343b880d..7c99ffe7 100644 --- a/aggregator/src/app/OptimismGasPriceOracle.ts +++ b/aggregator/src/app/OptimismGasPriceOracle.ts @@ -1,16 +1,15 @@ import { BigNumber, ethers } from "../../deps.ts"; import assert from "../helpers/assert.ts"; +import { OPTIMISM_GAS_PRICE_ORACLE_ADDRESS } from "../env.ts"; export default class OptimismGasPriceOracle { - static address = "0x420000000000000000000000000000000000000F"; - constructor( public provider: ethers.providers.Provider, ) {} private async callFn(method: string, blockTag?: ethers.providers.BlockTag) { const outputBytes = await this.provider.call({ - to: OptimismGasPriceOracle.address, + to: OPTIMISM_GAS_PRICE_ORACLE_ADDRESS, data: ethers.utils.id(method), }, blockTag); diff --git a/aggregator/src/env.ts b/aggregator/src/env.ts index a5c095fd..04119893 100644 --- a/aggregator/src/env.ts +++ b/aggregator/src/env.ts @@ -1,5 +1,6 @@ import assert from "./helpers/assert.ts"; import { + optionalEnv, optionalNumberEnv, requireBigNumberEnv, requireBoolEnv, @@ -104,9 +105,18 @@ export const BUNDLE_CHECKING_CONCURRENCY = requireIntEnv( */ export const IS_OPTIMISM = requireBoolEnv("IS_OPTIMISM"); +/** + * Address for the Optimism gas price oracle contract. Required when + * IS_OPTIMISM is true. + */ +export const OPTIMISM_GAS_PRICE_ORACLE_ADDRESS = optionalEnv( + "OPTIMISM_GAS_PRICE_ORACLE_ADDRESS", +); + /** * Similar to PREVIOUS_BASE_FEE_PERCENT_INCREASE, but for the L1 basefee for * the optimism-specific calculation. This gets passed on to users. + * Required when IS_OPTIMISM is true. */ export const OPTIMISM_L1_BASE_FEE_PERCENT_INCREASE = optionalNumberEnv( "OPTIMISM_L1_BASE_FEE_PERCENT_INCREASE", @@ -117,4 +127,8 @@ if (IS_OPTIMISM) { OPTIMISM_L1_BASE_FEE_PERCENT_INCREASE !== nil, "OPTIMISM_L1_BASE_FEE_PERCENT_INCREASE is required when IS_OPTIMISM is true", ); + assert( + OPTIMISM_GAS_PRICE_ORACLE_ADDRESS !== nil, + "OPTIMISM_GAS_PRICE_ORACLE_ADDRESS is required when IS_OPTIMISM is true", + ); }