Skip to content

Commit 04280ea

Browse files
authored
feat(xc-admin): add support for price store in relayer (#2004)
1 parent 803cbc1 commit 04280ea

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

governance/xc_admin/packages/crank_pythnet_relayer/src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Connection,
1616
Keypair,
1717
PublicKey,
18+
SystemProgram,
1819
TransactionInstruction,
1920
} from "@solana/web3.js";
2021
import * as fs from "fs";
@@ -30,6 +31,11 @@ import {
3031
mapKey,
3132
REMOTE_EXECUTOR_ADDRESS,
3233
envOrErr,
34+
PriceStoreMultisigInstruction,
35+
findDetermisticPublisherBufferAddress,
36+
PRICE_STORE_BUFFER_SPACE,
37+
PRICE_STORE_PROGRAM_ID,
38+
createDeterministicPublisherBufferAccountInstruction,
3339
} from "@pythnetwork/xc-admin-common";
3440

3541
const CLUSTER: PythCluster = envOrErr("CLUSTER") as PythCluster;
@@ -163,6 +169,17 @@ async function run() {
163169
} else {
164170
throw Error("Product account not found");
165171
}
172+
} else if (
173+
parsedInstruction instanceof PriceStoreMultisigInstruction &&
174+
parsedInstruction.name == "InitializePublisher"
175+
) {
176+
preInstructions.push(
177+
await createDeterministicPublisherBufferAccountInstruction(
178+
provider.connection,
179+
provider.wallet.publicKey,
180+
parsedInstruction.args.publisherKey
181+
)
182+
);
166183
}
167184
}
168185

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,27 +142,6 @@ export async function executeProposal(
142142
} else {
143143
throw Error("Product account not found");
144144
}
145-
} else if (
146-
parsedInstruction instanceof PriceStoreMultisigInstruction &&
147-
parsedInstruction.name == "InitializePublisher"
148-
) {
149-
const [bufferKey, bufferSeed] =
150-
await findDetermisticPublisherBufferAddress(
151-
parsedInstruction.args.publisherKey
152-
);
153-
transaction.add(
154-
SystemProgram.createAccountWithSeed({
155-
fromPubkey: squad.wallet.publicKey,
156-
basePubkey: squad.wallet.publicKey,
157-
newAccountPubkey: bufferKey,
158-
seed: bufferSeed,
159-
space: PRICE_STORE_BUFFER_SPACE,
160-
lamports: await squad.connection.getMinimumBalanceForRentExemption(
161-
PRICE_STORE_BUFFER_SPACE
162-
),
163-
programId: PRICE_STORE_PROGRAM_ID,
164-
})
165-
);
166145
}
167146

168147
TransactionBuilder.addPriorityFee(transaction, priorityFeeConfig);

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ enum InstructionId {
4646
InitializePublisher = 2,
4747
}
4848

49+
// Recommended buffer size, enough to hold 5000 prices.
50+
export const PRICE_STORE_BUFFER_SPACE = 100048;
51+
4952
export function findPriceStoreConfigAddress(): [PublicKey, number] {
5053
return PublicKey.findProgramAddressSync(
5154
[Buffer.from("CONFIG")],
@@ -281,6 +284,27 @@ export async function findDetermisticPublisherBufferAddress(
281284
return [address, seed];
282285
}
283286

287+
export async function createDeterministicPublisherBufferAccountInstruction(
288+
connection: Connection,
289+
base: PublicKey,
290+
publisher: PublicKey
291+
): Promise<TransactionInstruction> {
292+
const [bufferKey, seed] = await findDetermisticPublisherBufferAddress(
293+
publisher
294+
);
295+
return SystemProgram.createAccountWithSeed({
296+
fromPubkey: base,
297+
basePubkey: base,
298+
newAccountPubkey: bufferKey,
299+
seed,
300+
space: PRICE_STORE_BUFFER_SPACE,
301+
lamports: await connection.getMinimumBalanceForRentExemption(
302+
PRICE_STORE_BUFFER_SPACE
303+
),
304+
programId: PRICE_STORE_PROGRAM_ID,
305+
});
306+
}
307+
284308
export async function createDetermisticPriceStoreInitializePublisherInstruction(
285309
authorityKey: PublicKey,
286310
publisherKey: PublicKey
@@ -307,6 +331,3 @@ export async function isPriceStorePublisherInitialized(
307331
const response = await connection.getAccountInfo(publisherConfigKey);
308332
return response !== null;
309333
}
310-
311-
// Recommended buffer size, enough to hold 5000 prices.
312-
export const PRICE_STORE_BUFFER_SPACE = 100048;

0 commit comments

Comments
 (0)