Commit 4736eb2e authored by Karl Floersch's avatar Karl Floersch Committed by Mark Tyneway

feat: set gpo task

Creates a task that can set the owner of any contract that is `Ownable`.
It defaults to attempting to set the address of the `OVM_GasPriceOracle`
on L2. The following config options must be set:

- `CONTRACTS_RPC_URL`
- `CONTRACTS_DEPLOYER_KEY`

It can be invoked like so:

```
$ npx hardhat set-owner --owner 0x..
```

On L2 networks that do not enforce transaction fees, the
`--transaction-gas-price 0` config option may be used for
convenience.

This script also supports Ledger with the `--use-ledger` flag.
It defaults to deriving a key at the `ethers.utils.defaultPath`.
parent cbd4e854
---
'@eth-optimism/contracts': patch
---
Add a task for setting the gas price oracle
......@@ -15,6 +15,7 @@ import '@typechain/hardhat'
import '@eth-optimism/hardhat-ovm'
import './tasks/deploy'
import './tasks/l2-gasprice'
import './tasks/set-owner'
import 'hardhat-gas-reporter'
// Load environment variables from .env
......
......@@ -53,6 +53,7 @@
"@ethersproject/abstract-provider": "^5.0.8",
"@ethersproject/abstract-signer": "^5.1.0",
"@ethersproject/contracts": "^5.0.5",
"@ethersproject/hardware-wallets": "^5.4.0",
"glob": "^7.1.6"
},
"devDependencies": {
......@@ -76,19 +77,19 @@
"@types/yargs": "^16.0.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-eslint": "^10.1.0",
"buffer-xor": "^2.0.2",
"chai": "^4.3.1",
"copyfiles": "^2.3.0",
"directory-tree": "^2.2.7",
"dotenv": "^8.2.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.27.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ban": "^1.5.2",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-unicorn": "^32.0.1",
"ethereum-waffle": "^3.3.0",
......@@ -97,21 +98,21 @@
"hardhat": "^2.2.1",
"hardhat-deploy": "^0.7.4",
"hardhat-gas-reporter": "^1.0.4",
"lint-staged": "11.0.0",
"lodash": "^4.17.20",
"merkle-patricia-tree": "^4.0.0",
"merkletreejs": "^0.2.12",
"mkdirp": "^1.0.4",
"mocha": "^8.3.0",
"prettier": "^2.2.1",
"lint-staged": "11.0.0",
"random-bytes-seed": "^1.0.3",
"rlp": "^2.2.6",
"solhint": "^3.3.6",
"solidity-coverage": "^0.7.16",
"ts-generator": "0.0.8",
"ts-node": "^9.1.1",
"typescript": "^4.2.3",
"typechain": "2.0.0",
"typescript": "^4.2.3",
"yargs": "^16.2.0"
},
"peerDependencies": {
......
/* Imports: External */
import { ethers } from 'ethers'
import { LedgerSigner } from '@ethersproject/hardware-wallets'
import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes'
import { predeploys } from '../src/predeploys'
import { getContractFactory } from '../src/contract-defs'
task('set-owner')
.addParam('owner', 'the new oracle address', 0, types.string)
.addOptionalParam('transactionGasPrice', 'tx.gasPrice', undefined, types.int)
.addOptionalParam(
'useLedger',
'use a ledger for signing',
false,
types.boolean
)
.addOptionalParam(
'ledgerPath',
'ledger key derivation path',
ethers.utils.defaultPath,
types.string
)
.addOptionalParam(
'contractsRpcUrl',
'Sequencer HTTP Endpoint',
process.env.CONTRACTS_RPC_URL,
types.string
)
.addOptionalParam(
'contractsDeployerKey',
'Private Key',
process.env.CONTRACTS_DEPLOYER_KEY,
types.string
)
.addOptionalParam(
'contractAddress',
'Address of Ownable contract',
predeploys.OVM_GasPriceOracle,
types.string
)
.setAction(async (args, hre: any, runSuper) => {
const provider = new ethers.providers.JsonRpcProvider(args.contractsRpcUrl)
let signer: ethers.Signer
if (!args.useLedger) {
signer = new ethers.Wallet(args.contractsDeployerKey).connect(provider)
} else {
signer = new LedgerSigner(provider, 'default', args.ledgerPath)
}
const Ownable = getContractFactory('Ownable')
.attach(args.contractAddress)
.connect(provider)
const addr = await signer.getAddress()
console.log(`Using signer ${addr}`)
const owner = await Ownable.callStatic.owner()
if (owner !== addr) {
throw new Error(`Incorrect key. Owner ${owner}, Signer ${addr}`)
}
console.log(`Owner is currently ${owner.toString()}`)
console.log(`Setting owner to ${args.owner}`)
const tx = await Ownable.connect(signer).transferOwnership(
args.owner,
{ gasPrice: args.transactionGasPrice }
)
const receipt = await tx.wait()
console.log(`Success - ${receipt.transactionHash}`)
})
......@@ -753,7 +753,7 @@
"@ethersproject/properties" "^5.4.0"
"@ethersproject/transactions" "^5.4.0"
"@ethersproject/hardware-wallets@^5.0.8":
"@ethersproject/hardware-wallets@^5.0.8", "@ethersproject/hardware-wallets@^5.4.0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@ethersproject/hardware-wallets/-/hardware-wallets-5.4.0.tgz#bce275b395e26b6f50481095331157614490a473"
integrity sha512-Ea4ymm4etZoSWy93OcEGZkuVqyYdl/RjMlaXY6yQIYjsGi75sm4apbTiBA8DA9uajkv1FVakJZEBBTaVGgnBLA==
......
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