diff --git a/governance/xc_admin/packages/crank_pythnet_relayer/src/index.ts b/governance/xc_admin/packages/crank_pythnet_relayer/src/index.ts index c24bbd17bc..951fd5b4f7 100644 --- a/governance/xc_admin/packages/crank_pythnet_relayer/src/index.ts +++ b/governance/xc_admin/packages/crank_pythnet_relayer/src/index.ts @@ -15,6 +15,7 @@ import { Connection, Keypair, PublicKey, + SystemProgram, TransactionInstruction, } from "@solana/web3.js"; import * as fs from "fs"; @@ -30,6 +31,11 @@ import { mapKey, REMOTE_EXECUTOR_ADDRESS, envOrErr, + PriceStoreMultisigInstruction, + findDetermisticPublisherBufferAddress, + PRICE_STORE_BUFFER_SPACE, + PRICE_STORE_PROGRAM_ID, + createDeterministicPublisherBufferAccountInstruction, } from "@pythnetwork/xc-admin-common"; const CLUSTER: PythCluster = envOrErr("CLUSTER") as PythCluster; @@ -163,6 +169,17 @@ async function run() { } else { throw Error("Product account not found"); } + } else if ( + parsedInstruction instanceof PriceStoreMultisigInstruction && + parsedInstruction.name == "InitializePublisher" + ) { + preInstructions.push( + await createDeterministicPublisherBufferAccountInstruction( + provider.connection, + provider.wallet.publicKey, + parsedInstruction.args.publisherKey + ) + ); } } diff --git a/governance/xc_admin/packages/xc_admin_common/src/executor.ts b/governance/xc_admin/packages/xc_admin_common/src/executor.ts index a634e1d4f2..d6077daac4 100644 --- a/governance/xc_admin/packages/xc_admin_common/src/executor.ts +++ b/governance/xc_admin/packages/xc_admin_common/src/executor.ts @@ -142,27 +142,6 @@ export async function executeProposal( } else { throw Error("Product account not found"); } - } else if ( - parsedInstruction instanceof PriceStoreMultisigInstruction && - parsedInstruction.name == "InitializePublisher" - ) { - const [bufferKey, bufferSeed] = - await findDetermisticPublisherBufferAddress( - parsedInstruction.args.publisherKey - ); - transaction.add( - SystemProgram.createAccountWithSeed({ - fromPubkey: squad.wallet.publicKey, - basePubkey: squad.wallet.publicKey, - newAccountPubkey: bufferKey, - seed: bufferSeed, - space: PRICE_STORE_BUFFER_SPACE, - lamports: await squad.connection.getMinimumBalanceForRentExemption( - PRICE_STORE_BUFFER_SPACE - ), - programId: PRICE_STORE_PROGRAM_ID, - }) - ); } TransactionBuilder.addPriorityFee(transaction, priorityFeeConfig); diff --git a/governance/xc_admin/packages/xc_admin_common/src/price_store.ts b/governance/xc_admin/packages/xc_admin_common/src/price_store.ts index 47aba211bd..9a6448e19d 100644 --- a/governance/xc_admin/packages/xc_admin_common/src/price_store.ts +++ b/governance/xc_admin/packages/xc_admin_common/src/price_store.ts @@ -46,6 +46,9 @@ enum InstructionId { InitializePublisher = 2, } +// Recommended buffer size, enough to hold 5000 prices. +export const PRICE_STORE_BUFFER_SPACE = 100048; + export function findPriceStoreConfigAddress(): [PublicKey, number] { return PublicKey.findProgramAddressSync( [Buffer.from("CONFIG")], @@ -281,6 +284,27 @@ export async function findDetermisticPublisherBufferAddress( return [address, seed]; } +export async function createDeterministicPublisherBufferAccountInstruction( + connection: Connection, + base: PublicKey, + publisher: PublicKey +): Promise { + const [bufferKey, seed] = await findDetermisticPublisherBufferAddress( + publisher + ); + return SystemProgram.createAccountWithSeed({ + fromPubkey: base, + basePubkey: base, + newAccountPubkey: bufferKey, + seed, + space: PRICE_STORE_BUFFER_SPACE, + lamports: await connection.getMinimumBalanceForRentExemption( + PRICE_STORE_BUFFER_SPACE + ), + programId: PRICE_STORE_PROGRAM_ID, + }); +} + export async function createDetermisticPriceStoreInitializePublisherInstruction( authorityKey: PublicKey, publisherKey: PublicKey @@ -307,6 +331,3 @@ export async function isPriceStorePublisherInitialized( const response = await connection.getAccountInfo(publisherConfigKey); return response !== null; } - -// Recommended buffer size, enough to hold 5000 prices. -export const PRICE_STORE_BUFFER_SPACE = 100048;