UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

80 lines (60 loc) 5.44 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, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit'; import { AMM_V3_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const TRANSFER_REWARD_OWNER_DISCRIMINATOR = new Uint8Array([7, 22, 12, 83, 242, 43, 48, 121]); export function getTransferRewardOwnerDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(TRANSFER_REWARD_OWNER_DISCRIMINATOR); } export type TransferRewardOwnerInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountAuthority extends string | AccountMeta<string> = string, TAccountPoolState extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & AccountSignerMeta<TAccountAuthority> : TAccountAuthority, TAccountPoolState extends string ? WritableAccount<TAccountPoolState> : TAccountPoolState, ...TRemainingAccounts]>; export type TransferRewardOwnerInstructionData = { discriminator: ReadonlyUint8Array; newOwner: Address; }; export type TransferRewardOwnerInstructionDataArgs = { newOwner: Address; }; export function getTransferRewardOwnerInstructionDataEncoder(): FixedSizeEncoder<TransferRewardOwnerInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['newOwner', getAddressEncoder()]]), (value) => ({ ...value, discriminator: TRANSFER_REWARD_OWNER_DISCRIMINATOR })); } export function getTransferRewardOwnerInstructionDataDecoder(): FixedSizeDecoder<TransferRewardOwnerInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['newOwner', getAddressDecoder()]]); } export function getTransferRewardOwnerInstructionDataCodec(): FixedSizeCodec<TransferRewardOwnerInstructionDataArgs, TransferRewardOwnerInstructionData> { return combineCodec(getTransferRewardOwnerInstructionDataEncoder(), getTransferRewardOwnerInstructionDataDecoder()); } export type TransferRewardOwnerInput<TAccountAuthority extends string = string, TAccountPoolState extends string = string> = { authority: TransactionSigner<TAccountAuthority>; poolState: Address<TAccountPoolState>; newOwner: TransferRewardOwnerInstructionDataArgs["newOwner"]; } export function getTransferRewardOwnerInstruction<TAccountAuthority extends string, TAccountPoolState extends string, TProgramAddress extends Address = typeof AMM_V3_PROGRAM_ADDRESS>(input: TransferRewardOwnerInput<TAccountAuthority, TAccountPoolState>, config?: { programAddress?: TProgramAddress } ): TransferRewardOwnerInstruction<TProgramAddress, TAccountAuthority, TAccountPoolState> { // Program address. const programAddress = config?.programAddress ?? AMM_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { authority: { value: input.authority ?? null, isWritable: false }, poolState: { value: input.poolState ?? null, isWritable: true } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; // Original args. const args = { ...input, }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.authority), getAccountMeta(accounts.poolState)], data: getTransferRewardOwnerInstructionDataEncoder().encode(args as TransferRewardOwnerInstructionDataArgs), programAddress } as TransferRewardOwnerInstruction<TProgramAddress, TAccountAuthority, TAccountPoolState>); } export type ParsedTransferRewardOwnerInstruction<TProgram extends string = typeof AMM_V3_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { authority: TAccountMetas[0]; poolState: TAccountMetas[1]; }; data: TransferRewardOwnerInstructionData; }; export function parseTransferRewardOwnerInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedTransferRewardOwnerInstruction<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 as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; } return { programAddress: instruction.programAddress, accounts: { authority: getNextAccount(), poolState: getNextAccount() }, data: getTransferRewardOwnerInstructionDataDecoder().decode(instruction.data) }; }