123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- /**
- * 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/metaplex-foundation/kinobi
- */
- import {
- Address,
- Codec,
- Decoder,
- Encoder,
- IAccountMeta,
- IInstruction,
- IInstructionWithAccounts,
- IInstructionWithData,
- ReadonlyAccount,
- WritableAccount,
- combineCodec,
- getAddressDecoder,
- getAddressEncoder,
- getStructDecoder,
- getStructEncoder,
- getU8Decoder,
- getU8Encoder,
- transformEncoder,
- } from '@solana/web3.js';
- import { TOKEN_PROGRAM_ADDRESS } from '../programs';
- import { ResolvedAccount, getAccountMetaFactory } from '../shared';
- export type InitializeAccount3Instruction<
- TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
- TAccountAccount extends string | IAccountMeta<string> = string,
- TAccountMint extends string | IAccountMeta<string> = string,
- TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
- > = IInstruction<TProgram> &
- IInstructionWithData<Uint8Array> &
- IInstructionWithAccounts<
- [
- TAccountAccount extends string
- ? WritableAccount<TAccountAccount>
- : TAccountAccount,
- TAccountMint extends string
- ? ReadonlyAccount<TAccountMint>
- : TAccountMint,
- ...TRemainingAccounts,
- ]
- >;
- export type InitializeAccount3InstructionData = {
- discriminator: number;
- /** The new account's owner/multisignature. */
- owner: Address;
- };
- export type InitializeAccount3InstructionDataArgs = {
- /** The new account's owner/multisignature. */
- owner: Address;
- };
- export function getInitializeAccount3InstructionDataEncoder(): Encoder<InitializeAccount3InstructionDataArgs> {
- return transformEncoder(
- getStructEncoder([
- ['discriminator', getU8Encoder()],
- ['owner', getAddressEncoder()],
- ]),
- (value) => ({ ...value, discriminator: 18 })
- );
- }
- export function getInitializeAccount3InstructionDataDecoder(): Decoder<InitializeAccount3InstructionData> {
- return getStructDecoder([
- ['discriminator', getU8Decoder()],
- ['owner', getAddressDecoder()],
- ]);
- }
- export function getInitializeAccount3InstructionDataCodec(): Codec<
- InitializeAccount3InstructionDataArgs,
- InitializeAccount3InstructionData
- > {
- return combineCodec(
- getInitializeAccount3InstructionDataEncoder(),
- getInitializeAccount3InstructionDataDecoder()
- );
- }
- export type InitializeAccount3Input<
- TAccountAccount extends string = string,
- TAccountMint extends string = string,
- > = {
- /** The account to initialize. */
- account: Address<TAccountAccount>;
- /** The mint this account will be associated with. */
- mint: Address<TAccountMint>;
- owner: InitializeAccount3InstructionDataArgs['owner'];
- };
- export function getInitializeAccount3Instruction<
- TAccountAccount extends string,
- TAccountMint extends string,
- >(
- input: InitializeAccount3Input<TAccountAccount, TAccountMint>
- ): InitializeAccount3Instruction<
- typeof TOKEN_PROGRAM_ADDRESS,
- TAccountAccount,
- TAccountMint
- > {
- // Program address.
- const programAddress = TOKEN_PROGRAM_ADDRESS;
- // Original accounts.
- const originalAccounts = {
- account: { value: input.account ?? null, isWritable: true },
- mint: { value: input.mint ?? null, isWritable: false },
- };
- const accounts = originalAccounts as Record<
- keyof typeof originalAccounts,
- ResolvedAccount
- >;
- // Original args.
- const args = { ...input };
- const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
- const instruction = {
- accounts: [getAccountMeta(accounts.account), getAccountMeta(accounts.mint)],
- programAddress,
- data: getInitializeAccount3InstructionDataEncoder().encode(
- args as InitializeAccount3InstructionDataArgs
- ),
- } as InitializeAccount3Instruction<
- typeof TOKEN_PROGRAM_ADDRESS,
- TAccountAccount,
- TAccountMint
- >;
- return instruction;
- }
- export type ParsedInitializeAccount3Instruction<
- TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
- TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
- > = {
- programAddress: Address<TProgram>;
- accounts: {
- /** The account to initialize. */
- account: TAccountMetas[0];
- /** The mint this account will be associated with. */
- mint: TAccountMetas[1];
- };
- data: InitializeAccount3InstructionData;
- };
- export function parseInitializeAccount3Instruction<
- TProgram extends string,
- TAccountMetas extends readonly IAccountMeta[],
- >(
- instruction: IInstruction<TProgram> &
- IInstructionWithAccounts<TAccountMetas> &
- IInstructionWithData<Uint8Array>
- ): ParsedInitializeAccount3Instruction<TProgram, TAccountMetas> {
- if (instruction.accounts.length < 2) {
- // TODO: Coded error.
- throw new Error('Not enough accounts');
- }
- let accountIndex = 0;
- const getNextAccount = () => {
- const accountMeta = instruction.accounts![accountIndex]!;
- accountIndex += 1;
- return accountMeta;
- };
- return {
- programAddress: instruction.programAddress,
- accounts: {
- account: getNextAccount(),
- mint: getNextAccount(),
- },
- data: getInitializeAccount3InstructionDataDecoder().decode(
- instruction.data
- ),
- };
- }
|