-
Notifications
You must be signed in to change notification settings - Fork 2
/
hardhat.config.ts
164 lines (152 loc) · 3.77 KB
/
hardhat.config.ts
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import "@nomicfoundation/hardhat-toolbox"
import "@nomicfoundation/hardhat-chai-matchers";
import "hardhat-deploy"
import "hardhat-spdx-license-identifier"
import "hardhat-abi-exporter"
import "@nomiclabs/hardhat-etherscan"
import dotenv from "dotenv"
import { Deployment } from 'hardhat-deploy/types';
import { HardhatUserConfig, task } from "hardhat/config"
dotenv.config()
const config: HardhatUserConfig = {
abiExporter: {
path: "./abi",
clear: false,
flat: true,
runOnCompile: true,
except: ['ERC20.sol', 'IMetaSwap.sol']
},
paths: {
artifacts: "artifacts",
cache: "cache",
deploy: "deploy",
deployments: "deployments",
imports: "imports",
sources: "contracts",
tests: "test",
},
typechain: {
outDir: "types",
target: "ethers-v5",
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY
},
networks: {
hardhat: {
allowUnlimitedContractSize: false,
},
astar: {
url: 'https://astar.api.onfinality.io/public',
chainId: 592,
deploy: ['./deploy/astar/']
},
arbitrum: {
url: 'https://arb1.arbitrum.io/rpc',
chainId: 42161,
deploy: ['./deploy/arbitrum/'],
verify: {
etherscan: {
apiUrl: 'https://api.arbiscan.io/api',
}
}
},
moonbase: {
url: 'https://rpc.testnet.moonbeam.network',
chainId: 1287,
deploy: ['./deploy/moonbase/'],
verify: {
etherscan: {
apiUrl: 'https://api-moonbase.moonscan.io',
}
}
}
},
solidity: {
compilers: [
{
version: '0.8.7',
settings: {
optimizer: { enabled: true, runs: 200 }
},
}
],
},
namedAccounts: {
deployer: {
default: 0,
592: 0,
1287: 0,
42161: 0
},
libraryDeployer: {
default: 1,
592: 1,
1287: 1,
42161: 1
}
}
};
if (process.env.ACCOUNT_PRIVATE_KEYS) {
config.networks = {
...config.networks,
moonbase: {
...config.networks?.moonbase,
accounts: JSON.parse(process.env.ACCOUNT_PRIVATE_KEYS)
},
astar: {
...config.networks?.astar,
accounts: JSON.parse(process.env.ACCOUNT_PRIVATE_KEYS)
},
arbitrum: {
...config.networks?.arbitrum,
accounts: JSON.parse(process.env.ACCOUNT_PRIVATE_KEYS)
}
}
}
// Override the default deploy task
task("deploy", async (taskArgs, hre, runSuper) => {
const { all } = hre.deployments
/*
* Pre-deployment actions
*/
// Load exiting deployments
const existingDeployments: { [p: string]: Deployment } = await all()
// Create hard copy of existing deployment name to address mapping
const existingDeploymentToAddressMap: { [p: string]: string } = Object.keys(
existingDeployments,
).reduce((acc: { [p: string]: string }, key) => {
acc[key] = existingDeployments[key].address
return acc
}, {})
/*
* Run super task
*/
await runSuper(taskArgs)
/*
* Post-deployment actions
*/
const updatedDeployments: { [p: string]: Deployment } = await all()
// Filter out any existing deployments that have not changed
const newDeployments: { [p: string]: Deployment } = Object.keys(
updatedDeployments,
).reduce((acc: { [p: string]: Deployment }, key) => {
if (
!existingDeploymentToAddressMap.hasOwnProperty(key) ||
existingDeploymentToAddressMap[key] !== updatedDeployments[key].address
) {
acc[key] = updatedDeployments[key]
}
return acc
}, {})
// Print the new deployments to the console
if (Object.keys(newDeployments).length > 0) {
console.log("\nNew deployments:")
console.table(
Object.keys(newDeployments).map((k) => [k, newDeployments[k].address]),
)
} else {
console.warn("\nNo new deployments found")
}
})
export default config;