| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- /**
- * 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,
- IAccountSignerMeta,
- IInstruction,
- IInstructionWithAccounts,
- IInstructionWithData,
- ReadonlyAccount,
- ReadonlySignerAccount,
- TransactionSigner,
- WritableAccount,
- combineCodec,
- getStructDecoder,
- getStructEncoder,
- getU8Decoder,
- getU8Encoder,
- transformEncoder,
- } from '@solana/web3.js';
- import { TOKEN_PROGRAM_ADDRESS } from '../programs';
- import { ResolvedAccount, getAccountMetaFactory } from '../shared';
- export type ThawTokenInstruction<
- TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
- TAccountAccount extends string | IAccountMeta<string> = string,
- TAccountMint extends string | IAccountMeta<string> = string,
- TAccountOwner 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,
- TAccountOwner extends string
- ? ReadonlySignerAccount<TAccountOwner> &
- IAccountSignerMeta<TAccountOwner>
- : TAccountOwner,
- ...TRemainingAccounts,
- ]
- >;
- export type ThawTokenInstructionData = { discriminator: number };
- export type ThawTokenInstructionDataArgs = {};
- export function getThawTokenInstructionDataEncoder(): Encoder<ThawTokenInstructionDataArgs> {
- return transformEncoder(
- getStructEncoder([['discriminator', getU8Encoder()]]),
- (value) => ({ ...value, discriminator: 11 })
- );
- }
- export function getThawTokenInstructionDataDecoder(): Decoder<ThawTokenInstructionData> {
- return getStructDecoder([['discriminator', getU8Decoder()]]);
- }
- export function getThawTokenInstructionDataCodec(): Codec<
- ThawTokenInstructionDataArgs,
- ThawTokenInstructionData
- > {
- return combineCodec(
- getThawTokenInstructionDataEncoder(),
- getThawTokenInstructionDataDecoder()
- );
- }
- export type ThawTokenInput<
- TAccountAccount extends string = string,
- TAccountMint extends string = string,
- TAccountOwner extends string = string,
- > = {
- account: Address<TAccountAccount>;
- mint: Address<TAccountMint>;
- owner: TransactionSigner<TAccountOwner>;
- };
- export function getThawTokenInstruction<
- TAccountAccount extends string,
- TAccountMint extends string,
- TAccountOwner extends string,
- >(
- input: ThawTokenInput<TAccountAccount, TAccountMint, TAccountOwner>
- ): ThawTokenInstruction<
- typeof TOKEN_PROGRAM_ADDRESS,
- TAccountAccount,
- TAccountMint,
- TAccountOwner
- > {
- // 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 },
- owner: { value: input.owner ?? null, isWritable: false },
- };
- const accounts = originalAccounts as Record<
- keyof typeof originalAccounts,
- ResolvedAccount
- >;
- const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
- const instruction = {
- accounts: [
- getAccountMeta(accounts.account),
- getAccountMeta(accounts.mint),
- getAccountMeta(accounts.owner),
- ],
- programAddress,
- data: getThawTokenInstructionDataEncoder().encode({}),
- } as ThawTokenInstruction<
- typeof TOKEN_PROGRAM_ADDRESS,
- TAccountAccount,
- TAccountMint,
- TAccountOwner
- >;
- return instruction;
- }
- export type ParsedThawTokenInstruction<
- TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS,
- TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
- > = {
- programAddress: Address<TProgram>;
- accounts: {
- account: TAccountMetas[0];
- mint: TAccountMetas[1];
- owner: TAccountMetas[2];
- };
- data: ThawTokenInstructionData;
- };
- export function parseThawTokenInstruction<
- TProgram extends string,
- TAccountMetas extends readonly IAccountMeta[],
- >(
- instruction: IInstruction<TProgram> &
- IInstructionWithAccounts<TAccountMetas> &
- IInstructionWithData<Uint8Array>
- ): ParsedThawTokenInstruction<TProgram, TAccountMetas> {
- if (instruction.accounts.length < 3) {
- // 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(),
- owner: getNextAccount(),
- },
- data: getThawTokenInstructionDataDecoder().decode(instruction.data),
- };
- }
|