@@ -11,7 +11,8 @@ import {
11
11
Keypair ,
12
12
LAMPORTS_PER_SOL ,
13
13
PublicKey ,
14
- SystemProgram , TransactionInstruction ,
14
+ SystemProgram ,
15
+ TransactionInstruction ,
15
16
} from "@solana/web3.js" ;
16
17
import Squads from "@sqds/mesh" ;
17
18
import bs58 from "bs58" ;
@@ -47,7 +48,13 @@ program
47
48
)
48
49
. option ( "-p, --payload <hex-string>" , "payload to sign" , "0xdeadbeef" )
49
50
. action ( async ( options ) => {
50
- const squad = await getSquadsClient ( options . cluster , options . ledger , options . ledgerDerivationAccount , options . ledgerDerivationChange , options . wallet ) ;
51
+ const squad = await getSquadsClient (
52
+ options . cluster ,
53
+ options . ledger ,
54
+ options . ledgerDerivationAccount ,
55
+ options . ledgerDerivationChange ,
56
+ options . wallet
57
+ ) ;
51
58
await createWormholeMsgMultisigTx (
52
59
options . cluster ,
53
60
squad ,
@@ -59,7 +66,9 @@ program
59
66
60
67
program
61
68
. command ( "set-is-active" )
62
- . description ( "Create a new multisig transaction to set the attester is-active flag" )
69
+ . description (
70
+ "Create a new multisig transaction to set the attester is-active flag"
71
+ )
63
72
. option ( "-c, --cluster <network>" , "solana cluster to use" , "devnet" )
64
73
. requiredOption ( "-v, --vault-address <address>" , "multisig vault address" )
65
74
. option ( "-l, --ledger" , "use ledger" )
@@ -77,17 +86,38 @@ program
77
86
"keys/key.json"
78
87
)
79
88
. option ( "-a, --attester <program id>" )
80
- . option ( "-i, --is-active <true/false>" , "set the isActive field to this value" , true )
89
+ . option (
90
+ "-i, --is-active <true/false>" ,
91
+ "set the isActive field to this value" ,
92
+ true
93
+ )
81
94
. action ( async ( options ) => {
82
- const squad = await getSquadsClient ( options . cluster , options . ledger , options . ledgerDerivationAccount , options . ledgerDerivationChange , options . wallet ) ;
95
+ const squad = await getSquadsClient (
96
+ options . cluster ,
97
+ options . ledger ,
98
+ options . ledgerDerivationAccount ,
99
+ options . ledgerDerivationChange ,
100
+ options . wallet
101
+ ) ;
83
102
const msAccount = await squad . getMultisig ( options . vaultAddress ) ;
84
103
const vaultAuthority = squad . getAuthorityPDA (
85
104
msAccount . publicKey ,
86
105
msAccount . authorityIndex
87
106
) ;
88
107
const attesterProgramId = new PublicKey ( options . attester ) ;
89
- const txKey = await createTx ( squad , options . ledger , new PublicKey ( options . vaultAddress ) ) ;
90
- const instructions = [ await setIsActiveIx ( vaultAuthority , vaultAuthority , attesterProgramId , options . active ) ] ;
108
+ const txKey = await createTx (
109
+ squad ,
110
+ options . ledger ,
111
+ new PublicKey ( options . vaultAddress )
112
+ ) ;
113
+ const instructions = [
114
+ await setIsActiveIx (
115
+ vaultAuthority ,
116
+ vaultAuthority ,
117
+ attesterProgramId ,
118
+ options . active
119
+ ) ,
120
+ ] ;
91
121
await addInstructionsToTx ( squad , options . ledger , txKey , instructions ) ;
92
122
} ) ;
93
123
@@ -146,11 +176,12 @@ const solanaClusterMappingToWormholeNetwork: Record<Cluster, WormholeNetwork> =
146
176
"mainnet-beta" : "MAINNET" ,
147
177
} ;
148
178
149
- async function getSquadsClient ( cluster : Cluster ,
150
- ledger : boolean ,
151
- ledgerDerivationAccount : number | undefined ,
152
- ledgerDerivationChange : number | undefined ,
153
- walletPath : string ,
179
+ async function getSquadsClient (
180
+ cluster : Cluster ,
181
+ ledger : boolean ,
182
+ ledgerDerivationAccount : number | undefined ,
183
+ ledgerDerivationChange : number | undefined ,
184
+ walletPath : string
154
185
) {
155
186
let wallet : LedgerNodeWallet | NodeWallet ;
156
187
if ( ledger ) {
@@ -176,7 +207,7 @@ async function getSquadsClient(cluster: Cluster,
176
207
async function createTx (
177
208
squad : Squads ,
178
209
ledger : boolean ,
179
- vault : PublicKey ,
210
+ vault : PublicKey
180
211
) : Promise < PublicKey > {
181
212
const msAccount = await squad . getMultisig ( vault ) ;
182
213
@@ -201,7 +232,9 @@ async function addInstructionsToTx(
201
232
instructions : TransactionInstruction [ ]
202
233
) {
203
234
for ( let i = 0 ; i < instructions . length ; i ++ ) {
204
- console . log ( `Adding instruction ${ i } /${ instructions . length } to transaction...` ) ;
235
+ console . log (
236
+ `Adding instruction ${ i } /${ instructions . length } to transaction...`
237
+ ) ;
205
238
if ( ledger ) {
206
239
console . log ( "Please approve the transaction on your ledger device..." ) ;
207
240
}
@@ -221,33 +254,36 @@ async function setIsActiveIx(
221
254
attesterProgramId : PublicKey ,
222
255
isActive : boolean
223
256
) : Promise < TransactionInstruction > {
224
- const configKey = PublicKey . createProgramAddressSync ( [ Buffer . from ( "pyth2wormhole-config-v3" ) ] , attesterProgramId )
257
+ const configKey = PublicKey . createProgramAddressSync (
258
+ [ Buffer . from ( "pyth2wormhole-config-v3" ) ] ,
259
+ attesterProgramId
260
+ ) ;
225
261
const config : AccountMeta = {
226
262
pubkey : configKey ,
227
263
isSigner : false ,
228
264
isWritable : true ,
229
- }
265
+ } ;
230
266
231
267
const opsOwner : AccountMeta = {
232
268
pubkey : opsOwnerKey ,
233
269
isSigner : true ,
234
270
isWritable : true ,
235
- }
271
+ } ;
236
272
const payer : AccountMeta = {
237
273
pubkey : payerKey ,
238
274
isSigner : true ,
239
275
isWritable : true ,
240
- }
276
+ } ;
241
277
242
- const isActiveInt = ( isActive === true ) ? 1 : 0 ;
278
+ const isActiveInt = isActive === true ? 1 : 0 ;
243
279
// first byte is the isActive instruction, second byte is true/false
244
- const data = new Buffer ( [ 4 , isActiveInt ] )
280
+ const data = new Buffer ( [ 4 , isActiveInt ] ) ;
245
281
246
282
return {
247
283
keys : [ config , opsOwner , payer ] ,
248
284
programId : attesterProgramId ,
249
285
data : data ,
250
- }
286
+ } ;
251
287
}
252
288
253
289
async function getWormholeMessageIx (
@@ -286,7 +322,7 @@ async function getWormholeMessageIx(
286
322
emitter . toBase58 ( ) ,
287
323
message . toBase58 ( ) ,
288
324
0 ,
289
- Uint8Array . from ( Buffer . from ( payload , ' hex' ) ) ,
325
+ Uint8Array . from ( Buffer . from ( payload , " hex" ) ) ,
290
326
"CONFIRMED"
291
327
)
292
328
) ,
@@ -312,9 +348,12 @@ async function createWormholeMsgMultisigTx(
312
348
313
349
const message = Keypair . generate ( ) ;
314
350
315
- fs . mkdirSync ( ' keys' , { recursive : true } ) ;
351
+ fs . mkdirSync ( " keys" , { recursive : true } ) ;
316
352
// save message to Uint8 array keypair file called mesage.json
317
- fs . writeFileSync ( `keys/message-${ txKey . toBase58 ( ) } .json` , `[${ message . secretKey . toString ( ) } ]` ) ;
353
+ fs . writeFileSync (
354
+ `keys/message-${ txKey . toBase58 ( ) } .json` ,
355
+ `[${ message . secretKey . toString ( ) } ]`
356
+ ) ;
318
357
console . log ( `Message Address: ${ message . publicKey . toBase58 ( ) } ` ) ;
319
358
320
359
console . log ( "Creating wormhole instructions..." ) ;
@@ -431,7 +470,6 @@ async function executeMultisigTx(
431
470
) ;
432
471
await new Promise ( ( resolve ) => setTimeout ( resolve , 10000 ) ) ;
433
472
434
-
435
473
const txDetails = await squad . connection . getParsedTransaction (
436
474
signature ,
437
475
"confirmed"
@@ -460,10 +498,10 @@ async function executeMultisigTx(
460
498
const { vaaBytes } = await response . json ( ) ;
461
499
console . log ( `VAA (Base64): ${ vaaBytes } ` ) ;
462
500
const parsedVaa = await parse ( vaaBytes ) ;
463
- console . log ( `VAA (Hex): ${ Buffer . from ( vaaBytes ) . toString ( ' hex' ) } ` )
501
+ console . log ( `VAA (Hex): ${ Buffer . from ( vaaBytes ) . toString ( " hex" ) } ` ) ;
464
502
console . log ( `Emitter chain: ${ parsedVaa . emitter_chain } ` ) ;
465
503
console . log ( `Nonce: ${ parsedVaa . nonce } ` ) ;
466
- console . log ( `Payload: ${ Buffer . from ( parsedVaa . payload ) . toString ( ' hex' ) } ` ) ;
504
+ console . log ( `Payload: ${ Buffer . from ( parsedVaa . payload ) . toString ( " hex" ) } ` ) ;
467
505
}
468
506
469
507
async function parse ( data : string ) {
0 commit comments