Skip to content

Commit

Permalink
contracts: gas price oracle (#917)
Browse files Browse the repository at this point in the history
* contracts: gas price oracle

* tests: update

* fees: fix tests

* contracts: simplify gas price oracle

* lint: fix
  • Loading branch information
tynes authored and gakonst committed May 20, 2021
1 parent ab9119c commit 21614c8
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 95 deletions.
4 changes: 2 additions & 2 deletions packages/contracts/bin/take-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
}
}
8 changes: 4 additions & 4 deletions packages/contracts/src/contract-deployment/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface RollupDeployConfig {
allowArbitraryContractDeployment: boolean
}
l2ChugSplashDeployerOwner: string
congestionPriceOracleOwner: string
gasPriceOracleOwner: string
addressManager?: string
dependencies?: string[]
deployOverrides: Overrides
Expand Down Expand Up @@ -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],
},
}
}
6 changes: 3 additions & 3 deletions packages/contracts/src/state-dump/make-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
'OVM_ExecutionManagerWrapper',
'L2ChugSplashDeployer',
'L2ChugSplashOwner',
'OVM_CongestionPriceOracle',
'OVM_GasPriceOracle',
],
deployOverrides: {},
waitForReceipts: false,
l2ChugSplashDeployerOwner: cfg.l2ChugSplashDeployerOwner,
congestionPriceOracleOwner: cfg.congestionPriceOracleOwner,
gasPriceOracleOwner: cfg.gasPriceOracleOwner,
}

config = { ...config, ...cfg }
Expand All @@ -161,7 +161,7 @@ export const makeStateDump = async (cfg: RollupDeployConfig): Promise<any> => {
'OVM_ExecutionManagerWrapper',
'L2ChugSplashDeployer',
'L2ChugSplashOwner',
'OVM_CongestionPriceOracle',
'OVM_GasPriceOracle',
]

const deploymentResult = await deploy(config)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
)
})
})
})

0 comments on commit 21614c8

Please sign in to comment.