From 40b99a6ed4de28fd8481c77c546bf4a68ea2d993 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Wed, 23 Jun 2021 09:23:04 -0700 Subject: [PATCH] feat: `rollup gasPrices` RPC endpoint (#1136) * feature: l2geth endpoint * chore: add changeset Co-authored-by: Liam Horne --- .changeset/little-badgers-hammer.md | 6 ++++++ integration-tests/test/rpc.spec.ts | 11 +++++++++++ integration-tests/test/shared/env.ts | 9 ++++++++- l2geth/internal/ethapi/api.go | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .changeset/little-badgers-hammer.md diff --git a/.changeset/little-badgers-hammer.md b/.changeset/little-badgers-hammer.md new file mode 100644 index 000000000000..2c0beafb1d23 --- /dev/null +++ b/.changeset/little-badgers-hammer.md @@ -0,0 +1,6 @@ +--- +'@eth-optimism/integration-tests': patch +'@eth-optimism/l2geth': patch +--- + +Add new RPC endpoint `rollup_gasPrices` diff --git a/integration-tests/test/rpc.spec.ts b/integration-tests/test/rpc.spec.ts index 29a816cf9659..122740747bff 100644 --- a/integration-tests/test/rpc.spec.ts +++ b/integration-tests/test/rpc.spec.ts @@ -426,4 +426,15 @@ describe('Basic RPC tests', () => { .reverted }) }) + + describe('rollup_gasPrices', () => { + it('should return the L1 and L2 gas prices', async () => { + const result = await provider.send('rollup_gasPrices', []); + const l1GasPrice = await env.l1Wallet.provider.getGasPrice() + const l2GasPrice = await env.gasPriceOracle.gasPrice() + + expect(BigNumber.from(result.l1GasPrice)).to.deep.eq(l1GasPrice) + expect((BigNumber.from(result.l2GasPrice))).to.deep.eq(l2GasPrice) + }) + }) }) diff --git a/integration-tests/test/shared/env.ts b/integration-tests/test/shared/env.ts index 4b4f29e5071f..9da4690cf7aa 100644 --- a/integration-tests/test/shared/env.ts +++ b/integration-tests/test/shared/env.ts @@ -1,4 +1,4 @@ -import { getContractFactory } from '@eth-optimism/contracts' +import { getContractFactory, predeploys } from '@eth-optimism/contracts' import { Watcher } from '@eth-optimism/core-utils' import { Contract, utils, Wallet } from 'ethers' import { @@ -32,6 +32,7 @@ export class OptimismEnv { ovmEth: Contract l2Bridge: Contract l2Messenger: Contract + gasPriceOracle: Contract // The L1 <> L2 State watcher watcher: Watcher @@ -47,6 +48,7 @@ export class OptimismEnv { this.ovmEth = args.ovmEth this.l2Bridge = args.l2Bridge this.l2Messenger = args.l2Messenger + this.gasPriceOracle = args.gasPriceOracle this.watcher = args.watcher this.l1Wallet = args.l1Wallet this.l2Wallet = args.l2Wallet @@ -79,12 +81,17 @@ export class OptimismEnv { .connect(l1Wallet) .attach(ctcAddress) + const gasPriceOracle = getContractFactory('OVM_GasPriceOracle') + .connect(l2Wallet) + .attach(predeploys.OVM_GasPriceOracle) + return new OptimismEnv({ addressManager, l1Bridge, ctc, l1Messenger, ovmEth, + gasPriceOracle, l2Bridge, l2Messenger, watcher, diff --git a/l2geth/internal/ethapi/api.go b/l2geth/internal/ethapi/api.go index a8b3852c6e14..097a8e16b3c0 100644 --- a/l2geth/internal/ethapi/api.go +++ b/l2geth/internal/ethapi/api.go @@ -1983,6 +1983,27 @@ func (api *PublicRollupAPI) GetInfo(ctx context.Context) rollupInfo { } } +type gasPrices struct { + L1GasPrice *hexutil.Big `json:"l1GasPrice"` + L2GasPrice *hexutil.Big `json:"l2GasPrice"` +} + +// GasPrices returns the L1 and L2 gas price known by the node +func (api *PublicRollupAPI) GasPrices(ctx context.Context) (*gasPrices, error) { + l1GasPrice, err := api.b.SuggestL1GasPrice(ctx) + if err != nil { + return nil, err + } + l2GasPrice, err := api.b.SuggestL2GasPrice(ctx) + if err != nil { + return nil, err + } + return &gasPrices{ + L1GasPrice: (*hexutil.Big)(l1GasPrice), + L2GasPrice: (*hexutil.Big)(l2GasPrice), + }, nil +} + // PrivatelRollupAPI provides private RPC methods to control the sequencer. // These methods can be abused by external users and must be considered insecure for use by untrusted users. type PrivateRollupAPI struct {