From 9a59d09f9f5796c3702bad845727c2feb57031e0 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Tue, 5 Apr 2022 12:35:23 -0700 Subject: [PATCH] contracts: gas oracle script 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 --- .changeset/smart-foxes-shop.md | 5 + packages/contracts/scripts/ovm-gas-oracle.sh | 44 ++++++++ packages/contracts/tasks/index.ts | 1 - packages/contracts/tasks/l2-gasprice.ts | 103 ------------------- 4 files changed, 49 insertions(+), 104 deletions(-) create mode 100644 .changeset/smart-foxes-shop.md create mode 100755 packages/contracts/scripts/ovm-gas-oracle.sh delete mode 100644 packages/contracts/tasks/l2-gasprice.ts diff --git a/.changeset/smart-foxes-shop.md b/.changeset/smart-foxes-shop.md new file mode 100644 index 0000000000000..ee231362eeccd --- /dev/null +++ b/.changeset/smart-foxes-shop.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/contracts': patch +--- + +Remove l2 gas price hardhat task diff --git a/packages/contracts/scripts/ovm-gas-oracle.sh b/packages/contracts/scripts/ovm-gas-oracle.sh new file mode 100755 index 0000000000000..f6bc0b456783b --- /dev/null +++ b/packages/contracts/scripts/ovm-gas-oracle.sh @@ -0,0 +1,44 @@ +#!/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 + diff --git a/packages/contracts/tasks/index.ts b/packages/contracts/tasks/index.ts index 491be3a4ee2c1..b834161307639 100644 --- a/packages/contracts/tasks/index.ts +++ b/packages/contracts/tasks/index.ts @@ -1,4 +1,3 @@ -export * from './l2-gasprice' export * from './set-owner' export * from './take-dump' export * from './validate-address-dictator' diff --git a/packages/contracts/tasks/l2-gasprice.ts b/packages/contracts/tasks/l2-gasprice.ts deleted file mode 100644 index d6df98222ce9d..0000000000000 --- a/packages/contracts/tasks/l2-gasprice.ts +++ /dev/null @@ -1,103 +0,0 @@ -/* 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}`) - } - })