Skip to content

Commit

Permalink
feat: rollup gasPrices RPC endpoint (#1136)
Browse files Browse the repository at this point in the history
* feature: l2geth  endpoint

* chore: add changeset

Co-authored-by: Liam Horne <liam@lihorne.com>
  • Loading branch information
tynes and snario authored Jun 23, 2021
1 parent 98e02cf commit 40b99a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/little-badgers-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@eth-optimism/integration-tests': patch
'@eth-optimism/l2geth': patch
---

Add new RPC endpoint `rollup_gasPrices`
11 changes: 11 additions & 0 deletions integration-tests/test/rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
9 changes: 8 additions & 1 deletion integration-tests/test/shared/env.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -32,6 +32,7 @@ export class OptimismEnv {
ovmEth: Contract
l2Bridge: Contract
l2Messenger: Contract
gasPriceOracle: Contract

// The L1 <> L2 State watcher
watcher: Watcher
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions l2geth/internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 40b99a6

Please sign in to comment.