-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddVerifier.ts
More file actions
96 lines (85 loc) · 2.67 KB
/
addVerifier.ts
File metadata and controls
96 lines (85 loc) · 2.67 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
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
import { SocketVerifier__factory } from "../typechain";
import { routeIdConfigs, VerifierName } from "./config";
import { confirm } from "./utils";
import { ethers } from "hardhat";
const hre = require("hardhat");
const fs = require("fs");
const path = require("path");
export const addVerifier = async () => {
try {
const { network } = hre;
const networkName = network.name;
const [deployer] = await ethers.getSigners();
const networkFilePath = path.join(
__dirname,
`../deployments/${networkName}.json`
);
// check if the contract is already deployed in deployments folder in json
let deployment_json = undefined;
deployment_json = fs.readFileSync(networkFilePath, "utf-8");
const deployment = JSON.parse(deployment_json);
const SocketVerifierAddress = deployment?.SocketVerifier;
if (!SocketVerifierAddress) {
throw new Error("SocketVerifier not deployed");
}
const contract = SocketVerifier__factory.connect(
SocketVerifierAddress,
deployer
);
// check owner
const owner = await contract.owner();
if (owner !== deployer.address) {
throw new Error("Owner is not deployer");
}
// config
// const VerifierName: VerifierName = "AcrossV3Verification";
// const VerifierName = "CCTPVerification";
const VerifierName = "GnosisBridgeRouterVerification";
const verifierAddress = deployment[VerifierName];
if (!verifierAddress) {
throw new Error(`${VerifierName} not deployed`);
}
// @note change before running
const routeId = routeIdConfigs[networkName][VerifierName];
if (!routeId) {
throw new Error("Route ID is not configured");
}
// check if the verifier is already added
const currentVerifierAddress = await contract.routeIdsToVerifiers(routeId);
if (
currentVerifierAddress.toLowerCase() === verifierAddress.toLowerCase()
) {
throw new Error("Verifier is already added");
}
console.log({
routeId,
networkName,
VerifierName,
verifierAddress,
SocketVerifierAddress,
});
await confirm("Are you sure to add this verifier? (y/n)");
console.log("🔌 Adding verifier");
const tx = await contract.addVerifier(routeId, verifierAddress);
const receipt = await tx.wait();
console.log("✅ Verifier added");
return {
success: true,
receipt,
};
} catch (error) {
console.log(`❌ Error in adding verifier`, error);
return {
success: false,
};
}
};
addVerifier()
.then(() => {
console.log(`✅ finished running the add verifier`);
process.exit(0);
})
.catch((err) => {
console.error(err);
process.exit(1);
});