@@ -2,6 +2,7 @@ import yargs from "yargs";
2
2
import { hideBin } from "yargs/helpers" ;
3
3
import { DefaultStore , loadHotWallet , toPrivateKey } from "../src" ;
4
4
import { readFileSync } from "fs" ;
5
+ import { PythCluster } from "@pythnetwork/client/lib/cluster" ;
5
6
6
7
import {
7
8
COMMON_UPGRADE_OPTIONS ,
@@ -27,6 +28,18 @@ const parser = yargs(hideBin(process.argv))
27
28
} ,
28
29
} ) ;
29
30
31
+ // Override these URLs to use a different RPC node for mainnet / testnet.
32
+ // TODO: extract these RPCs to a config file (?)
33
+ const RPCS = {
34
+ "mainnet-beta" : "https://api.mainnet-beta.solana.com" ,
35
+ testnet : "https://api.testnet.solana.com" ,
36
+ devnet : "https://api.devnet.solana.com" ,
37
+ } as Record < PythCluster , string > ;
38
+
39
+ function registry ( cluster : PythCluster ) : string {
40
+ return RPCS [ cluster ] ;
41
+ }
42
+
30
43
async function main ( ) {
31
44
const argv = await parser . argv ;
32
45
const cacheFile =
@@ -45,40 +58,56 @@ async function main() {
45
58
46
59
console . log ( "Using cache file" , cacheFile ) ;
47
60
61
+ // Try to deploy on every chain, then collect any failures at the end. This logic makes it simpler to
62
+ // identify deployment problems (e.g., not enough gas) on every chain where they occur.
48
63
const payloads : Buffer [ ] = [ ] ;
64
+ const failures : string [ ] = [ ] ;
49
65
for ( const contract of Object . values ( DefaultStore . entropy_contracts ) ) {
50
66
if ( selectedChains . includes ( contract . chain ) ) {
51
67
const artifact = JSON . parse ( readFileSync ( argv [ "std-output" ] , "utf8" ) ) ;
52
68
console . log ( "Deploying contract to" , contract . chain . getId ( ) ) ;
53
- const address = await runIfNotCached (
54
- `deploy-${ contract . chain . getId ( ) } ` ,
55
- ( ) => {
56
- return contract . chain . deploy (
57
- toPrivateKey ( argv [ "private-key" ] ) ,
58
- artifact [ "abi" ] ,
59
- artifact [ "bytecode" ] ,
60
- [ ] ,
61
- 2
62
- ) ;
63
- }
64
- ) ;
65
- console . log (
66
- `Deployed contract at ${ address } on ${ contract . chain . getId ( ) } `
67
- ) ;
68
- const payload =
69
- argv [ "contract-type" ] === "executor"
70
- ? await contract . generateUpgradeExecutorContractsPayload ( address )
71
- : await contract . generateUpgradeEntropyContractPayload ( address ) ;
69
+ try {
70
+ const address = await runIfNotCached (
71
+ `deploy-${ contract . chain . getId ( ) } ` ,
72
+ ( ) => {
73
+ return contract . chain . deploy (
74
+ toPrivateKey ( argv [ "private-key" ] ) ,
75
+ artifact [ "abi" ] ,
76
+ artifact [ "bytecode" ] ,
77
+ [ ] ,
78
+ 2
79
+ ) ;
80
+ }
81
+ ) ;
82
+ console . log (
83
+ `Deployed contract at ${ address } on ${ contract . chain . getId ( ) } `
84
+ ) ;
85
+ const payload =
86
+ argv [ "contract-type" ] === "executor"
87
+ ? await contract . generateUpgradeExecutorContractsPayload ( address )
88
+ : await contract . generateUpgradeEntropyContractPayload ( address ) ;
72
89
73
- console . log ( payload . toString ( "hex" ) ) ;
74
- payloads . push ( payload ) ;
90
+ console . log ( payload . toString ( "hex" ) ) ;
91
+ payloads . push ( payload ) ;
92
+ } catch ( e ) {
93
+ console . log ( `error deploying: ${ e } ` ) ;
94
+ failures . push ( contract . chain . getId ( ) ) ;
95
+ }
75
96
}
76
97
}
77
98
99
+ if ( failures . length > 0 ) {
100
+ throw new Error (
101
+ `Some chains could not be deployed: ${ failures . join (
102
+ ", "
103
+ ) } . Scroll up to see the errors from each chain.`
104
+ ) ;
105
+ }
106
+
78
107
console . log ( "Using vault at for proposal" , vault . getId ( ) ) ;
79
108
const wallet = await loadHotWallet ( argv [ "ops-key-path" ] ) ;
80
109
console . log ( "Using wallet " , wallet . publicKey . toBase58 ( ) ) ;
81
- await vault . connect ( wallet ) ;
110
+ vault . connect ( wallet , registry ) ;
82
111
const proposal = await vault . proposeWormholeMessage ( payloads ) ;
83
112
console . log ( "Proposal address" , proposal . address . toBase58 ( ) ) ;
84
113
}
0 commit comments