Skip to content

Commit

Permalink
fix(governance/xc_admin): init publishers for price store only when n… (
Browse files Browse the repository at this point in the history
#2149)

* fix(governance/xc_admin): init publishers for price store only when needed

* fix: address feedback
  • Loading branch information
ali-bahjati authored Nov 27, 2024
1 parent 4556454 commit 76c8255
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,11 @@ export async function isPriceStorePublisherInitialized(
const response = await connection.getAccountInfo(publisherConfigKey);
return response !== null;
}

export async function isPriceStoreInitialized(
connection: Connection
): Promise<boolean> {
const configKey = findPriceStoreConfigAddress()[0];
const response = await connection.getAccountInfo(configKey);
return response !== null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
PRICE_FEED_OPS_KEY,
getMessageBufferAddressForPrice,
getMaximumNumberOfPublishers,
isPriceStoreInitialized,
isPriceStorePublisherInitialized,
createDetermisticPriceStoreInitializePublisherInstruction,
} from '@pythnetwork/xc-admin-common'
Expand Down Expand Up @@ -290,7 +291,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
const handleSendProposalButtonClick = async () => {
if (pythProgramClient && dataChanges && !isMultisigLoading && squads) {
const instructions: TransactionInstruction[] = []
const publisherInitializationsVerified: PublicKey[] = []
const publisherInPriceStoreInitializationsVerified: PublicKey[] = []

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

const initPublisher = async (publisherKey: PublicKey) => {
const initPublisherInPriceStore = async (publisherKey: PublicKey) => {
// Ignore this step if Price Store is not initialized (or not deployed)
if (!connection || !(await isPriceStoreInitialized(connection))) {
return
}

if (
publisherInitializationsVerified.every(
publisherInPriceStoreInitializationsVerified.every(
(el) => !el.equals(publisherKey)
)
) {
Expand All @@ -321,7 +327,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
)
)
}
publisherInitializationsVerified.push(publisherKey)
publisherInPriceStoreInitializationsVerified.push(publisherKey)
}
}
const { prev, new: newChanges } = dataChanges[symbol]
Expand Down Expand Up @@ -406,7 +412,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
})
.instruction()
)
await initPublisher(publisherPubKey)
await initPublisherInPriceStore(publisherPubKey)
}

// create set min publisher instruction if there are any publishers
Expand Down Expand Up @@ -576,7 +582,7 @@ const General = ({ proposerServerUrl }: { proposerServerUrl: string }) => {
})
.instruction()
)
await initPublisher(publisherPubKey)
await initPublisherInPriceStore(publisherPubKey)
}
}
}
Expand Down

0 comments on commit 76c8255

Please sign in to comment.