Преглед изворни кода

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

Ali Behjati пре 1 година
родитељ
комит
04280eae68

+ 17 - 0
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
+              )
+            );
           }
         }
 

+ 0 - 21
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);

+ 24 - 3
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<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
@@ -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;