-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeployClient.js
101 lines (83 loc) · 4.13 KB
/
deployClient.js
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
const { types } = require("hardhat/config")
const { VERIFICATION_BLOCK_CONFIRMATIONS, networkConfig } = require("../../network-config")
task("functions-deploy-client", "Deploys the FunctionsConsumer contract")
.addOptionalParam("verify", "Set to true to verify client contract", false, types.boolean)
.setAction(async (taskArgs) => {
if (network.name === "hardhat") {
throw Error(
'This command cannot be used on a local hardhat chain. Specify a valid network or simulate an FunctionsConsumer request locally with "npx hardhat functions-simulate".'
)
}
console.log(`Deploying FunctionsConsumer contract to ${network.name}`)
const oracleAddress = networkConfig[network.name]["functionsOracleProxy"]
console.log("\n__Compiling Contracts__")
await run("compile")
const clientContractFactory = await ethers.getContractFactory("FunctionsConsumer")
const clientContract = await clientContractFactory.deploy(oracleAddress)
console.log(
`\nWaiting ${VERIFICATION_BLOCK_CONFIRMATIONS} blocks for transaction ${clientContract.deployTransaction.hash} to be confirmed...`
)
await clientContract.deployTransaction.wait(VERIFICATION_BLOCK_CONFIRMATIONS)
const verifyContract = taskArgs.verify
if (verifyContract && (process.env.POLYGONSCAN_API_KEY || process.env.ETHERSCAN_API_KEY)) {
try {
console.log("\nVerifying contract...")
await clientContract.deployTransaction.wait(Math.max(6 - VERIFICATION_BLOCK_CONFIRMATIONS, 0))
await run("verify:verify", {
address: clientContract.address,
constructorArguments: [oracleAddress],
})
console.log("Contract verified")
} catch (error) {
if (!error.message.includes("Already Verified")) {
console.log("Error verifying contract. Try delete the ./build folder and try again.")
console.log(error)
} else {
console.log("Contract already verified")
}
}
} else if (verifyContract) {
console.log("\nPOLYGONSCAN_API_KEY or ETHERSCAN_API_KEY missing. Skipping contract verification...")
}
console.log(`\nFunctionsConsumer contract deployed to ${clientContract.address} on ${network.name}`)
})
task("functions-deploy-stork", "Deploys the Stork contract")
.addOptionalParam("verify", "Set to true to verify client contract", false, types.boolean)
.setAction(async (taskArgs) => {
if (network.name === "hardhat") {
throw Error(
'This command cannot be used on a local hardhat chain. Specify a valid network or simulate an FunctionsConsumer request locally with "npx hardhat functions-simulate".'
)
}
console.log(`Deploying Stork contract to ${network.name}`)
const oracleAddress = networkConfig[network.name]["functionsOracleProxy"]
const forwarderAddress = networkConfig[network.name]["forwarder"]
console.log("\n__Compiling Contracts__")
await run("compile")
const clientContractFactory = await ethers.getContractFactory("Stork")
const clientContract = await clientContractFactory.deploy(oracleAddress, forwarderAddress)
console.log(
`\nWaiting ${VERIFICATION_BLOCK_CONFIRMATIONS} blocks for transaction ${clientContract.deployTransaction.hash} to be confirmed...`
)
await clientContract.deployTransaction.wait(VERIFICATION_BLOCK_CONFIRMATIONS)
const verifyContract = taskArgs.verify
if (verifyContract) {
try {
console.log("\nVerifying contract...")
await clientContract.deployTransaction.wait(Math.max(6 - VERIFICATION_BLOCK_CONFIRMATIONS, 0))
await run("verify:verify", {
address: clientContract.address,
constructorArguments: [oracleAddress, forwarderAddress],
})
console.log("Contract verified")
} catch (error) {
if (!error.message.includes("Already Verified")) {
console.log("Error verifying contract. Try delete the ./build folder and try again.")
console.log(error)
} else {
console.log("Contract already verified")
}
}
}
console.log(`\Stork contract deployed to ${clientContract.address} on ${network.name}`)
})