Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xc-admin): add support for price store in relayer #2004

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading