Price account v2 for remote clusters (#1040)

This commit is contained in:
guibescos 2023-09-04 14:37:19 +01:00 committed by GitHub
parent 0559b45936
commit cfdfb9d2fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import {
TransactionInstruction,
} from "@solana/web3.js";
import { PRICE_FEED_OPS_KEY } from "./multisig";
import { isRemoteCluster } from "./cluster";
/**
* Get seed for deterministic creation of a price/product account
@ -33,10 +34,17 @@ function getSeed(accountType: AccountType, symbol: string): string {
* @param accountType Type of the account
* @returns
*/
function getAccountTypeSize(accountType: AccountType): number {
function getAccountTypeSize(
accountType: AccountType,
cluster: PythCluster
): number {
switch (accountType) {
case AccountType.Price:
return 3312;
if (isRemoteCluster(cluster)) {
return 12576;
} else {
return 3312;
}
case AccountType.Product:
return 512;
default:
@ -88,9 +96,9 @@ export async function getCreateAccountWithSeedInstruction(
basePubkey: base,
newAccountPubkey: address,
seed: seed,
space: getAccountTypeSize(accountType),
space: getAccountTypeSize(accountType, cluster),
lamports: await connection.getMinimumBalanceForRentExemption(
getAccountTypeSize(accountType)
getAccountTypeSize(accountType, cluster)
),
programId: getPythProgramKeyForCluster(cluster),
});