Skip to content

Commit 6fe551c

Browse files
authored
Add remote to general tab (#572)
1 parent 881bf76 commit 6fe551c

File tree

1 file changed

+40
-53
lines changed
  • governance/xc_admin/packages/xc_admin_frontend/components/tabs

1 file changed

+40
-53
lines changed

governance/xc_admin/packages/xc_admin_frontend/components/tabs/General.tsx

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { getPythProgramKeyForCluster } from '@pythnetwork/client'
33
import { PythOracle, pythOracleProgram } from '@pythnetwork/client/lib/anchor'
44
import { useAnchorWallet, useWallet } from '@solana/wallet-adapter-react'
55
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'
77
import { useCallback, useContext, useEffect, useState } from 'react'
88
import toast from 'react-hot-toast'
99
import {
1010
getMultisigCluster,
11+
isRemoteCluster,
12+
mapKey,
1113
OPS_KEY,
1214
proposeInstructions,
15+
WORMHOLE_ADDRESS,
1316
} from 'xc_admin_common'
1417
import { ClusterContext } from '../../contexts/ClusterContext'
1518
import { usePythContext } from '../../contexts/PythContext'
@@ -28,6 +31,10 @@ const General = () => {
2831
const [isSendProposalButtonLoading, setIsSendProposalButtonLoading] =
2932
useState(false)
3033
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+
3138
const anchorWallet = useAnchorWallet()
3239
const { isLoading: isMultisigLoading, squads } = useMultisig(
3340
anchorWallet as Wallet
@@ -237,9 +244,16 @@ const General = () => {
237244
}
238245

239246
const handleSendProposalButtonClick = async () => {
240-
if (pythProgramClient && dataChanges) {
247+
if (pythProgramClient && dataChanges && !isMultisigLoading && squads) {
241248
const instructions: TransactionInstruction[] = []
242249
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
243257
const { prev, new: newChanges } = dataChanges[symbol]
244258
// if prev is undefined, it means that the symbol is new
245259
if (!prev) {
@@ -254,10 +268,7 @@ const General = () => {
254268
await pythProgramClient.methods
255269
.addProduct()
256270
.accounts({
257-
fundingAccount: squads?.getAuthorityPDA(
258-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
259-
1
260-
),
271+
fundingAccount,
261272
tailMappingAccount: rawConfig.mappingAccounts[0].address,
262273
productAccount: productAccountKey,
263274
})
@@ -268,10 +279,7 @@ const General = () => {
268279
await pythProgramClient.methods
269280
.updProduct({ ...newChanges.metadata, symbol: symbol })
270281
.accounts({
271-
fundingAccount: squads?.getAuthorityPDA(
272-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
273-
1
274-
),
282+
fundingAccount,
275283
productAccount: productAccountKey,
276284
})
277285
.instruction()
@@ -287,10 +295,7 @@ const General = () => {
287295
await pythProgramClient.methods
288296
.addPrice(newChanges.priceAccounts[0].expo, 1)
289297
.accounts({
290-
fundingAccount: squads?.getAuthorityPDA(
291-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
292-
1
293-
),
298+
fundingAccount,
294299
productAccount: productAccountKey,
295300
priceAccount: priceAccountKey,
296301
})
@@ -304,10 +309,7 @@ const General = () => {
304309
pythProgramClient.methods
305310
.addPublisher(new PublicKey(publisherKey))
306311
.accounts({
307-
fundingAccount: squads?.getAuthorityPDA(
308-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
309-
1
310-
),
312+
fundingAccount,
311313
priceAccount: priceAccountKey,
312314
})
313315
.instruction()
@@ -323,10 +325,7 @@ const General = () => {
323325
.setMinPub(newChanges.priceAccounts[0].minPub, [0, 0, 0])
324326
.accounts({
325327
priceAccount: priceAccountKey,
326-
fundingAccount: squads?.getAuthorityPDA(
327-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
328-
1
329-
),
328+
fundingAccount,
330329
})
331330
.instruction()
332331
)
@@ -342,10 +341,7 @@ const General = () => {
342341
await pythProgramClient.methods
343342
.updProduct({ ...newChanges.metadata, symbol: symbol })
344343
.accounts({
345-
fundingAccount: squads?.getAuthorityPDA(
346-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
347-
1
348-
),
344+
fundingAccount,
349345
productAccount: new PublicKey(prev.address),
350346
})
351347
.instruction()
@@ -361,10 +357,7 @@ const General = () => {
361357
.setMinPub(newChanges.priceAccounts[0].minPub, [0, 0, 0])
362358
.accounts({
363359
priceAccount: new PublicKey(prev.priceAccounts[0].address),
364-
fundingAccount: squads?.getAuthorityPDA(
365-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
366-
1
367-
),
360+
fundingAccount,
368361
})
369362
.instruction()
370363
)
@@ -387,10 +380,7 @@ const General = () => {
387380
pythProgramClient.methods
388381
.addPublisher(new PublicKey(publisherKey))
389382
.accounts({
390-
fundingAccount: squads?.getAuthorityPDA(
391-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
392-
1
393-
),
383+
fundingAccount,
394384
priceAccount: new PublicKey(prev.priceAccounts[0].address),
395385
})
396386
.instruction()
@@ -401,32 +391,29 @@ const General = () => {
401391
pythProgramClient.methods
402392
.delPublisher(new PublicKey(publisherKey))
403393
.accounts({
404-
fundingAccount: squads?.getAuthorityPDA(
405-
SECURITY_MULTISIG[getMultisigCluster(cluster)],
406-
1
407-
),
394+
fundingAccount,
408395
priceAccount: new PublicKey(prev.priceAccounts[0].address),
409396
})
410397
.instruction()
411398
.then((instruction) => instructions.push(instruction))
412399
})
413400
}
414401
})
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)
430417
}
431418
}
432419
}

0 commit comments

Comments
 (0)