/** * This code was AUTOGENERATED using the kinobi library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun kinobi to update it. * * @see https://github.com/kinobi-so/kinobi */ import { Context, Option, OptionOrNullable, Pda, PublicKey, Signer, TransactionBuilder, transactionBuilder, } from '@metaplex-foundation/umi'; import { Serializer, bytes, mapSerializer, option, struct, u128, } from '@metaplex-foundation/umi/serializers'; import { ResolvedAccount, ResolvedAccountsWithIndices, getAccountMetasAndSigners, } from '../shared'; // Accounts. export type SetSolPriceInstructionAccounts = { updater: Signer; priceFeed: PublicKey | Pda; }; // Data. export type SetSolPriceInstructionData = { discriminator: Uint8Array; nativeTokenPriceUsd: Option; }; export type SetSolPriceInstructionDataArgs = { nativeTokenPriceUsd: OptionOrNullable; }; export function getSetSolPriceInstructionDataSerializer(): Serializer< SetSolPriceInstructionDataArgs, SetSolPriceInstructionData > { return mapSerializer< SetSolPriceInstructionDataArgs, any, SetSolPriceInstructionData >( struct( [ ['discriminator', bytes({ size: 8 })], ['nativeTokenPriceUsd', option(u128())], ], { description: 'SetSolPriceInstructionData' } ), (value) => ({ ...value, discriminator: new Uint8Array([151, 237, 70, 191, 232, 81, 138, 214]), }) ) as Serializer; } // Args. export type SetSolPriceInstructionArgs = SetSolPriceInstructionDataArgs; // Instruction. export function setSolPrice( context: Pick, input: SetSolPriceInstructionAccounts & SetSolPriceInstructionArgs ): TransactionBuilder { // Program ID. const programId = context.programs.getPublicKey( 'pricefeed', '8ahPGPjEbpgGaZx2NV1iG5Shj7TDwvsjkEDcGWjt94TP' ); // Accounts. const resolvedAccounts = { updater: { index: 0, isWritable: false as boolean, value: input.updater ?? null, }, priceFeed: { index: 1, isWritable: true as boolean, value: input.priceFeed ?? null, }, } satisfies ResolvedAccountsWithIndices; // Arguments. const resolvedArgs: SetSolPriceInstructionArgs = { ...input }; // Accounts in order. const orderedAccounts: ResolvedAccount[] = Object.values( resolvedAccounts ).sort((a, b) => a.index - b.index); // Keys and Signers. const [keys, signers] = getAccountMetasAndSigners( orderedAccounts, 'programId', programId ); // Data. const data = getSetSolPriceInstructionDataSerializer().serialize( resolvedArgs as SetSolPriceInstructionDataArgs ); // Bytes Created On Chain. const bytesCreatedOnChain = 0; return transactionBuilder([ { instruction: { keys, programId, data }, signers, bytesCreatedOnChain }, ]); }