|
|
@@ -2,6 +2,7 @@ import yargs from "yargs";
|
|
|
import { hideBin } from "yargs/helpers";
|
|
|
import { DefaultStore, loadHotWallet, toPrivateKey } from "../src";
|
|
|
import { readFileSync } from "fs";
|
|
|
+import { PythCluster } from "@pythnetwork/client/lib/cluster";
|
|
|
|
|
|
import {
|
|
|
COMMON_UPGRADE_OPTIONS,
|
|
|
@@ -27,6 +28,18 @@ const parser = yargs(hideBin(process.argv))
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+// Override these URLs to use a different RPC node for mainnet / testnet.
|
|
|
+// TODO: extract these RPCs to a config file (?)
|
|
|
+const RPCS = {
|
|
|
+ "mainnet-beta": "https://api.mainnet-beta.solana.com",
|
|
|
+ testnet: "https://api.testnet.solana.com",
|
|
|
+ devnet: "https://api.devnet.solana.com",
|
|
|
+} as Record<PythCluster, string>;
|
|
|
+
|
|
|
+function registry(cluster: PythCluster): string {
|
|
|
+ return RPCS[cluster];
|
|
|
+}
|
|
|
+
|
|
|
async function main() {
|
|
|
const argv = await parser.argv;
|
|
|
const cacheFile =
|
|
|
@@ -45,40 +58,56 @@ async function main() {
|
|
|
|
|
|
console.log("Using cache file", cacheFile);
|
|
|
|
|
|
+ // Try to deploy on every chain, then collect any failures at the end. This logic makes it simpler to
|
|
|
+ // identify deployment problems (e.g., not enough gas) on every chain where they occur.
|
|
|
const payloads: Buffer[] = [];
|
|
|
+ const failures: string[] = [];
|
|
|
for (const contract of Object.values(DefaultStore.entropy_contracts)) {
|
|
|
if (selectedChains.includes(contract.chain)) {
|
|
|
const artifact = JSON.parse(readFileSync(argv["std-output"], "utf8"));
|
|
|
console.log("Deploying contract to", contract.chain.getId());
|
|
|
- const address = await runIfNotCached(
|
|
|
- `deploy-${contract.chain.getId()}`,
|
|
|
- () => {
|
|
|
- return contract.chain.deploy(
|
|
|
- toPrivateKey(argv["private-key"]),
|
|
|
- artifact["abi"],
|
|
|
- artifact["bytecode"],
|
|
|
- [],
|
|
|
- 2
|
|
|
- );
|
|
|
- }
|
|
|
- );
|
|
|
- console.log(
|
|
|
- `Deployed contract at ${address} on ${contract.chain.getId()}`
|
|
|
- );
|
|
|
- const payload =
|
|
|
- argv["contract-type"] === "executor"
|
|
|
- ? await contract.generateUpgradeExecutorContractsPayload(address)
|
|
|
- : await contract.generateUpgradeEntropyContractPayload(address);
|
|
|
+ try {
|
|
|
+ const address = await runIfNotCached(
|
|
|
+ `deploy-${contract.chain.getId()}`,
|
|
|
+ () => {
|
|
|
+ return contract.chain.deploy(
|
|
|
+ toPrivateKey(argv["private-key"]),
|
|
|
+ artifact["abi"],
|
|
|
+ artifact["bytecode"],
|
|
|
+ [],
|
|
|
+ 2
|
|
|
+ );
|
|
|
+ }
|
|
|
+ );
|
|
|
+ console.log(
|
|
|
+ `Deployed contract at ${address} on ${contract.chain.getId()}`
|
|
|
+ );
|
|
|
+ const payload =
|
|
|
+ argv["contract-type"] === "executor"
|
|
|
+ ? await contract.generateUpgradeExecutorContractsPayload(address)
|
|
|
+ : await contract.generateUpgradeEntropyContractPayload(address);
|
|
|
|
|
|
- console.log(payload.toString("hex"));
|
|
|
- payloads.push(payload);
|
|
|
+ console.log(payload.toString("hex"));
|
|
|
+ payloads.push(payload);
|
|
|
+ } catch (e) {
|
|
|
+ console.log(`error deploying: ${e}`);
|
|
|
+ failures.push(contract.chain.getId());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (failures.length > 0) {
|
|
|
+ throw new Error(
|
|
|
+ `Some chains could not be deployed: ${failures.join(
|
|
|
+ ", "
|
|
|
+ )}. Scroll up to see the errors from each chain.`
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
console.log("Using vault at for proposal", vault.getId());
|
|
|
const wallet = await loadHotWallet(argv["ops-key-path"]);
|
|
|
console.log("Using wallet ", wallet.publicKey.toBase58());
|
|
|
- await vault.connect(wallet);
|
|
|
+ vault.connect(wallet, registry);
|
|
|
const proposal = await vault.proposeWormholeMessage(payloads);
|
|
|
console.log("Proposal address", proposal.address.toBase58());
|
|
|
}
|