UNPKG

@kamino-finance/kliquidity-sdk

Version:

Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol

104 lines (87 loc) 12.5 kB
/** * 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 { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit'; import { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const INITIALIZE_POSITION_BUNDLE_WITH_METADATA_DISCRIMINATOR = new Uint8Array([93, 124, 16, 179, 249, 131, 115, 245]); export function getInitializePositionBundleWithMetadataDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_POSITION_BUNDLE_WITH_METADATA_DISCRIMINATOR); } export type InitializePositionBundleWithMetadataInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountPositionBundle extends string | AccountMeta<string> = string, TAccountPositionBundleMint extends string | AccountMeta<string> = string, TAccountPositionBundleMetadata extends string | AccountMeta<string> = string, TAccountPositionBundleTokenAccount extends string | AccountMeta<string> = string, TAccountPositionBundleOwner extends string | AccountMeta<string> = string, TAccountFunder extends string | AccountMeta<string> = string, TAccountMetadataUpdateAuth extends string | AccountMeta<string> = string, TAccountTokenProgram extends string | AccountMeta<string> = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountSystemProgram extends string | AccountMeta<string> = "11111111111111111111111111111111", TAccountRent extends string | AccountMeta<string> = "SysvarRent111111111111111111111111111111111", TAccountAssociatedTokenProgram extends string | AccountMeta<string> = string, TAccountMetadataProgram extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountPositionBundle extends string ? WritableAccount<TAccountPositionBundle> : TAccountPositionBundle, TAccountPositionBundleMint extends string ? WritableSignerAccount<TAccountPositionBundleMint> & AccountSignerMeta<TAccountPositionBundleMint> : TAccountPositionBundleMint, TAccountPositionBundleMetadata extends string ? WritableAccount<TAccountPositionBundleMetadata> : TAccountPositionBundleMetadata, TAccountPositionBundleTokenAccount extends string ? WritableAccount<TAccountPositionBundleTokenAccount> : TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner extends string ? ReadonlyAccount<TAccountPositionBundleOwner> : TAccountPositionBundleOwner, TAccountFunder extends string ? WritableSignerAccount<TAccountFunder> & AccountSignerMeta<TAccountFunder> : TAccountFunder, TAccountMetadataUpdateAuth extends string ? ReadonlyAccount<TAccountMetadataUpdateAuth> : TAccountMetadataUpdateAuth, TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram, TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram, TAccountRent extends string ? ReadonlyAccount<TAccountRent> : TAccountRent, TAccountAssociatedTokenProgram extends string ? ReadonlyAccount<TAccountAssociatedTokenProgram> : TAccountAssociatedTokenProgram, TAccountMetadataProgram extends string ? ReadonlyAccount<TAccountMetadataProgram> : TAccountMetadataProgram, ...TRemainingAccounts]>; export type InitializePositionBundleWithMetadataInstructionData = { discriminator: ReadonlyUint8Array; }; export type InitializePositionBundleWithMetadataInstructionDataArgs = { }; export function getInitializePositionBundleWithMetadataInstructionDataEncoder(): FixedSizeEncoder<InitializePositionBundleWithMetadataInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: INITIALIZE_POSITION_BUNDLE_WITH_METADATA_DISCRIMINATOR })); } export function getInitializePositionBundleWithMetadataInstructionDataDecoder(): FixedSizeDecoder<InitializePositionBundleWithMetadataInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getInitializePositionBundleWithMetadataInstructionDataCodec(): FixedSizeCodec<InitializePositionBundleWithMetadataInstructionDataArgs, InitializePositionBundleWithMetadataInstructionData> { return combineCodec(getInitializePositionBundleWithMetadataInstructionDataEncoder(), getInitializePositionBundleWithMetadataInstructionDataDecoder()); } export type InitializePositionBundleWithMetadataInput<TAccountPositionBundle extends string = string, TAccountPositionBundleMint extends string = string, TAccountPositionBundleMetadata extends string = string, TAccountPositionBundleTokenAccount extends string = string, TAccountPositionBundleOwner extends string = string, TAccountFunder extends string = string, TAccountMetadataUpdateAuth extends string = string, TAccountTokenProgram extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string, TAccountAssociatedTokenProgram extends string = string, TAccountMetadataProgram extends string = string> = { positionBundle: Address<TAccountPositionBundle>; positionBundleMint: TransactionSigner<TAccountPositionBundleMint>; positionBundleMetadata: Address<TAccountPositionBundleMetadata>; positionBundleTokenAccount: Address<TAccountPositionBundleTokenAccount>; positionBundleOwner: Address<TAccountPositionBundleOwner>; funder: TransactionSigner<TAccountFunder>; metadataUpdateAuth: Address<TAccountMetadataUpdateAuth>; tokenProgram?: Address<TAccountTokenProgram>; systemProgram?: Address<TAccountSystemProgram>; rent?: Address<TAccountRent>; associatedTokenProgram: Address<TAccountAssociatedTokenProgram>; metadataProgram: Address<TAccountMetadataProgram>; } export function getInitializePositionBundleWithMetadataInstruction<TAccountPositionBundle extends string, TAccountPositionBundleMint extends string, TAccountPositionBundleMetadata extends string, TAccountPositionBundleTokenAccount extends string, TAccountPositionBundleOwner extends string, TAccountFunder extends string, TAccountMetadataUpdateAuth extends string, TAccountTokenProgram extends string, TAccountSystemProgram extends string, TAccountRent extends string, TAccountAssociatedTokenProgram extends string, TAccountMetadataProgram extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: InitializePositionBundleWithMetadataInput<TAccountPositionBundle, TAccountPositionBundleMint, TAccountPositionBundleMetadata, TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner, TAccountFunder, TAccountMetadataUpdateAuth, TAccountTokenProgram, TAccountSystemProgram, TAccountRent, TAccountAssociatedTokenProgram, TAccountMetadataProgram>, config?: { programAddress?: TProgramAddress } ): InitializePositionBundleWithMetadataInstruction<TProgramAddress, TAccountPositionBundle, TAccountPositionBundleMint, TAccountPositionBundleMetadata, TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner, TAccountFunder, TAccountMetadataUpdateAuth, TAccountTokenProgram, TAccountSystemProgram, TAccountRent, TAccountAssociatedTokenProgram, TAccountMetadataProgram> { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { positionBundle: { value: input.positionBundle ?? null, isWritable: true }, positionBundleMint: { value: input.positionBundleMint ?? null, isWritable: true }, positionBundleMetadata: { value: input.positionBundleMetadata ?? null, isWritable: true }, positionBundleTokenAccount: { value: input.positionBundleTokenAccount ?? null, isWritable: true }, positionBundleOwner: { value: input.positionBundleOwner ?? null, isWritable: false }, funder: { value: input.funder ?? null, isWritable: true }, metadataUpdateAuth: { value: input.metadataUpdateAuth ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isWritable: false }, metadataProgram: { value: input.metadataProgram ?? null, isWritable: false } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } if (!accounts.rent.value) { accounts.rent.value = 'SysvarRent111111111111111111111111111111111' as Address<'SysvarRent111111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.positionBundle), getAccountMeta(accounts.positionBundleMint), getAccountMeta(accounts.positionBundleMetadata), getAccountMeta(accounts.positionBundleTokenAccount), getAccountMeta(accounts.positionBundleOwner), getAccountMeta(accounts.funder), getAccountMeta(accounts.metadataUpdateAuth), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent), getAccountMeta(accounts.associatedTokenProgram), getAccountMeta(accounts.metadataProgram)], data: getInitializePositionBundleWithMetadataInstructionDataEncoder().encode({}), programAddress } as InitializePositionBundleWithMetadataInstruction<TProgramAddress, TAccountPositionBundle, TAccountPositionBundleMint, TAccountPositionBundleMetadata, TAccountPositionBundleTokenAccount, TAccountPositionBundleOwner, TAccountFunder, TAccountMetadataUpdateAuth, TAccountTokenProgram, TAccountSystemProgram, TAccountRent, TAccountAssociatedTokenProgram, TAccountMetadataProgram>); } export type ParsedInitializePositionBundleWithMetadataInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { positionBundle: TAccountMetas[0]; positionBundleMint: TAccountMetas[1]; positionBundleMetadata: TAccountMetas[2]; positionBundleTokenAccount: TAccountMetas[3]; positionBundleOwner: TAccountMetas[4]; funder: TAccountMetas[5]; metadataUpdateAuth: TAccountMetas[6]; tokenProgram: TAccountMetas[7]; systemProgram: TAccountMetas[8]; rent: TAccountMetas[9]; associatedTokenProgram: TAccountMetas[10]; metadataProgram: TAccountMetas[11]; }; data: InitializePositionBundleWithMetadataInstructionData; }; export function parseInitializePositionBundleWithMetadataInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedInitializePositionBundleWithMetadataInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 12) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; } return { programAddress: instruction.programAddress, accounts: { positionBundle: getNextAccount(), positionBundleMint: getNextAccount(), positionBundleMetadata: getNextAccount(), positionBundleTokenAccount: getNextAccount(), positionBundleOwner: getNextAccount(), funder: getNextAccount(), metadataUpdateAuth: getNextAccount(), tokenProgram: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount(), associatedTokenProgram: getNextAccount(), metadataProgram: getNextAccount() }, data: getInitializePositionBundleWithMetadataInstructionDataDecoder().decode(instruction.data) }; }