1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* 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) => {
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}`)
})