/** * 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 { AccountRole, 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 RevokeInstruction< TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, TAccountSource extends string | IAccountMeta = string, TAccountOwner extends string | IAccountMeta = string, TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< [ TAccountSource extends string ? WritableAccount : TAccountSource, TAccountOwner extends string ? ReadonlyAccount : TAccountOwner, ...TRemainingAccounts, ] >; export type RevokeInstructionData = { discriminator: number }; export type RevokeInstructionDataArgs = {}; export function getRevokeInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([['discriminator', getU8Encoder()]]), (value) => ({ ...value, discriminator: 5 }) ); } export function getRevokeInstructionDataDecoder(): Decoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getRevokeInstructionDataCodec(): Codec< RevokeInstructionDataArgs, RevokeInstructionData > { return combineCodec( getRevokeInstructionDataEncoder(), getRevokeInstructionDataDecoder() ); } export type RevokeInput< TAccountSource extends string = string, TAccountOwner extends string = string, > = { /** The source account. */ source: Address; /** The source account owner or its multisignature. */ owner: Address | TransactionSigner; multiSigners?: Array; }; export function getRevokeInstruction< TAccountSource extends string, TAccountOwner extends string, >( input: RevokeInput ): RevokeInstruction< typeof TOKEN_PROGRAM_ADDRESS, TAccountSource, (typeof input)['owner'] extends TransactionSigner ? ReadonlySignerAccount & IAccountSignerMeta : TAccountOwner > { // Program address. const programAddress = TOKEN_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { source: { value: input.source ?? null, isWritable: true }, owner: { value: input.owner ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Original args. const args = { ...input }; // Remaining accounts. const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( (signer) => ({ address: signer.address, role: AccountRole.READONLY_SIGNER, signer, }) ); const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.source), getAccountMeta(accounts.owner), ...remainingAccounts, ], programAddress, data: getRevokeInstructionDataEncoder().encode({}), } as RevokeInstruction< typeof TOKEN_PROGRAM_ADDRESS, TAccountSource, (typeof input)['owner'] extends TransactionSigner ? ReadonlySignerAccount & IAccountSignerMeta : TAccountOwner >; return instruction; } export type ParsedRevokeInstruction< TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; accounts: { /** The source account. */ source: TAccountMetas[0]; /** The source account owner or its multisignature. */ owner: TAccountMetas[1]; }; data: RevokeInstructionData; }; export function parseRevokeInstruction< TProgram extends string, TAccountMetas extends readonly IAccountMeta[], >( instruction: IInstruction & IInstructionWithAccounts & IInstructionWithData ): ParsedRevokeInstruction { 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: { source: getNextAccount(), owner: getNextAccount(), }, data: getRevokeInstructionDataDecoder().decode(instruction.data), }; }