-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[contracts]: introduce OVM_GasPriceOracle (#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: Mark Tyneway <[email protected]> Co-authored-by: Georgios Konstantopoulos <[email protected]>
- Loading branch information
1 parent
4866d7b
commit 9475409
Showing
7 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@eth-optimism/contracts': patch | ||
--- | ||
|
||
Introduces the congestion price oracle contract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_GasPriceOracle.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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 execution 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 execution 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 execution price | ||
uint256 internal executionPrice; | ||
|
||
/*************** | ||
* Constructor * | ||
***************/ | ||
|
||
/** | ||
* @param _owner Address that will initially own this contract. | ||
*/ | ||
constructor( | ||
address _owner | ||
) | ||
Ownable() | ||
{ | ||
transferOwnership(_owner); | ||
} | ||
|
||
|
||
/******************** | ||
* Public Functions * | ||
********************/ | ||
|
||
/** | ||
* @return Current execution price. | ||
*/ | ||
function getExecutionPrice() | ||
public | ||
view | ||
returns ( | ||
uint256 | ||
) | ||
{ | ||
return executionPrice; | ||
} | ||
|
||
/** | ||
* Allows the owner to modify the execution price. | ||
* @param _executionPrice New execution price. | ||
*/ | ||
function setExecutionPrice( | ||
uint256 _executionPrice | ||
) | ||
public | ||
onlyOwner | ||
{ | ||
executionPrice = _executionPrice; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/contracts/test/contracts/OVM/precompiles/OVM_GasPriceOracle.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { expect } from '../../../setup' | ||
|
||
/* External Imports */ | ||
import { ethers } from 'hardhat' | ||
import { ContractFactory, Contract, Signer } from 'ethers' | ||
|
||
describe('OVM_GasPriceOracle', () => { | ||
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() | ||
) | ||
}) | ||
|
||
describe('owner', () => { | ||
it('should have an owner', async () => { | ||
expect(await OVM_GasPriceOracle.owner()).to.equal( | ||
await signer1.getAddress() | ||
) | ||
}) | ||
}) | ||
|
||
describe('setExecutionPrice', () => { | ||
it('should revert if called by someone other than the owner', async () => { | ||
await expect(OVM_GasPriceOracle.connect(signer2).setExecutionPrice(1234)) | ||
.to.be.reverted | ||
}) | ||
|
||
it('should succeed if called by the owner', async () => { | ||
await expect(OVM_GasPriceOracle.connect(signer1).setExecutionPrice(1234)) | ||
.to.not.be.reverted | ||
}) | ||
}) | ||
|
||
describe('getExecutionPrice', () => { | ||
it('should return zero at first', async () => { | ||
expect(await OVM_GasPriceOracle.getExecutionPrice()).to.equal(0) | ||
}) | ||
|
||
it('should change when setExecutionPrice is called', async () => { | ||
const executionPrice = 1234 | ||
|
||
await OVM_GasPriceOracle.connect(signer1).setExecutionPrice( | ||
executionPrice | ||
) | ||
|
||
expect(await OVM_GasPriceOracle.getExecutionPrice()).to.equal( | ||
executionPrice | ||
) | ||
}) | ||
|
||
it('is the 1st storage slot', async () => { | ||
const executionPrice = 1234 | ||
const slot = 1 | ||
|
||
// set the price | ||
await OVM_GasPriceOracle.connect(signer1).setExecutionPrice( | ||
executionPrice | ||
) | ||
|
||
// get the storage slot value | ||
const priceAtSlot = await signer1.provider.getStorageAt( | ||
OVM_GasPriceOracle.address, | ||
slot | ||
) | ||
expect(await OVM_GasPriceOracle.getExecutionPrice()).to.equal( | ||
ethers.BigNumber.from(priceAtSlot) | ||
) | ||
}) | ||
}) | ||
}) |