UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

59 lines 5.83 kB
"use strict"; /** * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.REMOVE_LIQUIDITY_BY_RANGE_DISCRIMINATOR = void 0; exports.getRemoveLiquidityByRangeDiscriminatorBytes = getRemoveLiquidityByRangeDiscriminatorBytes; exports.getRemoveLiquidityByRangeInstructionDataEncoder = getRemoveLiquidityByRangeInstructionDataEncoder; exports.getRemoveLiquidityByRangeInstructionDataDecoder = getRemoveLiquidityByRangeInstructionDataDecoder; exports.getRemoveLiquidityByRangeInstructionDataCodec = getRemoveLiquidityByRangeInstructionDataCodec; exports.getRemoveLiquidityByRangeInstruction = getRemoveLiquidityByRangeInstruction; exports.parseRemoveLiquidityByRangeInstruction = parseRemoveLiquidityByRangeInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.REMOVE_LIQUIDITY_BY_RANGE_DISCRIMINATOR = new Uint8Array([26, 82, 102, 152, 240, 74, 105, 26]); function getRemoveLiquidityByRangeDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.REMOVE_LIQUIDITY_BY_RANGE_DISCRIMINATOR); } function getRemoveLiquidityByRangeInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['fromBinId', (0, kit_1.getI32Encoder)()], ['toBinId', (0, kit_1.getI32Encoder)()], ['bpsToRemove', (0, kit_1.getU16Encoder)()]]), (value) => ({ ...value, discriminator: exports.REMOVE_LIQUIDITY_BY_RANGE_DISCRIMINATOR })); } function getRemoveLiquidityByRangeInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['fromBinId', (0, kit_1.getI32Decoder)()], ['toBinId', (0, kit_1.getI32Decoder)()], ['bpsToRemove', (0, kit_1.getU16Decoder)()]]); } function getRemoveLiquidityByRangeInstructionDataCodec() { return (0, kit_1.combineCodec)(getRemoveLiquidityByRangeInstructionDataEncoder(), getRemoveLiquidityByRangeInstructionDataDecoder()); } function getRemoveLiquidityByRangeInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.LB_CLMM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { position: { value: input.position ?? null, isWritable: true }, lbPair: { value: input.lbPair ?? null, isWritable: true }, binArrayBitmapExtension: { value: input.binArrayBitmapExtension ?? null, isWritable: true }, userTokenX: { value: input.userTokenX ?? null, isWritable: true }, userTokenY: { value: input.userTokenY ?? null, isWritable: true }, reserveX: { value: input.reserveX ?? null, isWritable: true }, reserveY: { value: input.reserveY ?? null, isWritable: true }, tokenXMint: { value: input.tokenXMint ?? null, isWritable: false }, tokenYMint: { value: input.tokenYMint ?? null, isWritable: false }, binArrayLower: { value: input.binArrayLower ?? null, isWritable: true }, binArrayUpper: { value: input.binArrayUpper ?? null, isWritable: true }, sender: { value: input.sender ?? null, isWritable: false }, tokenXProgram: { value: input.tokenXProgram ?? null, isWritable: false }, tokenYProgram: { value: input.tokenYProgram ?? null, isWritable: false }, eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, program: { value: input.program ?? null, isWritable: false } }; const accounts = originalAccounts; // Original args. const args = { ...input, }; const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.position), getAccountMeta(accounts.lbPair), getAccountMeta(accounts.binArrayBitmapExtension), getAccountMeta(accounts.userTokenX), getAccountMeta(accounts.userTokenY), getAccountMeta(accounts.reserveX), getAccountMeta(accounts.reserveY), getAccountMeta(accounts.tokenXMint), getAccountMeta(accounts.tokenYMint), getAccountMeta(accounts.binArrayLower), getAccountMeta(accounts.binArrayUpper), getAccountMeta(accounts.sender), getAccountMeta(accounts.tokenXProgram), getAccountMeta(accounts.tokenYProgram), getAccountMeta(accounts.eventAuthority), getAccountMeta(accounts.program)], data: getRemoveLiquidityByRangeInstructionDataEncoder().encode(args), programAddress }); } function parseRemoveLiquidityByRangeInstruction(instruction) { if (instruction.accounts.length < 16) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === programs_1.LB_CLMM_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { position: getNextAccount(), lbPair: getNextAccount(), binArrayBitmapExtension: getNextOptionalAccount(), userTokenX: getNextAccount(), userTokenY: getNextAccount(), reserveX: getNextAccount(), reserveY: getNextAccount(), tokenXMint: getNextAccount(), tokenYMint: getNextAccount(), binArrayLower: getNextAccount(), binArrayUpper: getNextAccount(), sender: getNextAccount(), tokenXProgram: getNextAccount(), tokenYProgram: getNextAccount(), eventAuthority: getNextAccount(), program: getNextAccount() }, data: getRemoveLiquidityByRangeInstructionDataDecoder().decode(instruction.data) }; } //# sourceMappingURL=removeLiquidityByRange.js.map