Commit 40b99a6e authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

feat: `rollup gasPrices` RPC endpoint (#1136)

* feature: l2geth  endpoint

* chore: add changeset
Co-authored-by: default avatarLiam Horne <liam@lihorne.com>
parent 98e02cfa
---
'@eth-optimism/integration-tests': patch
'@eth-optimism/l2geth': patch
---
Add new RPC endpoint `rollup_gasPrices`
......@@ -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)
})
})
})
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,
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment