Skip to content

Commit

Permalink
feat(xc-admin): add support for price store in relayer (#2004)
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati authored Oct 8, 2024
1 parent 803cbc1 commit 04280ea
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
17 changes: 17 additions & 0 deletions governance/xc_admin/packages/crank_pythnet_relayer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Connection,
Keypair,
PublicKey,
SystemProgram,
TransactionInstruction,
} from "@solana/web3.js";
import * as fs from "fs";
Expand All @@ -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;
Expand Down Expand Up @@ -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
)
);
}
}

Expand Down
21 changes: 0 additions & 21 deletions governance/xc_admin/packages/xc_admin_common/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 24 additions & 3 deletions governance/xc_admin/packages/xc_admin_common/src/price_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")],
Expand Down Expand Up @@ -281,6 +284,27 @@ export async function findDetermisticPublisherBufferAddress(
return [address, seed];
}

export async function createDeterministicPublisherBufferAccountInstruction(
connection: Connection,
base: PublicKey,
publisher: PublicKey
): Promise<TransactionInstruction> {
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
Expand All @@ -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;

0 comments on commit 04280ea

Please sign in to comment.