Skip to content

Commit 76c8255

Browse files
authored
fix(governance/xc_admin): init publishers for price store only when n… (#2149)
* fix(governance/xc_admin): init publishers for price store only when needed * fix: address feedback
1 parent 4556454 commit 76c8255

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

governance/xc_admin/packages/xc_admin_common/src/price_store.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,11 @@ export async function isPriceStorePublisherInitialized(
331331
const response = await connection.getAccountInfo(publisherConfigKey);
332332
return response !== null;
333333
}
334+
335+
export async function isPriceStoreInitialized(
336+
connection: Connection
337+
): Promise<boolean> {
338+
const configKey = findPriceStoreConfigAddress()[0];
339+
const response = await connection.getAccountInfo(configKey);
340+
return response !== null;
341+
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
PRICE_FEED_OPS_KEY,
2222
getMessageBufferAddressForPrice,
2323
getMaximumNumberOfPublishers,
24+
isPriceStoreInitialized,
2425
isPriceStorePublisherInitialized,
2526
createDetermisticPriceStoreInitializePublisherInstruction,
2627
} from '@pythnetwork/xc-admin-common'
@@ -290,7 +291,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
290291
const handleSendProposalButtonClick = async () => {
291292
if (pythProgramClient && dataChanges && !isMultisigLoading && squads) {
292293
const instructions: TransactionInstruction[] = []
293-
const publisherInitializationsVerified: PublicKey[] = []
294+
const publisherInPriceStoreInitializationsVerified: PublicKey[] = []
294295

295296
for (const symbol of Object.keys(dataChanges)) {
296297
const multisigAuthority = squads.getAuthorityPDA(
@@ -301,9 +302,14 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
301302
? mapKey(multisigAuthority)
302303
: multisigAuthority
303304

304-
const initPublisher = async (publisherKey: PublicKey) => {
305+
const initPublisherInPriceStore = async (publisherKey: PublicKey) => {
306+
// Ignore this step if Price Store is not initialized (or not deployed)
307+
if (!connection || !(await isPriceStoreInitialized(connection))) {
308+
return
309+
}
310+
305311
if (
306-
publisherInitializationsVerified.every(
312+
publisherInPriceStoreInitializationsVerified.every(
307313
(el) => !el.equals(publisherKey)
308314
)
309315
) {
@@ -321,7 +327,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
321327
)
322328
)
323329
}
324-
publisherInitializationsVerified.push(publisherKey)
330+
publisherInPriceStoreInitializationsVerified.push(publisherKey)
325331
}
326332
}
327333
const { prev, new: newChanges } = dataChanges[symbol]
@@ -406,7 +412,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
406412
})
407413
.instruction()
408414
)
409-
await initPublisher(publisherPubKey)
415+
await initPublisherInPriceStore(publisherPubKey)
410416
}
411417

412418
// create set min publisher instruction if there are any publishers
@@ -576,7 +582,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
576582
})
577583
.instruction()
578584
)
579-
await initPublisher(publisherPubKey)
585+
await initPublisherInPriceStore(publisherPubKey)
580586
}
581587
}
582588
}

0 commit comments

Comments
 (0)