Repository navigation
Expand file tree
/
Copy pathdeploy.ts
More file actions
57 lines (46 loc) · 1.84 KB
/
Copy pathdeploy.ts
File metadata and controls
57 lines (46 loc) · 1.84 KB
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
import { promises as fs } from 'fs'
import { task } from 'hardhat/config'
import addressBook from '../addresses.json'
type AddressBook = Record<string, Record<string, { address: string }>>
const addresses: AddressBook = addressBook
enum Contract {
DataEdge,
EventfulDataEdge,
}
enum DeployName {
EBODataEdge = 'EBO',
SAODataEdge = 'SAO',
REODataEdge = 'REO',
}
task('data-edge:deploy', 'Deploy a DataEdge contract')
.addParam('contract', 'Chose DataEdge or EventfulDataEdge')
.addParam('deployName', 'Chose EBO, SAO or REO')
.setAction(async (taskArgs, hre) => {
if (!Object.values(Contract).includes(taskArgs.contract)) {
throw new Error(`Contract ${taskArgs.contract} not supported`)
}
if (!Object.values(DeployName).includes(taskArgs.deployName)) {
throw new Error(`Deploy name ${taskArgs.deployName} not supported`)
}
const factory = await hre.ethers.getContractFactory(taskArgs.contract)
console.log(`Deploying contract...`)
const contract = await factory.deploy()
const tx = contract.deploymentTransaction()!
const contractAddress = await contract.getAddress()
const [signer] = await hre.ethers.getSigners()
console.log(`> deployer: ${await signer.getAddress()}`)
console.log(`> contract: ${contractAddress}`)
console.log(
`> tx: ${tx.hash} nonce:${tx.nonce} limit: ${tx.gasLimit.toString()} gas: ${Number(tx.gasPrice) / 1e9} (gwei)`,
)
await contract.waitForDeployment()
console.log(`Done!`)
// Update addresses.json
const chainId = hre.network.config.chainId!.toString()
if (!addresses[chainId]) {
addresses[chainId] = {}
}
const deployName = `${taskArgs.deployName}${taskArgs.contract}`
addresses[chainId][deployName] = { address: contractAddress }
return fs.writeFile('addresses.json', JSON.stringify(addresses, null, 2) + '\n')
})