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