Commit 8e2bfd07 authored by Karl Floersch's avatar Karl Floersch Committed by GitHub

feat: deployment config for fee oracle contract (#936)

* feat[contracts]: add GasPriceOracle w/o predeploy

Based on #912

* feat[contracts]: congestion price oracle

* chore: add changeset

* contracts: gas price oracle (#917)

* contracts: gas price oracle

* tests: update

* fees: fix tests

* contracts: simplify gas price oracle

* lint: fix

* test: execution price is at the 1st storage slot

* chore: rename predeploy to GasPriceOracle

* chore: rename gas price oracle test name
Co-authored-by: default avatarMark Tyneway <mark.tyneway@gmail.com>
Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>

* Add an L2 deploy script for gas oracle contract

* Add a kovan deployment artifact

* Add deployment to readme

* Add extra validation & initial execution price

* Update README.md

* Fix execution price logic

* Perform new deployment with final contract

* contracts: better require in ovm gas price oracle

* Deploy L2GasPriceOracle

* Update contract to use new fee logic & rename to gas

* Deploy updated contract

* Fix lint

* gas price oracle: do not restrict gas price

* gas price oracle: new deployment

* tests: delete dead test
Co-authored-by: default avatarsmartcontracts <kelvinfichter@gmail.com>
Co-authored-by: default avatarMark Tyneway <mark.tyneway@gmail.com>
Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
parent a02392b0
---
'@eth-optimism/contracts': patch
---
Introduces the congestion price oracle contract
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.8.0;
/* External Imports */
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title OVM_GasPriceOracle
* @dev This contract exposes the current l2 gas price, a measure of how congested the network
* currently is. This measure is used by the Sequencer to determine what fee to charge for
* transactions. When the system is more congested, the l2 gas price will increase and fees
* will also increase as a result.
*
* Compiler used: optimistic-solc
* Runtime target: OVM
*/
contract OVM_GasPriceOracle is Ownable {
/*************
* Variables *
*************/
// Current l2 gas price
uint256 public gasPrice;
/***************
* Constructor *
***************/
/**
* @param _owner Address that will initially own this contract.
*/
constructor(
address _owner,
uint256 _initialGasPrice
)
Ownable()
{
setGasPrice(_initialGasPrice);
transferOwnership(_owner);
}
/********************
* Public Functions *
********************/
/**
* Allows the owner to modify the l2 gas price.
* @param _gasPrice New l2 gas price.
*/
function setGasPrice(
uint256 _gasPrice
)
public
onlyOwner
{
gasPrice = _gasPrice;
}
}
/* Imports: External */
import { DeployFunction } from 'hardhat-deploy/dist/types'
/* Imports: Internal */
import { getContractDefinition } from '../src'
const deployFn: DeployFunction = async (hre: any) => {
const { deployments, getNamedAccounts } = hre
const { deploy } = deployments
const { deployer } = await getNamedAccounts()
const gasPriceOracle = getContractDefinition('OVM_GasPriceOracle', true)
const gasOracleOwner = (hre as any).deployConfig.ovmSequencerAddress
const initialGasPrice = (hre as any).deployConfig.initialGasPriceOracleGasPrice
if (!gasOracleOwner || !initialGasPrice) {
throw new Error('initialGasPrice & ovmSequencerAddress required to deploy gas price oracle')
}
await deploy('OVM_GasPriceOracle', {
contract: gasPriceOracle,
from: deployer,
args: [gasOracleOwner, initialGasPrice],
log: true,
});
}
deployFn.tags = ['OVM_GasPriceOracle']
export default deployFn
# Optimism Regenesis Deployments # Optimism Regenesis Deployments
## LAYER 2 ## LAYER 2
## OPTIMISTIC-KOVAN
Network : __optimistic-kovan (chain id: 69)__
|Contract|Address|
|--|--|
|OVM_GasPriceOracle|[0x038a8825A3C3B0c08d52Cc76E5E361953Cf6Dc76](https://kovan-optimistic.etherscan.io/address/0x038a8825A3C3B0c08d52Cc76E5E361953Cf6Dc76)|
---
### Chain IDs: ### Chain IDs:
- Mainnet: 10 - Mainnet: 10
- Kovan: 69 - Kovan: 69
......
...@@ -99,6 +99,12 @@ task('deploy') ...@@ -99,6 +99,12 @@ task('deploy')
undefined, undefined,
types.string types.string
) )
.addOptionalParam(
'initialGasPriceOracleGasPrice',
'The initial execution price for the gas price oracle.',
undefined,
types.int
)
.setAction(async (args, hre: any, runSuper) => { .setAction(async (args, hre: any, runSuper) => {
// Necessary because hardhat doesn't let us attach non-optional parameters to existing tasks. // Necessary because hardhat doesn't let us attach non-optional parameters to existing tasks.
const validateAddressArg = (argName: string) => { const validateAddressArg = (argName: string) => {
......
import { expect } from '../../../setup'
/* External Imports */
import { ethers } from 'hardhat'
import { ContractFactory, Contract, Signer } from 'ethers'
describe('OVM_GasPriceOracle', () => {
const initialGasPrice = 0
let signer1: Signer
let signer2: Signer
before(async () => {
;[signer1, signer2] = await ethers.getSigners()
})
let Factory__OVM_GasPriceOracle: ContractFactory
before(async () => {
Factory__OVM_GasPriceOracle = await ethers.getContractFactory(
'OVM_GasPriceOracle'
)
})
let OVM_GasPriceOracle: Contract
beforeEach(async () => {
OVM_GasPriceOracle = await Factory__OVM_GasPriceOracle.deploy(
await signer1.getAddress(),
initialGasPrice
)
})
describe('owner', () => {
it('should have an owner', async () => {
expect(await OVM_GasPriceOracle.owner()).to.equal(
await signer1.getAddress()
)
})
})
describe('setGasPrice', () => {
it('should revert if called by someone other than the owner', async () => {
await expect(OVM_GasPriceOracle.connect(signer2).setGasPrice(1234)).to.be
.reverted
})
it('should succeed if called by the owner and is equal to `0`', async () => {
await expect(OVM_GasPriceOracle.connect(signer1).setGasPrice(0)).to.not.be
.reverted
})
})
describe('get gasPrice', () => {
it('should return zero at first', async () => {
expect(await OVM_GasPriceOracle.gasPrice()).to.equal(initialGasPrice)
})
it('should change when setGasPrice is called', async () => {
const gasPrice = 1234
await OVM_GasPriceOracle.connect(signer1).setGasPrice(gasPrice)
expect(await OVM_GasPriceOracle.gasPrice()).to.equal(gasPrice)
})
it('is the 1st storage slot', async () => {
const gasPrice = 1234
const slot = 1
// set the price
await OVM_GasPriceOracle.connect(signer1).setGasPrice(gasPrice)
// get the storage slot value
const priceAtSlot = await signer1.provider.getStorageAt(
OVM_GasPriceOracle.address,
slot
)
expect(await OVM_GasPriceOracle.gasPrice()).to.equal(
ethers.BigNumber.from(priceAtSlot)
)
})
})
})
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