/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type Codec, type Decoder, type Encoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from "@solana/kit"; import { SCOPE_PROGRAM_ADDRESS } from "../programs"; import { getAccountMetaFactory, type ResolvedAccount } from "../shared"; export const REFRESH_CHAINLINK_PRICE_DISCRIMINATOR = new Uint8Array([ 97, 9, 20, 115, 72, 255, 4, 140, ]); export function getRefreshChainlinkPriceDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( REFRESH_CHAINLINK_PRICE_DISCRIMINATOR, ); } export type RefreshChainlinkPriceInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountUser extends string | AccountMeta = string, TAccountOraclePrices extends string | AccountMeta = string, TAccountOracleMappings extends string | AccountMeta = string, TAccountOracleTwaps extends string | AccountMeta = string, TAccountVerifierAccount extends string | AccountMeta = string, TAccountAccessController extends string | AccountMeta = string, TAccountConfigAccount extends string | AccountMeta = string, TAccountVerifierProgramId extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountUser extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountUser, TAccountOraclePrices extends string ? WritableAccount : TAccountOraclePrices, TAccountOracleMappings extends string ? ReadonlyAccount : TAccountOracleMappings, TAccountOracleTwaps extends string ? WritableAccount : TAccountOracleTwaps, TAccountVerifierAccount extends string ? ReadonlyAccount : TAccountVerifierAccount, TAccountAccessController extends string ? ReadonlyAccount : TAccountAccessController, TAccountConfigAccount extends string ? ReadonlyAccount : TAccountConfigAccount, TAccountVerifierProgramId extends string ? ReadonlyAccount : TAccountVerifierProgramId, ...TRemainingAccounts, ] >; export type RefreshChainlinkPriceInstructionData = { discriminator: ReadonlyUint8Array; token: number; serializedChainlinkReport: ReadonlyUint8Array; }; export type RefreshChainlinkPriceInstructionDataArgs = { token: number; serializedChainlinkReport: ReadonlyUint8Array; }; export function getRefreshChainlinkPriceInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], ["token", getU16Encoder()], [ "serializedChainlinkReport", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder()), ], ]), (value) => ({ ...value, discriminator: REFRESH_CHAINLINK_PRICE_DISCRIMINATOR, }), ); } export function getRefreshChainlinkPriceInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["token", getU16Decoder()], [ "serializedChainlinkReport", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder()), ], ]); } export function getRefreshChainlinkPriceInstructionDataCodec(): Codec< RefreshChainlinkPriceInstructionDataArgs, RefreshChainlinkPriceInstructionData > { return combineCodec( getRefreshChainlinkPriceInstructionDataEncoder(), getRefreshChainlinkPriceInstructionDataDecoder(), ); } export type RefreshChainlinkPriceInput< TAccountUser extends string = string, TAccountOraclePrices extends string = string, TAccountOracleMappings extends string = string, TAccountOracleTwaps extends string = string, TAccountVerifierAccount extends string = string, TAccountAccessController extends string = string, TAccountConfigAccount extends string = string, TAccountVerifierProgramId extends string = string, > = { /** The account that signs the transaction. */ user: TransactionSigner; oraclePrices: Address; oracleMappings: Address; oracleTwaps: Address; /** * The Verifier Account stores the DON's public keys and other verification parameters. * This account must match the PDA derived from the verifier program. */ verifierAccount: Address; /** The Access Controller Account */ accessController: Address; /** The Config Account is a PDA derived from a signed report */ configAccount: Address; /** The Verifier Program ID specifies the target Chainlink Data Streams Verifier Program. */ verifierProgramId: Address; token: RefreshChainlinkPriceInstructionDataArgs["token"]; serializedChainlinkReport: RefreshChainlinkPriceInstructionDataArgs["serializedChainlinkReport"]; }; export function getRefreshChainlinkPriceInstruction< TAccountUser extends string, TAccountOraclePrices extends string, TAccountOracleMappings extends string, TAccountOracleTwaps extends string, TAccountVerifierAccount extends string, TAccountAccessController extends string, TAccountConfigAccount extends string, TAccountVerifierProgramId extends string, TProgramAddress extends Address = typeof SCOPE_PROGRAM_ADDRESS, >( input: RefreshChainlinkPriceInput< TAccountUser, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountVerifierAccount, TAccountAccessController, TAccountConfigAccount, TAccountVerifierProgramId >, config?: { programAddress?: TProgramAddress }, ): RefreshChainlinkPriceInstruction< TProgramAddress, TAccountUser, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountVerifierAccount, TAccountAccessController, TAccountConfigAccount, TAccountVerifierProgramId > { // Program address. const programAddress = config?.programAddress ?? SCOPE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { user: { value: input.user ?? null, isWritable: false }, oraclePrices: { value: input.oraclePrices ?? null, isWritable: true }, oracleMappings: { value: input.oracleMappings ?? null, isWritable: false }, oracleTwaps: { value: input.oracleTwaps ?? null, isWritable: true }, verifierAccount: { value: input.verifierAccount ?? null, isWritable: false, }, accessController: { value: input.accessController ?? null, isWritable: false, }, configAccount: { value: input.configAccount ?? null, isWritable: false }, verifierProgramId: { value: input.verifierProgramId ?? null, isWritable: false, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.user), getAccountMeta(accounts.oraclePrices), getAccountMeta(accounts.oracleMappings), getAccountMeta(accounts.oracleTwaps), getAccountMeta(accounts.verifierAccount), getAccountMeta(accounts.accessController), getAccountMeta(accounts.configAccount), getAccountMeta(accounts.verifierProgramId), ], data: getRefreshChainlinkPriceInstructionDataEncoder().encode( args as RefreshChainlinkPriceInstructionDataArgs, ), programAddress, } as RefreshChainlinkPriceInstruction< TProgramAddress, TAccountUser, TAccountOraclePrices, TAccountOracleMappings, TAccountOracleTwaps, TAccountVerifierAccount, TAccountAccessController, TAccountConfigAccount, TAccountVerifierProgramId >); } export type ParsedRefreshChainlinkPriceInstruction< TProgram extends string = typeof SCOPE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { /** The account that signs the transaction. */ user: TAccountMetas[0]; oraclePrices: TAccountMetas[1]; oracleMappings: TAccountMetas[2]; oracleTwaps: TAccountMetas[3]; /** * The Verifier Account stores the DON's public keys and other verification parameters. * This account must match the PDA derived from the verifier program. */ verifierAccount: TAccountMetas[4]; /** The Access Controller Account */ accessController: TAccountMetas[5]; /** The Config Account is a PDA derived from a signed report */ configAccount: TAccountMetas[6]; /** The Verifier Program ID specifies the target Chainlink Data Streams Verifier Program. */ verifierProgramId: TAccountMetas[7]; }; data: RefreshChainlinkPriceInstructionData; }; export function parseRefreshChainlinkPriceInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedRefreshChainlinkPriceInstruction { if (instruction.accounts.length < 8) { // TODO: Coded error. throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { user: getNextAccount(), oraclePrices: getNextAccount(), oracleMappings: getNextAccount(), oracleTwaps: getNextAccount(), verifierAccount: getNextAccount(), accessController: getNextAccount(), configAccount: getNextAccount(), verifierProgramId: getNextAccount(), }, data: getRefreshChainlinkPriceInstructionDataDecoder().decode( instruction.data, ), }; }