From 21614c88b3d4540fabd2455f75def57a62378f48 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Wed, 19 May 2021 20:12:23 -0700 Subject: [PATCH] contracts: gas price oracle (#917) * contracts: gas price oracle * tests: update * fees: fix tests * contracts: simplify gas price oracle * lint: fix --- packages/contracts/bin/take-dump.ts | 4 +- ...PriceOracle.sol => OVM_GasPriceOracle.sol} | 37 +++++----- .../src/contract-deployment/config.ts | 8 +-- .../contracts/src/state-dump/make-dump.ts | 6 +- .../OVM_CongestionPriceOracle.spec.ts | 67 ------------------- .../precompiles/OVM_GasPriceOracle.spec.ts | 65 ++++++++++++++++++ 6 files changed, 92 insertions(+), 95 deletions(-) rename packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/{OVM_CongestionPriceOracle.sol => OVM_GasPriceOracle.sol} (56%) delete mode 100644 packages/contracts/test/contracts/OVM/precompiles/OVM_CongestionPriceOracle.spec.ts create mode 100644 packages/contracts/test/contracts/OVM/precompiles/OVM_GasPriceOracle.spec.ts diff --git a/packages/contracts/bin/take-dump.ts b/packages/contracts/bin/take-dump.ts index ad7d8b3d124c..95c35680eec4 100644 --- a/packages/contracts/bin/take-dump.ts +++ b/packages/contracts/bin/take-dump.ts @@ -8,7 +8,7 @@ const CHAIN_ID = env.CHAIN_ID || '420' // Defaults to 0xFF....FF = *no upgrades* const L2_CHUG_SPLASH_DEPLOYER_OWNER = env.L2_CHUG_SPLASH_DEPLOYER_OWNER || '0x' + 'FF'.repeat(20) -const CONGESTION_PRICE_ORACLE_OWNER = env.CONGESTION_PRICE_ORACLE_OWNER || '0x' + 'FF'.repeat(20) +const GAS_PRICE_ORACLE_OWNER = env.GAS_PRICE_ORACLE_OWNER || '0x' + 'FF'.repeat(20) /* Internal Imports */ import { makeStateDump } from '../src/state-dump/make-dump' @@ -23,7 +23,7 @@ import { RollupDeployConfig } from '../src/contract-deployment' ovmCHAINID: parseInt(CHAIN_ID, 10), }, l2ChugSplashDeployerOwner: L2_CHUG_SPLASH_DEPLOYER_OWNER, - congestionPriceOracleOwner: CONGESTION_PRICE_ORACLE_OWNER + gasPriceOracleOwner: GAS_PRICE_ORACLE_OWNER } const dump = await makeStateDump(config as RollupDeployConfig) diff --git a/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_CongestionPriceOracle.sol b/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_GasPriceOracle.sol similarity index 56% rename from packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_CongestionPriceOracle.sol rename to packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_GasPriceOracle.sol index 82131fb48a05..6f11866b0857 100644 --- a/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_CongestionPriceOracle.sol +++ b/packages/contracts/contracts/optimistic-ethereum/OVM/predeploys/OVM_GasPriceOracle.sol @@ -5,29 +5,28 @@ pragma solidity >0.5.0 <0.8.0; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; /** - * @title OVM_CongestionPriceOracle - * @dev This contract exposes the current congestion price, a measure of how congested the network + * @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 congestion price will increase and fees + * 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_CongestionPriceOracle is Ownable { - +contract OVM_GasPriceOracle is Ownable { + /************* * Variables * *************/ - - // Current congestion price - uint256 internal congestionPrice; - + + // Current execution price + uint256 internal executionPrice; /*************** * Constructor * ***************/ - + /** * @param _owner Address that will initially own this contract. */ @@ -43,30 +42,30 @@ contract OVM_CongestionPriceOracle is Ownable { /******************** * Public Functions * ********************/ - + /** - * @return Current congestion price. + * @return Current execution price. */ - function getCongestionPrice() + function getExecutionPrice() public view returns ( uint256 ) { - return congestionPrice; + return executionPrice; } /** - * Allows the owner to modify the congestion price. - * @param _congestionPrice New congestion price. + * Allows the owner to modify the execution price. + * @param _executionPrice New execution price. */ - function setCongestionPrice( - uint256 _congestionPrice + function setExecutionPrice( + uint256 _executionPrice ) public onlyOwner { - congestionPrice = _congestionPrice; + executionPrice = _executionPrice; } } diff --git a/packages/contracts/src/contract-deployment/config.ts b/packages/contracts/src/contract-deployment/config.ts index 78a718612ebe..59e78b5898c7 100644 --- a/packages/contracts/src/contract-deployment/config.ts +++ b/packages/contracts/src/contract-deployment/config.ts @@ -36,7 +36,7 @@ export interface RollupDeployConfig { allowArbitraryContractDeployment: boolean } l2ChugSplashDeployerOwner: string - congestionPriceOracleOwner: string + gasPriceOracleOwner: string addressManager?: string dependencies?: string[] deployOverrides: Overrides @@ -269,9 +269,9 @@ export const makeContractDeployConfig = async ( factory: getContractFactory('L2ChugSplashDeployer'), params: [config.l2ChugSplashDeployerOwner], }, - OVM_CongestionPriceOracle: { - factory: getContractFactory('OVM_CongestionPriceOracle'), - params: [config.congestionPriceOracleOwner], + OVM_GasPriceOracle: { + factory: getContractFactory('OVM_GasPriceOracle'), + params: [config.gasPriceOracleOwner], }, } } diff --git a/packages/contracts/src/state-dump/make-dump.ts b/packages/contracts/src/state-dump/make-dump.ts index 14c398df1051..e1442c62e9a5 100644 --- a/packages/contracts/src/state-dump/make-dump.ts +++ b/packages/contracts/src/state-dump/make-dump.ts @@ -139,12 +139,12 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise => { 'OVM_ExecutionManagerWrapper', 'L2ChugSplashDeployer', 'L2ChugSplashOwner', - 'OVM_CongestionPriceOracle', + 'OVM_GasPriceOracle', ], deployOverrides: {}, waitForReceipts: false, l2ChugSplashDeployerOwner: cfg.l2ChugSplashDeployerOwner, - congestionPriceOracleOwner: cfg.congestionPriceOracleOwner, + gasPriceOracleOwner: cfg.gasPriceOracleOwner, } config = { ...config, ...cfg } @@ -161,7 +161,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise => { 'OVM_ExecutionManagerWrapper', 'L2ChugSplashDeployer', 'L2ChugSplashOwner', - 'OVM_CongestionPriceOracle', + 'OVM_GasPriceOracle', ] const deploymentResult = await deploy(config) diff --git a/packages/contracts/test/contracts/OVM/precompiles/OVM_CongestionPriceOracle.spec.ts b/packages/contracts/test/contracts/OVM/precompiles/OVM_CongestionPriceOracle.spec.ts deleted file mode 100644 index 8a0c0dbfdacc..000000000000 --- a/packages/contracts/test/contracts/OVM/precompiles/OVM_CongestionPriceOracle.spec.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { expect } from '../../../setup' - -/* External Imports */ -import { ethers } from 'hardhat' -import { ContractFactory, Contract, Signer } from 'ethers' - -describe('OVM_SequencerEntrypoint', () => { - let signer1: Signer - let signer2: Signer - before(async () => { - ;[signer1, signer2] = await ethers.getSigners() - }) - - let Factory__OVM_CongestionPriceOracle: ContractFactory - before(async () => { - Factory__OVM_CongestionPriceOracle = await ethers.getContractFactory( - 'OVM_CongestionPriceOracle' - ) - }) - - let OVM_CongestionPriceOracle: Contract - beforeEach(async () => { - OVM_CongestionPriceOracle = await Factory__OVM_CongestionPriceOracle.deploy( - await signer1.getAddress() - ) - }) - - describe('owner', () => { - it('should have an owner', async () => { - expect(await OVM_CongestionPriceOracle.owner()).to.equal( - await signer1.getAddress() - ) - }) - }) - - describe('setCongestionPrice', () => { - it('should revert if called by someone other than the owner', async () => { - await expect( - OVM_CongestionPriceOracle.connect(signer2).setCongestionPrice(1234) - ).to.be.reverted - }) - - it('should succeed if called by the owner', async () => { - await expect( - OVM_CongestionPriceOracle.connect(signer1).setCongestionPrice(1234) - ).to.not.be.reverted - }) - }) - - describe('getCongestionPrice', () => { - it('should return zero at first', async () => { - expect(await OVM_CongestionPriceOracle.getCongestionPrice()).to.equal(0) - }) - - it('should change when setCongestionPrice is called', async () => { - const congestionPrice = 1234 - - await OVM_CongestionPriceOracle.connect(signer1).setCongestionPrice( - congestionPrice - ) - - expect(await OVM_CongestionPriceOracle.getCongestionPrice()).to.equal( - congestionPrice - ) - }) - }) -}) diff --git a/packages/contracts/test/contracts/OVM/precompiles/OVM_GasPriceOracle.spec.ts b/packages/contracts/test/contracts/OVM/precompiles/OVM_GasPriceOracle.spec.ts new file mode 100644 index 000000000000..64d099d7c40f --- /dev/null +++ b/packages/contracts/test/contracts/OVM/precompiles/OVM_GasPriceOracle.spec.ts @@ -0,0 +1,65 @@ +import { expect } from '../../../setup' + +/* External Imports */ +import { ethers } from 'hardhat' +import { ContractFactory, Contract, Signer } from 'ethers' + +describe('OVM_SequencerEntrypoint', () => { + 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 + ) + }) + }) +})