Skip to content

Commit

Permalink
Add proxy contract for Boba_GasPriceOracle (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
boyuan-chen authored Apr 20, 2022
1 parent 9f234ec commit e20bc72
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract Proxy__Boba_GasPriceOracle {
contract Boba_GasPriceOracleProxyCall {
address public gasPriceOracleAddress;

constructor(address _gasPriceOracleAddress) {
Expand Down
47 changes: 32 additions & 15 deletions integration-tests/test/boba-fee-payment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { OptimismEnv } from './shared/env'
import { gasPriceOracleWallet } from './shared/utils'

/* Imports: ABI */
import Proxy__Boba_GasPriceOracleJson from '../artifacts/contracts/Proxy__Boba_GasPriceOracle.sol/Proxy__Boba_GasPriceOracle.json'
import Boba_GasPriceOracleProxyCallJson from '../artifacts/contracts/Boba_GasPriceOracleProxyCall.sol/Boba_GasPriceOracleProxyCall.json'

const setPrices = async (env: OptimismEnv, value: number | BigNumber) => {
const gasPrice = await env.messenger.contracts.l2.OVM_GasPriceOracle.connect(
Expand All @@ -31,10 +31,11 @@ describe('Boba Fee Payment Integration Tests', async () => {
let L1Boba: Contract
let L2Boba: Contract
let Boba_GasPriceOracle: Contract

let Factory__Proxy__Boba_GasPriceOracle: ContractFactory
let Proxy__Boba_GasPriceOracle: Contract

let Factory__Boba_GasPriceOracleProxyCall: ContractFactory
let Boba_GasPriceOracleProxyCall: Contract

const other = '0x1234123412341234123412341234123412341234'

before(async () => {
Expand All @@ -47,20 +48,35 @@ describe('Boba Fee Payment Integration Tests', async () => {
.attach(predeploys.L2GovernanceERC20)
.connect(env.l2Wallet)
Boba_GasPriceOracle = getContractFactory('Boba_GasPriceOracle')
.attach(predeploys.Boba_GasPriceOracle)
.attach(predeploys.Proxy__Boba_GasPriceOracle)
.connect(env.l2Wallet)

Proxy__Boba_GasPriceOracle = getContractFactory(
'Lib_ResolvedDelegateBobaProxy'
)
.attach(predeploys.Proxy__Boba_GasPriceOracle)
.connect(env.l2Wallet)

Factory__Proxy__Boba_GasPriceOracle = new ethers.ContractFactory(
Proxy__Boba_GasPriceOracleJson.abi,
Proxy__Boba_GasPriceOracleJson.bytecode,
Factory__Boba_GasPriceOracleProxyCall = new ethers.ContractFactory(
Boba_GasPriceOracleProxyCallJson.abi,
Boba_GasPriceOracleProxyCallJson.bytecode,
env.l2Wallet
)

Proxy__Boba_GasPriceOracle =
await Factory__Proxy__Boba_GasPriceOracle.deploy(
Boba_GasPriceOracleProxyCall =
await Factory__Boba_GasPriceOracleProxyCall.deploy(
Boba_GasPriceOracle.address
)
await Proxy__Boba_GasPriceOracle.deployTransaction.wait()
await Boba_GasPriceOracleProxyCall.deployTransaction.wait()
})

it('{tag:boba} should have correct proxy target and proxy owner', async () => {
expect(
await Proxy__Boba_GasPriceOracle.addressManager('proxyOwner')
).to.be.eq(env.l1Wallet.address)
expect(
await Proxy__Boba_GasPriceOracle.addressManager('proxyTarget')
).to.be.eq(predeploys.Boba_GasPriceOracle)
})

it('{tag:boba} should register to use boba as the fee token', async () => {
Expand All @@ -74,8 +90,9 @@ describe('Boba Fee Payment Integration Tests', async () => {
})

it('{tag:boba} should not register the fee tokens for non EOA accounts', async () => {
await expect(Proxy__Boba_GasPriceOracle.useBobaAsFeeToken()).to.be.reverted
await expect(Proxy__Boba_GasPriceOracle.useETHAsFeeToken()).to.be.reverted
await expect(Boba_GasPriceOracleProxyCall.useBobaAsFeeToken()).to.be
.reverted
await expect(Boba_GasPriceOracleProxyCall.useETHAsFeeToken()).to.be.reverted
})

it('{tag:boba} Paying a nonzero but acceptable boba gasPrice fee for transferring ETH', async () => {
Expand Down Expand Up @@ -636,7 +653,7 @@ describe('Boba Fee Payment Integration Tests', async () => {
Boba_GasPriceOracle.address
)

const TestContract = await Factory__Proxy__Boba_GasPriceOracle.deploy(
const TestContract = await Factory__Boba_GasPriceOracleProxyCall.deploy(
Boba_GasPriceOracle.address
)
const receipt = await TestContract.deployTransaction.wait()
Expand Down Expand Up @@ -667,7 +684,7 @@ describe('Boba Fee Payment Integration Tests', async () => {
it('{tag:boba} should pay BOBA to deploy contracts for different gas limit', async () => {
await setPrices(env, 1000)

const data = Factory__Proxy__Boba_GasPriceOracle.getDeployTransaction(
const data = Factory__Boba_GasPriceOracleProxyCall.getDeployTransaction(
Boba_GasPriceOracle.address
)
const estimatedGas = await env.l2Wallet.estimateGas(data)
Expand All @@ -683,7 +700,7 @@ describe('Boba Fee Payment Integration Tests', async () => {
Boba_GasPriceOracle.address
)

const TestContract = await Factory__Proxy__Boba_GasPriceOracle.deploy(
const TestContract = await Factory__Boba_GasPriceOracleProxyCall.deploy(
Boba_GasPriceOracle.address
)
const receipt = await TestContract.deployTransaction.wait()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ library Lib_PredeployAddresses {
0x4200000000000000000000000000000000000020;
address internal constant BOBA_TURING_PREPAY = 0x4200000000000000000000000000000000000021;
address internal constant BOBA_TURING_HELPER = 0x4200000000000000000000000000000000000022;
address internal constant L2_BOBA = 0x4200000000000000000000000000000000000023;
address internal constant PROXY__BOBA_GAS_PRICE_ORACLE =
0x4200000000000000000000000000000000000024;
address internal constant BOBA_GAS_PRICE_ORACLE = 0x4200000000000000000000000000000000000025;
}
45 changes: 37 additions & 8 deletions packages/contracts/src/make-genesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export interface RollupDeployConfig {
berlinBlock: number
}

const addSlotsForBobaProxyContract = (
dump: any, predeployAddress: string, variable: any
) => {
for (const keyName of Object.keys(variable)) {
const key = utils.hexlify(utils.toUtf8Bytes(keyName));
const index = BigNumber.from('0').toHexString();
const newKeyPreimage = utils.concat([key, utils.hexZeroPad(index, 32)]);
const compositeKey = utils.keccak256(utils.hexlify(newKeyPreimage));
dump[predeployAddress].storage[compositeKey] = variable[keyName]
}
return dump
}

/**
* Generates the initial state for the L2 system by injecting the relevant L2 system contracts.
*
Expand Down Expand Up @@ -123,6 +136,10 @@ export const makeL2GenesisFile = async (
l1Token: cfg.l1BobaTokenAddress,
l2Bridge:predeploys.L2StandardBridge,
},
Proxy__Boba_GasPriceOracle: {
proxyOwner: cfg.deployer,
proxyTarget: predeploys.Boba_GasPriceOracle
},
Boba_GasPriceOracle: {
_owner: cfg.gasPriceOracleOwner,
feeWallet: cfg.l1FeeWalletAddress,
Expand Down Expand Up @@ -152,38 +169,50 @@ export const makeL2GenesisFile = async (
// and returns the address given by that opcode.
dump[predeployAddress].code = '0x4B60005260206000F3'
} else if (predeployName === 'BobaTuringHelper') {
// Add a default BobaTuringHelper for testing purposes
dump[predeployAddress].code = cfg.TuringHelperJson.deployedBytecode

} else if (predeployName === 'L2GovernanceERC20') {
// Fix the address(this) of L2GovernanceERC20
dump[predeployAddress].code = L2GovernanceERC20Helper.L2GovernanceERC20Bytecode
} else if (predeployName === 'Proxy__Boba_GasPriceOracle') {
// Add proxy contract for Boba_GasPriceOracle
const artifact = getContractArtifact('Lib_ResolvedDelegateBobaProxy')
dump[predeployAddress].code = artifact.deployedBytecode
} else {
// Standard case: get the deployed bytecode from the artifact
const artifact = getContractArtifact(predeployName)
dump[predeployAddress].code = artifact.deployedBytecode
}

// Compute and set the required storage slots for each contract that needs it.
if (predeployName in variables) {
if (predeployName === 'BobaTuringHelper') {
// Add a default BobaTuringHelper for testing purposes
const indexOwner = BigNumber.from('0').toHexString();
dump[predeployAddress].storage[utils.hexZeroPad(indexOwner, 32)] = cfg.deployer
const indexAddress = BigNumber.from('1').toHexString();
dump[predeployAddress].storage[utils.hexZeroPad(indexAddress, 32)] = predeploys.BobaTuringHelper
continue
}
if (predeployName === 'Proxy__Boba_GasPriceOracle') {
// Add a proxy contract for Boba_GasPriceOracle
addSlotsForBobaProxyContract(dump, predeployAddress, variables[predeployName])
const storageLayout = await getStorageLayout('Boba_GasPriceOracle')
const slots = computeStorageSlots(storageLayout, variables['Boba_GasPriceOracle'])
for (const slot of slots) {
dump[predeploys.Proxy__Boba_GasPriceOracle].storage[slot.key] = slot.val
}
continue
}
const storageLayout = await getStorageLayout(predeployName)
// Calculate the mapping keys
if (predeployName === 'Lib_ResolvedDelegateBobaProxy') {
for (const keyName of Object.keys(variables[predeployName])) {
const key = utils.hexlify(utils.toUtf8Bytes(keyName));
const index = BigNumber.from('0').toHexString();
const newKeyPreimage = utils.concat([key, utils.hexZeroPad(index, 32)]);
const compositeKey = utils.keccak256(utils.hexlify(newKeyPreimage));
dump[predeployAddress].storage[compositeKey] = variables[predeployName][keyName]
}
addSlotsForBobaProxyContract(dump, predeployAddress, variables[predeployName])
} else {
const slots = computeStorageSlots(storageLayout, variables[predeployName])
for (const slot of slots) {
dump[predeployAddress].storage[slot.key] = slot.val
// Add the storage slots for Proxy__BobaTuringCredit
if (predeployName === "BobaTuringCredit") {
dump[predeploys.Lib_ResolvedDelegateBobaProxy].storage[slot.key] = slot.val
}
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/src/predeploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export const predeploys = {
L2GovernanceERC20: "0x4200000000000000000000000000000000000023",

// Boba gas price oracle
Boba_GasPriceOracle: "0x4200000000000000000000000000000000000024"
Proxy__Boba_GasPriceOracle: "0x4200000000000000000000000000000000000024",
Boba_GasPriceOracle: "0x4200000000000000000000000000000000000025"
}

0 comments on commit e20bc72

Please sign in to comment.