@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
59 lines • 5.18 kB
JavaScript
;
/**
* 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.INCREASE_LIQUIDITY_DISCRIMINATOR = void 0;
exports.getIncreaseLiquidityDiscriminatorBytes = getIncreaseLiquidityDiscriminatorBytes;
exports.getIncreaseLiquidityInstructionDataEncoder = getIncreaseLiquidityInstructionDataEncoder;
exports.getIncreaseLiquidityInstructionDataDecoder = getIncreaseLiquidityInstructionDataDecoder;
exports.getIncreaseLiquidityInstructionDataCodec = getIncreaseLiquidityInstructionDataCodec;
exports.getIncreaseLiquidityInstruction = getIncreaseLiquidityInstruction;
exports.parseIncreaseLiquidityInstruction = parseIncreaseLiquidityInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.INCREASE_LIQUIDITY_DISCRIMINATOR = new Uint8Array([46, 156, 243, 118, 13, 205, 251, 178]);
function getIncreaseLiquidityDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.INCREASE_LIQUIDITY_DISCRIMINATOR); }
function getIncreaseLiquidityInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['liquidity', (0, kit_1.getU128Encoder)()], ['amount0Max', (0, kit_1.getU64Encoder)()], ['amount1Max', (0, kit_1.getU64Encoder)()]]), (value) => ({ ...value, discriminator: exports.INCREASE_LIQUIDITY_DISCRIMINATOR }));
}
function getIncreaseLiquidityInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['liquidity', (0, kit_1.getU128Decoder)()], ['amount0Max', (0, kit_1.getU64Decoder)()], ['amount1Max', (0, kit_1.getU64Decoder)()]]);
}
function getIncreaseLiquidityInstructionDataCodec() {
return (0, kit_1.combineCodec)(getIncreaseLiquidityInstructionDataEncoder(), getIncreaseLiquidityInstructionDataDecoder());
}
function getIncreaseLiquidityInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.AMM_V3_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { nftOwner: { value: input.nftOwner ?? null, isWritable: false }, nftAccount: { value: input.nftAccount ?? null, isWritable: false }, poolState: { value: input.poolState ?? null, isWritable: true }, protocolPosition: { value: input.protocolPosition ?? null, isWritable: true }, personalPosition: { value: input.personalPosition ?? null, isWritable: true }, tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: true }, tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: true }, tokenAccount0: { value: input.tokenAccount0 ?? null, isWritable: true }, tokenAccount1: { value: input.tokenAccount1 ?? null, isWritable: true }, tokenVault0: { value: input.tokenVault0 ?? null, isWritable: true }, tokenVault1: { value: input.tokenVault1 ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false } };
const accounts = originalAccounts;
// Original args.
const args = { ...input, };
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.nftOwner), getAccountMeta(accounts.nftAccount), getAccountMeta(accounts.poolState), getAccountMeta(accounts.protocolPosition), getAccountMeta(accounts.personalPosition), getAccountMeta(accounts.tickArrayLower), getAccountMeta(accounts.tickArrayUpper), getAccountMeta(accounts.tokenAccount0), getAccountMeta(accounts.tokenAccount1), getAccountMeta(accounts.tokenVault0), getAccountMeta(accounts.tokenVault1), getAccountMeta(accounts.tokenProgram)], data: getIncreaseLiquidityInstructionDataEncoder().encode(args), programAddress });
}
function parseIncreaseLiquidityInstruction(instruction) {
if (instruction.accounts.length < 12) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts[accountIndex];
accountIndex += 1;
return accountMeta;
};
return { programAddress: instruction.programAddress, accounts: { nftOwner: getNextAccount(), nftAccount: getNextAccount(), poolState: getNextAccount(), protocolPosition: getNextAccount(), personalPosition: getNextAccount(), tickArrayLower: getNextAccount(), tickArrayUpper: getNextAccount(), tokenAccount0: getNextAccount(), tokenAccount1: getNextAccount(), tokenVault0: getNextAccount(), tokenVault1: getNextAccount(), tokenProgram: getNextAccount() }, data: getIncreaseLiquidityInstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=increaseLiquidity.js.map