-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathexecuteGovernanceVaa.ts
More file actions
88 lines (70 loc) · 2 KB
/
Copy pathexecuteGovernanceVaa.ts
File metadata and controls
88 lines (70 loc) · 2 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
import { inspect } from "util";
import { ChainId } from "@certusone/wormhole-sdk";
import {
loadOperatingChains,
init,
ChainInfo,
getChainConfig,
getSigner,
getContractAddress,
} from "./env";
import { Governance__factory } from "../contract-bindings";
const processName = "executeGovernanceVaas";
type GovernanceConfig = {
chainId: ChainId;
vaa: string;
};
init();
const chains = loadOperatingChains();
async function run() {
console.log(`Start ${processName}!`);
const results = await Promise.all(
chains.map(async (chain) => {
let result;
try {
result = await executeGovernance(chain);
} catch (error: unknown) {
return { chainId: chain.chainId, peerUpdateTxs: [] as string[], error };
}
return result;
})
);
for (const result of results) {
if (!result) {
continue;
}
if ("error" in result) {
console.error(
`${processName} failed for chain ${result.chainId}: ${inspect(result.error)}`
);
continue;
}
console.log(`${processName} succeeded for chain ${result.chainId}`);
}
}
async function executeGovernance(chain: ChainInfo) {
const log = (...args: any[]) => console.log(`[${chain.chainId}]`, ...args);
const { vaa } = await getChainConfig<GovernanceConfig>(
"governance-vaas",
chain.chainId
);
const governanceContract = await getGovernanceContract(chain);
const vaaHex = Buffer.from(vaa, "base64").toString("hex");
log("Executing governance with VAA: ", vaaHex);
const tx = await governanceContract.performGovernance(
`0x${vaaHex}`,
{} // overrides
);
log(`Submitted governance transaction: ${tx.hash}`);
await tx.wait();
log("success.");
}
run().then(() => console.log("Done!"));
async function getGovernanceContract(chain: ChainInfo) {
const signer = await getSigner(chain);
const governanceAddress = await getContractAddress(
"GeneralPurposeGovernances",
chain.chainId
);
return Governance__factory.connect(governanceAddress, signer);
}