UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

60 lines 5.7 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.ADD_LIQUIDITY_DISCRIMINATOR = void 0; exports.getAddLiquidityDiscriminatorBytes = getAddLiquidityDiscriminatorBytes; exports.getAddLiquidityInstructionDataEncoder = getAddLiquidityInstructionDataEncoder; exports.getAddLiquidityInstructionDataDecoder = getAddLiquidityInstructionDataDecoder; exports.getAddLiquidityInstructionDataCodec = getAddLiquidityInstructionDataCodec; exports.getAddLiquidityInstruction = getAddLiquidityInstruction; exports.parseAddLiquidityInstruction = parseAddLiquidityInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); const types_1 = require("../types"); exports.ADD_LIQUIDITY_DISCRIMINATOR = new Uint8Array([181, 157, 89, 67, 143, 182, 52, 72]); function getAddLiquidityDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.ADD_LIQUIDITY_DISCRIMINATOR); } function getAddLiquidityInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['amountX', (0, kit_1.getU64Encoder)()], ['amountY', (0, kit_1.getU64Encoder)()], ['binLiquidityDist', (0, kit_1.getArrayEncoder)((0, types_1.getBinLiquidityDistributionEncoder)())]]), (value) => ({ ...value, discriminator: exports.ADD_LIQUIDITY_DISCRIMINATOR })); } function getAddLiquidityInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['amountX', (0, kit_1.getU64Decoder)()], ['amountY', (0, kit_1.getU64Decoder)()], ['binLiquidityDist', (0, kit_1.getArrayDecoder)((0, types_1.getBinLiquidityDistributionDecoder)())]]); } function getAddLiquidityInstructionDataCodec() { return (0, kit_1.combineCodec)(getAddLiquidityInstructionDataEncoder(), getAddLiquidityInstructionDataDecoder()); } function getAddLiquidityInstruction(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: getAddLiquidityInstructionDataEncoder().encode(args), programAddress }); } function parseAddLiquidityInstruction(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: getAddLiquidityInstructionDataDecoder().decode(instruction.data) }; } //# sourceMappingURL=addLiquidity.js.map