@@ -3,13 +3,16 @@ import { getPythProgramKeyForCluster } from '@pythnetwork/client'
3
3
import { PythOracle , pythOracleProgram } from '@pythnetwork/client/lib/anchor'
4
4
import { useAnchorWallet , useWallet } from '@solana/wallet-adapter-react'
5
5
import { WalletModalButton } from '@solana/wallet-adapter-react-ui'
6
- import { PublicKey , TransactionInstruction } from '@solana/web3.js'
6
+ import { Cluster , PublicKey , TransactionInstruction } from '@solana/web3.js'
7
7
import { useCallback , useContext , useEffect , useState } from 'react'
8
8
import toast from 'react-hot-toast'
9
9
import {
10
10
getMultisigCluster ,
11
+ isRemoteCluster ,
12
+ mapKey ,
11
13
OPS_KEY ,
12
14
proposeInstructions ,
15
+ WORMHOLE_ADDRESS ,
13
16
} from 'xc_admin_common'
14
17
import { ClusterContext } from '../../contexts/ClusterContext'
15
18
import { usePythContext } from '../../contexts/PythContext'
@@ -28,6 +31,10 @@ const General = () => {
28
31
const [ isSendProposalButtonLoading , setIsSendProposalButtonLoading ] =
29
32
useState ( false )
30
33
const { cluster } = useContext ( ClusterContext )
34
+ const isRemote : boolean = isRemoteCluster ( cluster ) // Move to multisig context
35
+ const multisigCluster : Cluster | 'localnet' = getMultisigCluster ( cluster ) // Move to multisig context
36
+ const wormholeAddress = WORMHOLE_ADDRESS [ multisigCluster ] // Move to multisig context
37
+
31
38
const anchorWallet = useAnchorWallet ( )
32
39
const { isLoading : isMultisigLoading , squads } = useMultisig (
33
40
anchorWallet as Wallet
@@ -237,9 +244,16 @@ const General = () => {
237
244
}
238
245
239
246
const handleSendProposalButtonClick = async ( ) => {
240
- if ( pythProgramClient && dataChanges ) {
247
+ if ( pythProgramClient && dataChanges && ! isMultisigLoading && squads ) {
241
248
const instructions : TransactionInstruction [ ] = [ ]
242
249
Object . keys ( dataChanges ) . forEach ( async ( symbol ) => {
250
+ const multisigAuthority = squads . getAuthorityPDA (
251
+ SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
252
+ 1
253
+ )
254
+ const fundingAccount = isRemote
255
+ ? mapKey ( multisigAuthority )
256
+ : multisigAuthority
243
257
const { prev, new : newChanges } = dataChanges [ symbol ]
244
258
// if prev is undefined, it means that the symbol is new
245
259
if ( ! prev ) {
@@ -254,10 +268,7 @@ const General = () => {
254
268
await pythProgramClient . methods
255
269
. addProduct ( )
256
270
. accounts ( {
257
- fundingAccount : squads ?. getAuthorityPDA (
258
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
259
- 1
260
- ) ,
271
+ fundingAccount,
261
272
tailMappingAccount : rawConfig . mappingAccounts [ 0 ] . address ,
262
273
productAccount : productAccountKey ,
263
274
} )
@@ -268,10 +279,7 @@ const General = () => {
268
279
await pythProgramClient . methods
269
280
. updProduct ( { ...newChanges . metadata , symbol : symbol } )
270
281
. accounts ( {
271
- fundingAccount : squads ?. getAuthorityPDA (
272
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
273
- 1
274
- ) ,
282
+ fundingAccount,
275
283
productAccount : productAccountKey ,
276
284
} )
277
285
. instruction ( )
@@ -287,10 +295,7 @@ const General = () => {
287
295
await pythProgramClient . methods
288
296
. addPrice ( newChanges . priceAccounts [ 0 ] . expo , 1 )
289
297
. accounts ( {
290
- fundingAccount : squads ?. getAuthorityPDA (
291
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
292
- 1
293
- ) ,
298
+ fundingAccount,
294
299
productAccount : productAccountKey ,
295
300
priceAccount : priceAccountKey ,
296
301
} )
@@ -304,10 +309,7 @@ const General = () => {
304
309
pythProgramClient . methods
305
310
. addPublisher ( new PublicKey ( publisherKey ) )
306
311
. accounts ( {
307
- fundingAccount : squads ?. getAuthorityPDA (
308
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
309
- 1
310
- ) ,
312
+ fundingAccount,
311
313
priceAccount : priceAccountKey ,
312
314
} )
313
315
. instruction ( )
@@ -323,10 +325,7 @@ const General = () => {
323
325
. setMinPub ( newChanges . priceAccounts [ 0 ] . minPub , [ 0 , 0 , 0 ] )
324
326
. accounts ( {
325
327
priceAccount : priceAccountKey ,
326
- fundingAccount : squads ?. getAuthorityPDA (
327
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
328
- 1
329
- ) ,
328
+ fundingAccount,
330
329
} )
331
330
. instruction ( )
332
331
)
@@ -342,10 +341,7 @@ const General = () => {
342
341
await pythProgramClient . methods
343
342
. updProduct ( { ...newChanges . metadata , symbol : symbol } )
344
343
. accounts ( {
345
- fundingAccount : squads ?. getAuthorityPDA (
346
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
347
- 1
348
- ) ,
344
+ fundingAccount,
349
345
productAccount : new PublicKey ( prev . address ) ,
350
346
} )
351
347
. instruction ( )
@@ -361,10 +357,7 @@ const General = () => {
361
357
. setMinPub ( newChanges . priceAccounts [ 0 ] . minPub , [ 0 , 0 , 0 ] )
362
358
. accounts ( {
363
359
priceAccount : new PublicKey ( prev . priceAccounts [ 0 ] . address ) ,
364
- fundingAccount : squads ?. getAuthorityPDA (
365
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
366
- 1
367
- ) ,
360
+ fundingAccount,
368
361
} )
369
362
. instruction ( )
370
363
)
@@ -387,10 +380,7 @@ const General = () => {
387
380
pythProgramClient . methods
388
381
. addPublisher ( new PublicKey ( publisherKey ) )
389
382
. accounts ( {
390
- fundingAccount : squads ?. getAuthorityPDA (
391
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
392
- 1
393
- ) ,
383
+ fundingAccount,
394
384
priceAccount : new PublicKey ( prev . priceAccounts [ 0 ] . address ) ,
395
385
} )
396
386
. instruction ( )
@@ -401,32 +391,29 @@ const General = () => {
401
391
pythProgramClient . methods
402
392
. delPublisher ( new PublicKey ( publisherKey ) )
403
393
. accounts ( {
404
- fundingAccount : squads ?. getAuthorityPDA (
405
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
406
- 1
407
- ) ,
394
+ fundingAccount,
408
395
priceAccount : new PublicKey ( prev . priceAccounts [ 0 ] . address ) ,
409
396
} )
410
397
. instruction ( )
411
398
. then ( ( instruction ) => instructions . push ( instruction ) )
412
399
} )
413
400
}
414
401
} )
415
- if ( ! isMultisigLoading && squads ) {
416
- setIsSendProposalButtonLoading ( true )
417
- try {
418
- const proposalPubkey = await proposeInstructions (
419
- squads ,
420
- SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
421
- instructions ,
422
- false
423
- )
424
- toast . success ( `Proposal sent! 🚀 Proposal Pubkey: ${ proposalPubkey } ` )
425
- setIsSendProposalButtonLoading ( false )
426
- } catch ( e : any ) {
427
- toast . error ( capitalizeFirstLetter ( e . message ) )
428
- setIsSendProposalButtonLoading ( false )
429
- }
402
+
403
+ setIsSendProposalButtonLoading ( true )
404
+ try {
405
+ const proposalPubkey = await proposeInstructions (
406
+ squads ,
407
+ SECURITY_MULTISIG [ getMultisigCluster ( cluster ) ] ,
408
+ instructions ,
409
+ isRemote ,
410
+ wormholeAddress
411
+ )
412
+ toast . success ( `Proposal sent! 🚀 Proposal Pubkey: ${ proposalPubkey } ` )
413
+ setIsSendProposalButtonLoading ( false )
414
+ } catch ( e : any ) {
415
+ toast . error ( capitalizeFirstLetter ( e . message ) )
416
+ setIsSendProposalButtonLoading ( false )
430
417
}
431
418
}
432
419
}
0 commit comments