Skip to content

Commit

Permalink
Refactor constants
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Feb 28, 2024
1 parent 0068d5f commit dcdd39f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import {
parsePriceFeedMessage,
} from "@pythnetwork/price-service-sdk";
import {
DEFAULT_REDUCED_GUARDIAN_SET_SIZE,
DEFAULT_TREASURY_ID,
POST_UPDATE_ATOMIC_COMPUTE_BUDGET,
POST_UPDATE_COMPUTE_BUDGET,
VERIFY_ENCODED_VAA_COMPUTE_BUDGET,
} from "./constants";
} from "./compute_budget";
import { Wallet } from "@coral-xyz/anchor/dist/cjs/provider";
import {
buildEncodedVaaCreateInstruction,
Expand All @@ -40,6 +38,8 @@ import {
} from "@pythnetwork/solana-utils";
import { priorityFeeConfig as PriorityFeeConfig } from "@pythnetwork/solana-utils/lib/transaction";

export const DEFAULT_TREASURY_ID = 0;

export class PythSolanaReceiver {
readonly connection: Connection;
readonly wallet: Wallet;
Expand Down Expand Up @@ -140,10 +140,7 @@ export class PythSolanaReceiver {
Buffer.from(priceUpdateData, "base64")
);
const guardianSetIndex = getGuardianSetIndex(accumulatorUpdateData.vaa);
const trimmedVaa = trimSignatures(
accumulatorUpdateData.vaa,
DEFAULT_REDUCED_GUARDIAN_SET_SIZE
);
const trimmedVaa = trimSignatures(accumulatorUpdateData.vaa);

for (const update of accumulatorUpdateData.updates) {
const priceUpdateKeypair = new Keypair();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export const DEFAULT_TREASURY_ID = 0;
export const DEFAULT_REDUCED_GUARDIAN_SET_SIZE = 5;

export const VERIFY_ENCODED_VAA_COMPUTE_BUDGET = 400000;
export const POST_UPDATE_ATOMIC_COMPUTE_BUDGET = 400000;
export const POST_UPDATE_COMPUTE_BUDGET = 200000;
6 changes: 5 additions & 1 deletion target_chains/solana/sdk/js/pyth_solana_receiver/src/vaa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import { InstructionWithEphemeralSigners } from "@pythnetwork/solana-utils";
export const VAA_START = 46;
export const VAA_SIGNATURE_SIZE = 66;
export const VAA_SPLIT_INDEX = 792;
export const DEFAULT_REDUCED_GUARDIAN_SET_SIZE = 5;

export function getGuardianSetIndex(vaa: Buffer) {
return vaa.readUInt32BE(1);
}

export function trimSignatures(vaa: Buffer, n: number): Buffer {
export function trimSignatures(
vaa: Buffer,
n = DEFAULT_REDUCED_GUARDIAN_SET_SIZE
): Buffer {
const currentNumSignatures = vaa[5];
if (n > currentNumSignatures) {
throw new Error(
Expand Down

0 comments on commit dcdd39f

Please sign in to comment.