UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

79 lines (61 loc) 7.07 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 ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit'; import { WHIRLPOOL_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; export const SET_TOKEN_BADGE_AUTHORITY_DISCRIMINATOR = new Uint8Array([207, 202, 4, 32, 205, 79, 13, 178]); export function getSetTokenBadgeAuthorityDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_TOKEN_BADGE_AUTHORITY_DISCRIMINATOR); } export type SetTokenBadgeAuthorityInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountWhirlpoolsConfig extends string | AccountMeta<string> = string, TAccountWhirlpoolsConfigExtension extends string | AccountMeta<string> = string, TAccountConfigExtensionAuthority extends string | AccountMeta<string> = string, TAccountNewTokenBadgeAuthority extends string | AccountMeta<string> = string, TRemainingAccounts extends readonly AccountMeta<string>[] = []> = Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array> & InstructionWithAccounts<[TAccountWhirlpoolsConfig extends string ? ReadonlyAccount<TAccountWhirlpoolsConfig> : TAccountWhirlpoolsConfig, TAccountWhirlpoolsConfigExtension extends string ? WritableAccount<TAccountWhirlpoolsConfigExtension> : TAccountWhirlpoolsConfigExtension, TAccountConfigExtensionAuthority extends string ? ReadonlySignerAccount<TAccountConfigExtensionAuthority> & AccountSignerMeta<TAccountConfigExtensionAuthority> : TAccountConfigExtensionAuthority, TAccountNewTokenBadgeAuthority extends string ? ReadonlyAccount<TAccountNewTokenBadgeAuthority> : TAccountNewTokenBadgeAuthority, ...TRemainingAccounts]>; export type SetTokenBadgeAuthorityInstructionData = { discriminator: ReadonlyUint8Array; }; export type SetTokenBadgeAuthorityInstructionDataArgs = { }; export function getSetTokenBadgeAuthorityInstructionDataEncoder(): FixedSizeEncoder<SetTokenBadgeAuthorityInstructionDataArgs> { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: SET_TOKEN_BADGE_AUTHORITY_DISCRIMINATOR })); } export function getSetTokenBadgeAuthorityInstructionDataDecoder(): FixedSizeDecoder<SetTokenBadgeAuthorityInstructionData> { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getSetTokenBadgeAuthorityInstructionDataCodec(): FixedSizeCodec<SetTokenBadgeAuthorityInstructionDataArgs, SetTokenBadgeAuthorityInstructionData> { return combineCodec(getSetTokenBadgeAuthorityInstructionDataEncoder(), getSetTokenBadgeAuthorityInstructionDataDecoder()); } export type SetTokenBadgeAuthorityInput<TAccountWhirlpoolsConfig extends string = string, TAccountWhirlpoolsConfigExtension extends string = string, TAccountConfigExtensionAuthority extends string = string, TAccountNewTokenBadgeAuthority extends string = string> = { whirlpoolsConfig: Address<TAccountWhirlpoolsConfig>; whirlpoolsConfigExtension: Address<TAccountWhirlpoolsConfigExtension>; configExtensionAuthority: TransactionSigner<TAccountConfigExtensionAuthority>; newTokenBadgeAuthority: Address<TAccountNewTokenBadgeAuthority>; } export function getSetTokenBadgeAuthorityInstruction<TAccountWhirlpoolsConfig extends string, TAccountWhirlpoolsConfigExtension extends string, TAccountConfigExtensionAuthority extends string, TAccountNewTokenBadgeAuthority extends string, TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS>(input: SetTokenBadgeAuthorityInput<TAccountWhirlpoolsConfig, TAccountWhirlpoolsConfigExtension, TAccountConfigExtensionAuthority, TAccountNewTokenBadgeAuthority>, config?: { programAddress?: TProgramAddress } ): SetTokenBadgeAuthorityInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpoolsConfigExtension, TAccountConfigExtensionAuthority, TAccountNewTokenBadgeAuthority> { // Program address. const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { whirlpoolsConfig: { value: input.whirlpoolsConfig ?? null, isWritable: false }, whirlpoolsConfigExtension: { value: input.whirlpoolsConfigExtension ?? null, isWritable: true }, configExtensionAuthority: { value: input.configExtensionAuthority ?? null, isWritable: false }, newTokenBadgeAuthority: { value: input.newTokenBadgeAuthority ?? null, isWritable: false } } const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.whirlpoolsConfig), getAccountMeta(accounts.whirlpoolsConfigExtension), getAccountMeta(accounts.configExtensionAuthority), getAccountMeta(accounts.newTokenBadgeAuthority)], data: getSetTokenBadgeAuthorityInstructionDataEncoder().encode({}), programAddress } as SetTokenBadgeAuthorityInstruction<TProgramAddress, TAccountWhirlpoolsConfig, TAccountWhirlpoolsConfigExtension, TAccountConfigExtensionAuthority, TAccountNewTokenBadgeAuthority>); } export type ParsedSetTokenBadgeAuthorityInstruction<TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[]> = { programAddress: Address<TProgram>; accounts: { whirlpoolsConfig: TAccountMetas[0]; whirlpoolsConfigExtension: TAccountMetas[1]; configExtensionAuthority: TAccountMetas[2]; newTokenBadgeAuthority: TAccountMetas[3]; }; data: SetTokenBadgeAuthorityInstructionData; }; export function parseSetTokenBadgeAuthorityInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas> & InstructionWithData<ReadonlyUint8Array>): ParsedSetTokenBadgeAuthorityInstruction<TProgram, TAccountMetas> { if (instruction.accounts.length < 4) { // 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: { whirlpoolsConfig: getNextAccount(), whirlpoolsConfigExtension: getNextAccount(), configExtensionAuthority: getNextAccount(), newTokenBadgeAuthority: getNextAccount() }, data: getSetTokenBadgeAuthorityInstructionDataDecoder().decode(instruction.data) }; }