Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deployment config for fee oracle contract #936

Merged
merged 19 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-carpets-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts': patch
---

Introduces the congestion price oracle contract
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
tynes marked this conversation as resolved.
Show resolved Hide resolved
)
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(
tynes marked this conversation as resolved.
Show resolved Hide resolved
uint256 _executionPrice
)
public
onlyOwner
{
executionPrice = _executionPrice;
}
}
24 changes: 24 additions & 0 deletions packages/contracts/deploy-l2/000-OVM_GasPriceOracle.deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* 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)

await deploy('OVM_GasPriceOracle', {
contract: gasPriceOracle,
from: deployer,
args: [(hre as any).deployConfig.ovmSequencerAddress],
log: true,
});
}

deployFn.tags = ['OVM_GasPriceOracle']

export default deployFn
9 changes: 9 additions & 0 deletions packages/contracts/deployments/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Optimism Regenesis Deployments
## LAYER 2

## OPTIMISTIC-KOVAN

Network : __undefined (chain id: 69)__

|Contract|Address|
|--|--|
|OVM_GasPriceOracle|[0x668E5b997b9aE88a56cd40409119d4Db9e6d752E](https://undefined.etherscan.io/address/0x668E5b997b9aE88a56cd40409119d4Db9e6d752E)|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this undefined? Does our code generation script have an error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is undefined because this was deployed to L2. The script needs to be updated to point to the optimistic etherscan but I don't believe there is a kovan optimistic etherscan

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

---

### Chain IDs:
- Mainnet: 10
- Kovan: 69
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/deployments/optimistic-kovan/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
69
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"address": "0x668E5b997b9aE88a56cd40409119d4Db9e6d752E",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_owner",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "getExecutionPrice",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_executionPrice",
"type": "uint256"
}
],
"name": "setExecutionPrice",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"transactionHash": "0x462abd3d2d81ff8fc93d3474c3d97130b7b2b6a60a8860271a8fd26b30e344c0",
"receipt": {
"to": null,
"from": "0xd033f09cB85621F98F7A84C64dB381ac16Eff818",
"contractAddress": "0x668E5b997b9aE88a56cd40409119d4Db9e6d752E",
"transactionIndex": 0,
"gasUsed": "1683084",
"logsBloom": "0x00000000000000000000000000000040000000000000000000840000000000000000000000000000000000100000000000000000000200040000000000000000000000000000000000000008000000000001000010000000000000000000000400000000020000200000000000008800000000000000000000000010000020400000000000000000000000000000000000000000002000000000000000000000000000000000000000010000000000000000000000000000000000000000000000008002000000000000000000000000000000000000000000000000000060000000000000000000000000000000000001000000000000000000000000000000",
"blockHash": "0xe535ac12159e47d36cc8c40cd8687c91befafa6bf3f70bb8e145349f13097e05",
"transactionHash": "0x462abd3d2d81ff8fc93d3474c3d97130b7b2b6a60a8860271a8fd26b30e344c0",
"logs": [
{
"transactionIndex": 0,
"blockNumber": 168730,
"transactionHash": "0x462abd3d2d81ff8fc93d3474c3d97130b7b2b6a60a8860271a8fd26b30e344c0",
"address": "0x4200000000000000000000000000000000000006",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x000000000000000000000000d033f09cb85621f98f7a84c64db381ac16eff818",
"0x0000000000000000000000004200000000000000000000000000000000000005"
],
"data": "0x0000000000000000000000000000000000000000000000000000000000000000",
"logIndex": 0,
"blockHash": "0xe535ac12159e47d36cc8c40cd8687c91befafa6bf3f70bb8e145349f13097e05"
},
{
"transactionIndex": 0,
"blockNumber": 168730,
"transactionHash": "0x462abd3d2d81ff8fc93d3474c3d97130b7b2b6a60a8860271a8fd26b30e344c0",
"address": "0x668E5b997b9aE88a56cd40409119d4Db9e6d752E",
"topics": [
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x000000000000000000000000d033f09cb85621f98f7a84c64db381ac16eff818"
],
"data": "0x",
"logIndex": 1,
"blockHash": "0xe535ac12159e47d36cc8c40cd8687c91befafa6bf3f70bb8e145349f13097e05"
},
{
"transactionIndex": 0,
"blockNumber": 168730,
"transactionHash": "0x462abd3d2d81ff8fc93d3474c3d97130b7b2b6a60a8860271a8fd26b30e344c0",
"address": "0x668E5b997b9aE88a56cd40409119d4Db9e6d752E",
"topics": [
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
"0x000000000000000000000000d033f09cb85621f98f7a84c64db381ac16eff818",
"0x00000000000000000000000018394b52d3cb931dfa76f63251919d051953413d"
],
"data": "0x",
"logIndex": 2,
"blockHash": "0xe535ac12159e47d36cc8c40cd8687c91befafa6bf3f70bb8e145349f13097e05"
}
],
"blockNumber": 168730,
"cumulativeGasUsed": "1683084",
"status": 1,
"byzantium": true
},
"args": [
"0x18394B52d3Cb931dfA76F63251919D051953413d"
],
"bytecode": "0x60806040523480156100195760008061001661023f565b50505b506040516109a03803806109a0833981810160405260208110156100455760008061004261023f565b50505b81019080805192506000915061005b90506100c6565b905080600060018161006b6102aa565b816001600160a01b0302191690836001600160a01b031602179061008d61030a565b5050506001600160a01b038116600060008051602061098083398151915260405160405180910390a3506100c0816100d6565b5061039e565b60005a6100d1610358565b905090565b6100de6100c6565b6001600160a01b03166100ef61021e565b6001600160a01b0316146101525760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016040518091039061014f61023f565b50505b6001600160a01b0381166101a05760405162461bcd60e51b815260040180806020018281038252602681526020018061095a602691396040019150506040518091039061019d61023f565b50505b806001600160a01b03166000806101b56102aa565b906101000a90046001600160a01b03166001600160a01b031660008051602061098083398151915260405160405180910390a38060006001816101f66102aa565b816001600160a01b0302191690836001600160a01b031602179061021861030a565b50505050565b6000808061022a6102aa565b906101000a90046001600160a01b0316905090565b632a2a7adb598160e01b8152600481016020815285602082015260005b8681101561027757808601518282016040015260200161025c565b506020828760640184336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b505050565b6303daa959598160e01b8152836004820152602081602483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b8051935060005b6040811015610305576000828201526020016102ee565b505050565b6322bd64c0598160e01b8152836004820152846024820152600081604483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b6000815260206102ee565b6373509064598160e01b8152602081600483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b805160008252935060206102ee565b6105ad806103ad6000396000f3fe60806040523480156100195760008061001661042c565b50505b50600436106100605760003560e01c8063447cca981461006e578063715018a6146100885780638da5cb5b14610092578063ee6d2073146100b6578063f2fde38b146100dc575b60008061006b61042c565b50505b61007661010b565b60405190815260200160405180910390f35b61009061011c565b005b61009a61021e565b6040516001600160a01b03909116815260200160405180910390f35b610090600480360360208110156100d5576000806100d261042c565b50505b503561023f565b610090600480360360208110156100fb576000806100f861042c565b50505b50356001600160a01b03166102cd565b60006001610117610497565b905090565b610124610421565b6001600160a01b031661013561021e565b6001600160a01b0316146101985760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016040518091039061019561042c565b50505b600080806101a4610497565b906101000a90046001600160a01b03166001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000806001816101f7610497565b816001600160a01b0302191690836001600160a01b03160217906102196104f2565b505050565b6000808061022a610497565b906101000a90046001600160a01b0316905090565b610247610421565b6001600160a01b031661025861021e565b6001600160a01b0316146102bb5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401604051809103906102b861042c565b50505b808060016102c76104f2565b50505050565b6102d5610421565b6001600160a01b03166102e661021e565b6001600160a01b0316146103495760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016040518091039061034661042c565b50505b6001600160a01b0381166103975760405162461bcd60e51b8152600401808060200182810382526026815260200180610587602691396040019150506040518091039061039461042c565b50505b806001600160a01b03166000806103ac610497565b906101000a90046001600160a01b03166001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a38060006001816103ff610497565b816001600160a01b0302191690836001600160a01b03160217906102c76104f2565b60005a610117610540565b632a2a7adb598160e01b8152600481016020815285602082015260005b86811015610464578086015182820160400152602001610449565b506020828760640184336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b505050565b6303daa959598160e01b8152836004820152602081602483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b8051935060005b6040811015610219576000828201526020016104db565b6322bd64c0598160e01b8152836004820152846024820152600081604483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b6000815260206104db565b6373509064598160e01b8152602081600483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b805160008252935060206104db56fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573738be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
"deployedBytecode": "0x60806040523480156100195760008061001661042c565b50505b50600436106100605760003560e01c8063447cca981461006e578063715018a6146100885780638da5cb5b14610092578063ee6d2073146100b6578063f2fde38b146100dc575b60008061006b61042c565b50505b61007661010b565b60405190815260200160405180910390f35b61009061011c565b005b61009a61021e565b6040516001600160a01b03909116815260200160405180910390f35b610090600480360360208110156100d5576000806100d261042c565b50505b503561023f565b610090600480360360208110156100fb576000806100f861042c565b50505b50356001600160a01b03166102cd565b60006001610117610497565b905090565b610124610421565b6001600160a01b031661013561021e565b6001600160a01b0316146101985760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016040518091039061019561042c565b50505b600080806101a4610497565b906101000a90046001600160a01b03166001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a36000806001816101f7610497565b816001600160a01b0302191690836001600160a01b03160217906102196104f2565b505050565b6000808061022a610497565b906101000a90046001600160a01b0316905090565b610247610421565b6001600160a01b031661025861021e565b6001600160a01b0316146102bb5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401604051809103906102b861042c565b50505b808060016102c76104f2565b50505050565b6102d5610421565b6001600160a01b03166102e661021e565b6001600160a01b0316146103495760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016040518091039061034661042c565b50505b6001600160a01b0381166103975760405162461bcd60e51b8152600401808060200182810382526026815260200180610587602691396040019150506040518091039061039461042c565b50505b806001600160a01b03166000806103ac610497565b906101000a90046001600160a01b03166001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a38060006001816103ff610497565b816001600160a01b0302191690836001600160a01b03160217906102c76104f2565b60005a610117610540565b632a2a7adb598160e01b8152600481016020815285602082015260005b86811015610464578086015182820160400152602001610449565b506020828760640184336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b505050565b6303daa959598160e01b8152836004820152602081602483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b8051935060005b6040811015610219576000828201526020016104db565b6322bd64c0598160e01b8152836004820152846024820152600081604483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b6000815260206104db565b6373509064598160e01b8152602081600483336000905af158600e01573d6000803e3d6000fd5b3d6001141558600a015760016000f35b805160008252935060206104db56fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373"
}
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)
)
})
})
})