Commit 5818decb authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

contracts: gas oracle script (#2425)

Create a simple script that can set the
config for the  `OVM_GasPriceOracle` using `cast`.
Using the `hardhat` task requires 4gb+
of memory when running.

Also remove the `set-l2-gasprice` hardhat
task that does the same functionality
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 83ce16a0
---
'@eth-optimism/contracts': patch
---
Remove l2 gas price hardhat task
#!/bin/sh
set -e
RPC_URL=${RPC_URL:-http://localhost:8545}
OVM_GAS_ORACLE=0x420000000000000000000000000000000000000F
function send_tx() {
cast send --rpc-url $RPC_URL \
--private-key $PRIVATE_KEY \
--legacy \
--gas-price 0 \
$OVM_GAS_ORACLE \
$1 \
$2
}
function call() {
cast call --rpc-url $RPC_URL \
$OVM_GAS_ORACLE \
$1
}
echo "Scalar: $(call 'scalar()(uint256)')"
echo "L2 gas price: $(call 'gasPrice()(uint256)')"
echo "Overhead: $(call 'overhead()(uint256)')"
if [[ ! -z $PRIVATE_KEY ]]; then
if [[ ! -z $SCALAR ]]; then
echo "Setting scalar to $SCALAR"
send_tx 'setScalar(uint256)' $SCALAR
fi
if [[ ! -z $OVERHEAD ]]; then
echo "Setting overhead to $OVERHEAD"
send_tx 'setOverhead(uint256)' $OVERHEAD
fi
if [[ ! -z $L2_GAS_PRICE ]]; then
echo "Setting L2 gas price to $L2_GAS_PRICE"
send_tx 'setGasPrice(uint256)' $L2_GAS_PRICE
fi
fi
export * from './l2-gasprice'
export * from './set-owner' export * from './set-owner'
export * from './take-dump' export * from './take-dump'
export * from './validate-address-dictator' export * from './validate-address-dictator'
......
/* Imports: External */
import { ethers } from 'ethers'
import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes'
import { predeploys } from '../src/predeploys'
import { getContractDefinition } from '../src/contract-defs'
task('set-l2-gasprice')
.addOptionalParam(
'l2GasPrice',
'Gas Price to set on L2',
undefined,
types.int
)
.addOptionalParam('transactionGasPrice', 'tx.gasPrice', undefined, types.int)
.addOptionalParam(
'overhead',
'amortized additional gas used by each batch that users must pay for',
undefined,
types.int
)
.addOptionalParam(
'scalar',
'amount to scale up the gas to charge',
undefined,
types.int
)
.addOptionalParam(
'contractsRpcUrl',
'Sequencer HTTP Endpoint',
process.env.CONTRACTS_RPC_URL,
types.string
)
.addOptionalParam(
'contractsDeployerKey',
'Private Key',
process.env.CONTRACTS_DEPLOYER_KEY,
types.string
)
.setAction(async (args) => {
const provider = new ethers.providers.JsonRpcProvider(args.contractsRpcUrl)
const signer = new ethers.Wallet(args.contractsDeployerKey).connect(
provider
)
const GasPriceOracleArtifact = getContractDefinition('OVM_GasPriceOracle')
const GasPriceOracle = new ethers.Contract(
predeploys.OVM_GasPriceOracle,
GasPriceOracleArtifact.abi,
signer
)
const addr = await signer.getAddress()
console.log(`Using signer ${addr}`)
const owner = await GasPriceOracle.callStatic.owner()
if (owner !== addr) {
throw new Error(`Incorrect key. Owner ${owner}, Signer ${addr}`)
}
// List the current values
const gasPrice = await GasPriceOracle.callStatic.gasPrice()
const scalar = await GasPriceOracle.callStatic.scalar()
const overhead = await GasPriceOracle.callStatic.overhead()
console.log('Current values:')
console.log(`Gas Price: ${gasPrice.toString()}`)
console.log(`Scalar: ${scalar.toString()}`)
console.log(`Overhead: ${overhead.toString()}`)
if (args.l2GasPrice !== undefined) {
console.log(`Setting gas price to ${args.l2GasPrice}`)
const tx = await GasPriceOracle.connect(signer).setGasPrice(
args.l2GasPrice,
{ gasPrice: args.transactionGasPrice }
)
const receipt = await tx.wait()
console.log(`Success - ${receipt.transactionHash}`)
}
if (args.scalar !== undefined) {
console.log(`Setting scalar to ${args.scalar}`)
const tx = await GasPriceOracle.connect(signer).setScalar(args.scalar, {
gasPrice: args.transactionGasPrice,
})
const receipt = await tx.wait()
console.log(`Success - ${receipt.transactionHash}`)
}
if (args.overhead !== undefined) {
console.log(`Setting overhead to ${args.overhead}`)
const tx = await GasPriceOracle.connect(signer).setOverhead(
args.overhead,
{ gasPrice: args.transactionGasPrice }
)
const receipt = await tx.wait()
console.log(`Success - ${receipt.transactionHash}`)
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment