@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
59 lines • 4.64 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.SWAP_DISCRIMINATOR = void 0;
exports.getSwapDiscriminatorBytes = getSwapDiscriminatorBytes;
exports.getSwapInstructionDataEncoder = getSwapInstructionDataEncoder;
exports.getSwapInstructionDataDecoder = getSwapInstructionDataDecoder;
exports.getSwapInstructionDataCodec = getSwapInstructionDataCodec;
exports.getSwapInstruction = getSwapInstruction;
exports.parseSwapInstruction = parseSwapInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.SWAP_DISCRIMINATOR = new Uint8Array([248, 198, 158, 145, 225, 117, 135, 200]);
function getSwapDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.SWAP_DISCRIMINATOR); }
function getSwapInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['amount', (0, kit_1.getU64Encoder)()], ['otherAmountThreshold', (0, kit_1.getU64Encoder)()], ['sqrtPriceLimitX64', (0, kit_1.getU128Encoder)()], ['isBaseInput', (0, kit_1.getBooleanEncoder)()]]), (value) => ({ ...value, discriminator: exports.SWAP_DISCRIMINATOR }));
}
function getSwapInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['amount', (0, kit_1.getU64Decoder)()], ['otherAmountThreshold', (0, kit_1.getU64Decoder)()], ['sqrtPriceLimitX64', (0, kit_1.getU128Decoder)()], ['isBaseInput', (0, kit_1.getBooleanDecoder)()]]);
}
function getSwapInstructionDataCodec() {
return (0, kit_1.combineCodec)(getSwapInstructionDataEncoder(), getSwapInstructionDataDecoder());
}
function getSwapInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.AMM_V3_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { payer: { value: input.payer ?? null, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isWritable: false }, poolState: { value: input.poolState ?? null, isWritable: true }, inputTokenAccount: { value: input.inputTokenAccount ?? null, isWritable: true }, outputTokenAccount: { value: input.outputTokenAccount ?? null, isWritable: true }, inputVault: { value: input.inputVault ?? null, isWritable: true }, outputVault: { value: input.outputVault ?? null, isWritable: true }, observationState: { value: input.observationState ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, tickArray: { value: input.tickArray ?? null, isWritable: true } };
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.payer), getAccountMeta(accounts.ammConfig), getAccountMeta(accounts.poolState), getAccountMeta(accounts.inputTokenAccount), getAccountMeta(accounts.outputTokenAccount), getAccountMeta(accounts.inputVault), getAccountMeta(accounts.outputVault), getAccountMeta(accounts.observationState), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.tickArray)], data: getSwapInstructionDataEncoder().encode(args), programAddress });
}
function parseSwapInstruction(instruction) {
if (instruction.accounts.length < 10) {
// 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: { payer: getNextAccount(), ammConfig: getNextAccount(), poolState: getNextAccount(), inputTokenAccount: getNextAccount(), outputTokenAccount: getNextAccount(), inputVault: getNextAccount(), outputVault: getNextAccount(), observationState: getNextAccount(), tokenProgram: getNextAccount(), tickArray: getNextAccount() }, data: getSwapInstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=swap.js.map