diff --git a/clients/js/src/generated/instructions/batch.ts b/clients/js/src/generated/instructions/batch.ts new file mode 100644 index 00000000..3aee12b0 --- /dev/null +++ b/clients/js/src/generated/instructions/batch.ts @@ -0,0 +1,138 @@ +/** + * 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 { + AccountRole, + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type Address, + type Codec, + type Decoder, + type Encoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, + type TransactionSigner, +} from '@solana/kit'; +import { TOKEN_PROGRAM_ADDRESS } from '../programs'; + +export const BATCH_DISCRIMINATOR = 255; + +export function getBatchDiscriminatorBytes() { + return getU8Encoder().encode(BATCH_DISCRIMINATOR); +} + +export type BatchInstruction< + TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & InstructionWithData & InstructionWithAccounts; + +export type BatchInstructionData = { + discriminator: number; + /** Instruction data for batch instructions. */ + data: Array<{ numberOfAccounts: number; instructionData: ReadonlyUint8Array }>; +}; + +export type BatchInstructionDataArgs = { + /** Instruction data for batch instructions. */ + data: Array<{ numberOfAccounts: number; instructionData: ReadonlyUint8Array }>; +}; + +export function getBatchInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + [ + 'data', + getArrayEncoder( + getStructEncoder([ + ['numberOfAccounts', getU8Encoder()], + ['instructionData', addEncoderSizePrefix(getBytesEncoder(), getU8Encoder())], + ]), + { size: 'remainder' }, + ), + ], + ]), + value => ({ ...value, discriminator: BATCH_DISCRIMINATOR }), + ); +} + +export function getBatchInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + [ + 'data', + getArrayDecoder( + getStructDecoder([ + ['numberOfAccounts', getU8Decoder()], + ['instructionData', addDecoderSizePrefix(getBytesDecoder(), getU8Decoder())], + ]), + { size: 'remainder' }, + ), + ], + ]); +} + +export function getBatchInstructionDataCodec(): Codec { + return combineCodec(getBatchInstructionDataEncoder(), getBatchInstructionDataDecoder()); +} + +export type BatchInput = { + data: BatchInstructionDataArgs['data']; + accounts?: Array; +}; + +export function getBatchInstruction( + input: BatchInput, + config?: { programAddress?: TProgramAddress }, +): BatchInstruction { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_PROGRAM_ADDRESS; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: AccountMeta[] = (args.accounts ?? []).map(signer => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + })); + + return Object.freeze({ + accounts: remainingAccounts, + data: getBatchInstructionDataEncoder().encode(args as BatchInstructionDataArgs), + programAddress, + } as BatchInstruction); +} + +export type ParsedBatchInstruction = { + programAddress: Address; + data: BatchInstructionData; +}; + +export function parseBatchInstruction( + instruction: Instruction & InstructionWithData, +): ParsedBatchInstruction { + return { + programAddress: instruction.programAddress, + data: getBatchInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index a9731e09..2626709b 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -9,6 +9,7 @@ export * from './amountToUiAmount'; export * from './approve'; export * from './approveChecked'; +export * from './batch'; export * from './burn'; export * from './burnChecked'; export * from './closeAccount'; @@ -34,3 +35,5 @@ export * from './thawAccount'; export * from './transfer'; export * from './transferChecked'; export * from './uiAmountToAmount'; +export * from './unwrapLamports'; +export * from './withdrawExcessLamports'; diff --git a/clients/js/src/generated/instructions/syncNative.ts b/clients/js/src/generated/instructions/syncNative.ts index 118fc893..bb0a40ad 100644 --- a/clients/js/src/generated/instructions/syncNative.ts +++ b/clients/js/src/generated/instructions/syncNative.ts @@ -23,6 +23,7 @@ import { type Instruction, type InstructionWithAccounts, type InstructionWithData, + type ReadonlyAccount, type ReadonlyUint8Array, type WritableAccount, } from '@solana/kit'; @@ -38,11 +39,18 @@ export function getSyncNativeDiscriminatorBytes() { export type SyncNativeInstruction< TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, TAccountAccount extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta | undefined = undefined, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< - [TAccountAccount extends string ? WritableAccount : TAccountAccount, ...TRemainingAccounts] + [ + TAccountAccount extends string ? WritableAccount : TAccountAccount, + ...(TAccountRent extends undefined + ? [] + : [TAccountRent extends string ? ReadonlyAccount : TAccountRent]), + ...TRemainingAccounts, + ] >; export type SyncNativeInstructionData = { discriminator: number }; @@ -67,31 +75,45 @@ export function getSyncNativeInstructionDataCodec(): FixedSizeCodec< return combineCodec(getSyncNativeInstructionDataEncoder(), getSyncNativeInstructionDataDecoder()); } -export type SyncNativeInput = { +export type SyncNativeInput = { /** The native token account to sync with its underlying lamports. */ account: Address; + /** Rent sysvar. */ + rent?: Address; }; export function getSyncNativeInstruction< TAccountAccount extends string, + TAccountRent extends string, TProgramAddress extends Address = typeof TOKEN_PROGRAM_ADDRESS, >( - input: SyncNativeInput, + input: SyncNativeInput, config?: { programAddress?: TProgramAddress }, -): SyncNativeInstruction { +): SyncNativeInstruction { // Program address. const programAddress = config?.programAddress ?? TOKEN_PROGRAM_ADDRESS; // Original accounts. - const originalAccounts = { account: { value: input.account ?? null, isWritable: true } }; + const originalAccounts = { + account: { value: input.account ?? null, isWritable: true }, + rent: { value: input.rent ?? null, isWritable: false }, + }; const accounts = originalAccounts as Record; - const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + // Resolve default values. + if (!accounts.rent.value) { + accounts.rent.value = + 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted'); return Object.freeze({ - accounts: [getAccountMeta('account', accounts.account)], + accounts: [getAccountMeta('account', accounts.account), getAccountMeta('rent', accounts.rent)].filter( + (x: T | undefined): x is T => x !== undefined, + ), data: getSyncNativeInstructionDataEncoder().encode({}), programAddress, - } as SyncNativeInstruction); + } as SyncNativeInstruction); } export type ParsedSyncNativeInstruction< @@ -102,6 +124,8 @@ export type ParsedSyncNativeInstruction< accounts: { /** The native token account to sync with its underlying lamports. */ account: TAccountMetas[0]; + /** Rent sysvar. */ + rent?: TAccountMetas[1] | undefined; }; data: SyncNativeInstructionData; }; @@ -123,9 +147,15 @@ export function parseSyncNativeInstruction { + if (optionalAccountsRemaining === 0) return undefined; + optionalAccountsRemaining -= 1; + return getNextAccount(); + }; return { programAddress: instruction.programAddress, - accounts: { account: getNextAccount() }, + accounts: { account: getNextAccount(), rent: getNextOptionalAccount() }, data: getSyncNativeInstructionDataDecoder().decode(instruction.data), }; } diff --git a/clients/js/src/generated/instructions/unwrapLamports.ts b/clients/js/src/generated/instructions/unwrapLamports.ts new file mode 100644 index 00000000..fe9a32cc --- /dev/null +++ b/clients/js/src/generated/instructions/unwrapLamports.ts @@ -0,0 +1,218 @@ +/** + * 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 { + AccountRole, + combineCodec, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + none, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type Codec, + type Decoder, + type Encoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type Option, + type OptionOrNullable, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from '@solana/kit'; +import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core'; +import { TOKEN_PROGRAM_ADDRESS } from '../programs'; + +export const UNWRAP_LAMPORTS_DISCRIMINATOR = 45; + +export function getUnwrapLamportsDiscriminatorBytes() { + return getU8Encoder().encode(UNWRAP_LAMPORTS_DISCRIMINATOR); +} + +export type UnwrapLamportsInstruction< + TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, + TAccountSource extends string | AccountMeta = string, + TAccountDestination extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSource extends string ? WritableAccount : TAccountSource, + TAccountDestination extends string ? WritableAccount : TAccountDestination, + TAccountAuthority extends string ? ReadonlyAccount : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type UnwrapLamportsInstructionData = { + discriminator: number; + /** + * Optional amount of lamports to transfer. + * If not provided, the instruction will unwrap all lamports in excess of rent exemption. + */ + amount: Option; +}; + +export type UnwrapLamportsInstructionDataArgs = { + /** + * Optional amount of lamports to transfer. + * If not provided, the instruction will unwrap all lamports in excess of rent exemption. + */ + amount?: OptionOrNullable; +}; + +export function getUnwrapLamportsInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['amount', getOptionEncoder(getU64Encoder())], + ]), + value => ({ ...value, discriminator: UNWRAP_LAMPORTS_DISCRIMINATOR, amount: value.amount ?? none() }), + ); +} + +export function getUnwrapLamportsInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['amount', getOptionDecoder(getU64Decoder())], + ]); +} + +export function getUnwrapLamportsInstructionDataCodec(): Codec< + UnwrapLamportsInstructionDataArgs, + UnwrapLamportsInstructionData +> { + return combineCodec(getUnwrapLamportsInstructionDataEncoder(), getUnwrapLamportsInstructionDataDecoder()); +} + +export type UnwrapLamportsInput< + TAccountSource extends string = string, + TAccountDestination extends string = string, + TAccountAuthority extends string = string, +> = { + /** The source account. */ + source: Address; + /** The destination account. */ + destination: Address; + /** The source account owner or its multisignature account. */ + authority: Address | TransactionSigner; + amount?: UnwrapLamportsInstructionDataArgs['amount']; + multiSigners?: Array; +}; + +export function getUnwrapLamportsInstruction< + TAccountSource extends string, + TAccountDestination extends string, + TAccountAuthority extends string, + TProgramAddress extends Address = typeof TOKEN_PROGRAM_ADDRESS, +>( + input: UnwrapLamportsInput, + config?: { programAddress?: TProgramAddress }, +): UnwrapLamportsInstruction< + TProgramAddress, + TAccountSource, + TAccountDestination, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + source: { value: input.source ?? null, isWritable: true }, + destination: { value: input.destination ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: AccountMeta[] = (args.multiSigners ?? []).map(signer => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + })); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta('source', accounts.source), + getAccountMeta('destination', accounts.destination), + getAccountMeta('authority', accounts.authority), + ...remainingAccounts, + ], + data: getUnwrapLamportsInstructionDataEncoder().encode(args as UnwrapLamportsInstructionDataArgs), + programAddress, + } as UnwrapLamportsInstruction< + TProgramAddress, + TAccountSource, + TAccountDestination, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountAuthority + >); +} + +export type ParsedUnwrapLamportsInstruction< + TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The source account. */ + source: TAccountMetas[0]; + /** The destination account. */ + destination: TAccountMetas[1]; + /** The source account owner or its multisignature account. */ + authority: TAccountMetas[2]; + }; + data: UnwrapLamportsInstructionData; +}; + +export function parseUnwrapLamportsInstruction( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedUnwrapLamportsInstruction { + if (instruction.accounts.length < 3) { + throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 3, + }); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { source: getNextAccount(), destination: getNextAccount(), authority: getNextAccount() }, + data: getUnwrapLamportsInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/instructions/withdrawExcessLamports.ts b/clients/js/src/generated/instructions/withdrawExcessLamports.ts new file mode 100644 index 00000000..02467803 --- /dev/null +++ b/clients/js/src/generated/instructions/withdrawExcessLamports.ts @@ -0,0 +1,197 @@ +/** + * 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 { + AccountRole, + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from '@solana/kit'; +import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core'; +import { TOKEN_PROGRAM_ADDRESS } from '../programs'; + +export const WITHDRAW_EXCESS_LAMPORTS_DISCRIMINATOR = 38; + +export function getWithdrawExcessLamportsDiscriminatorBytes() { + return getU8Encoder().encode(WITHDRAW_EXCESS_LAMPORTS_DISCRIMINATOR); +} + +export type WithdrawExcessLamportsInstruction< + TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, + TAccountSource extends string | AccountMeta = string, + TAccountDestination extends string | AccountMeta = string, + TAccountAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSource extends string ? WritableAccount : TAccountSource, + TAccountDestination extends string ? WritableAccount : TAccountDestination, + TAccountAuthority extends string ? ReadonlyAccount : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type WithdrawExcessLamportsInstructionData = { discriminator: number }; + +export type WithdrawExcessLamportsInstructionDataArgs = {}; + +export function getWithdrawExcessLamportsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({ + ...value, + discriminator: WITHDRAW_EXCESS_LAMPORTS_DISCRIMINATOR, + })); +} + +export function getWithdrawExcessLamportsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getWithdrawExcessLamportsInstructionDataCodec(): FixedSizeCodec< + WithdrawExcessLamportsInstructionDataArgs, + WithdrawExcessLamportsInstructionData +> { + return combineCodec( + getWithdrawExcessLamportsInstructionDataEncoder(), + getWithdrawExcessLamportsInstructionDataDecoder(), + ); +} + +export type WithdrawExcessLamportsInput< + TAccountSource extends string = string, + TAccountDestination extends string = string, + TAccountAuthority extends string = string, +> = { + /** The source account. */ + source: Address; + /** The destination account. */ + destination: Address; + /** The source account owner or its multisignature account. */ + authority: Address | TransactionSigner; + multiSigners?: Array; +}; + +export function getWithdrawExcessLamportsInstruction< + TAccountSource extends string, + TAccountDestination extends string, + TAccountAuthority extends string, + TProgramAddress extends Address = typeof TOKEN_PROGRAM_ADDRESS, +>( + input: WithdrawExcessLamportsInput, + config?: { programAddress?: TProgramAddress }, +): WithdrawExcessLamportsInstruction< + TProgramAddress, + TAccountSource, + TAccountDestination, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + source: { value: input.source ?? null, isWritable: true }, + destination: { value: input.destination ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: AccountMeta[] = (args.multiSigners ?? []).map(signer => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + })); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta('source', accounts.source), + getAccountMeta('destination', accounts.destination), + getAccountMeta('authority', accounts.authority), + ...remainingAccounts, + ], + data: getWithdrawExcessLamportsInstructionDataEncoder().encode({}), + programAddress, + } as WithdrawExcessLamportsInstruction< + TProgramAddress, + TAccountSource, + TAccountDestination, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountAuthority + >); +} + +export type ParsedWithdrawExcessLamportsInstruction< + TProgram extends string = typeof TOKEN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The source account. */ + source: TAccountMetas[0]; + /** The destination account. */ + destination: TAccountMetas[1]; + /** The source account owner or its multisignature account. */ + authority: TAccountMetas[2]; + }; + data: WithdrawExcessLamportsInstructionData; +}; + +export function parseWithdrawExcessLamportsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedWithdrawExcessLamportsInstruction { + if (instruction.accounts.length < 3) { + throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 3, + }); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { source: getNextAccount(), destination: getNextAccount(), authority: getNextAccount() }, + data: getWithdrawExcessLamportsInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/js/src/generated/programs/token.ts b/clients/js/src/generated/programs/token.ts index f2094234..58beff35 100644 --- a/clients/js/src/generated/programs/token.ts +++ b/clients/js/src/generated/programs/token.ts @@ -45,6 +45,7 @@ import { getAmountToUiAmountInstruction, getApproveCheckedInstruction, getApproveInstruction, + getBatchInstruction, getBurnCheckedInstruction, getBurnInstruction, getCloseAccountInstruction, @@ -67,9 +68,12 @@ import { getTransferCheckedInstruction, getTransferInstruction, getUiAmountToAmountInstruction, + getUnwrapLamportsInstruction, + getWithdrawExcessLamportsInstruction, parseAmountToUiAmountInstruction, parseApproveCheckedInstruction, parseApproveInstruction, + parseBatchInstruction, parseBurnCheckedInstruction, parseBurnInstruction, parseCloseAccountInstruction, @@ -92,9 +96,12 @@ import { parseTransferCheckedInstruction, parseTransferInstruction, parseUiAmountToAmountInstruction, + parseUnwrapLamportsInstruction, + parseWithdrawExcessLamportsInstruction, type AmountToUiAmountInput, type ApproveCheckedInput, type ApproveInput, + type BatchInput, type BurnCheckedInput, type BurnInput, type CloseAccountInput, @@ -113,6 +120,7 @@ import { type ParsedAmountToUiAmountInstruction, type ParsedApproveCheckedInstruction, type ParsedApproveInstruction, + type ParsedBatchInstruction, type ParsedBurnCheckedInstruction, type ParsedBurnInstruction, type ParsedCloseAccountInstruction, @@ -135,6 +143,8 @@ import { type ParsedTransferCheckedInstruction, type ParsedTransferInstruction, type ParsedUiAmountToAmountInstruction, + type ParsedUnwrapLamportsInstruction, + type ParsedWithdrawExcessLamportsInstruction, type RevokeInput, type SetAuthorityInput, type SyncNativeInput, @@ -142,6 +152,8 @@ import { type TransferCheckedInput, type TransferInput, type UiAmountToAmountInput, + type UnwrapLamportsInput, + type WithdrawExcessLamportsInput, } from '../instructions'; export const TOKEN_PROGRAM_ADDRESS = @@ -196,6 +208,9 @@ export enum TokenInstruction { InitializeImmutableOwner, AmountToUiAmount, UiAmountToAmount, + WithdrawExcessLamports, + UnwrapLamports, + Batch, } export function identifyTokenInstruction( @@ -277,6 +292,15 @@ export function identifyTokenInstruction( if (containsBytes(data, getU8Encoder().encode(24), 0)) { return TokenInstruction.UiAmountToAmount; } + if (containsBytes(data, getU8Encoder().encode(38), 0)) { + return TokenInstruction.WithdrawExcessLamports; + } + if (containsBytes(data, getU8Encoder().encode(45), 0)) { + return TokenInstruction.UnwrapLamports; + } + if (containsBytes(data, getU8Encoder().encode(255), 0)) { + return TokenInstruction.Batch; + } throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: 'token', @@ -310,7 +334,10 @@ export type ParsedTokenInstruction