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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { task } from 'hardhat/config'
import * as types from 'hardhat/internal/core/params/argumentTypes'
import { LedgerSigner } from '@ethersproject/hardware-wallets'
task('deploy-receiver')
.addParam('creator', 'Creator address', undefined, types.string)
.addParam('owner', 'Owner address', undefined, types.string)
.setAction(async (args, hre) => {
console.log(`connecting to ledger...`)
const signer = new LedgerSigner(
hre.ethers.provider,
'default',
hre.ethers.utils.defaultPath
)
const addr = await signer.getAddress()
if (args.creator !== addr) {
throw new Error(`Incorrect key. Creator ${args.creator}, Signer ${addr}`)
}
const singleton = new hre.ethers.Contract(
'0xce0042B868300000d44A59004Da54A005ffdcf9f',
[
{
constant: false,
inputs: [
{
internalType: 'bytes',
name: '_initCode',
type: 'bytes',
},
{
internalType: 'bytes32',
name: '_salt',
type: 'bytes32',
},
],
name: 'deploy',
outputs: [
{
internalType: 'address payable',
name: 'createdContract',
type: 'address',
},
],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
],
signer
)
const salt =
'0x0000000000000000000000000000000000000000000000000000000000000001'
const code = hre.ethers.utils.hexConcat([
hre.artifacts.readArtifactSync('RetroReceiver').bytecode,
hre.ethers.utils.defaultAbiCoder.encode(['address'], [addr]),
])
// Predict and connect to the contract address
const receiver = await hre.ethers.getContractAt(
'RetroReceiver',
await singleton.callStatic.deploy(code, salt, {
gasLimit: 2_000_000,
}),
signer
)
console.log(`creating contract: ${receiver.address}...`)
const tx1 = await singleton.deploy(code, salt, {
gasLimit: 2_000_000,
})
console.log(`waiting for tx: ${tx1.hash}...`)
await tx1.wait()
console.log(`transferring ownership to: ${args.owner}...`)
const tx2 = await receiver.setOwner(args.owner)
console.log(`waiting for tx: ${tx2.hash}...`)
await tx2.wait()
console.log(`verifying contract: ${receiver.address}...`)
await hre.run('verify:verify', {
address: receiver.address,
constructorArguments: [addr],
})
console.log(`all done`)
})