@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
57 lines • 4.32 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.COLLECT_FEES_DISCRIMINATOR = void 0;
exports.getCollectFeesDiscriminatorBytes = getCollectFeesDiscriminatorBytes;
exports.getCollectFeesInstructionDataEncoder = getCollectFeesInstructionDataEncoder;
exports.getCollectFeesInstructionDataDecoder = getCollectFeesInstructionDataDecoder;
exports.getCollectFeesInstructionDataCodec = getCollectFeesInstructionDataCodec;
exports.getCollectFeesInstruction = getCollectFeesInstruction;
exports.parseCollectFeesInstruction = parseCollectFeesInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.COLLECT_FEES_DISCRIMINATOR = new Uint8Array([164, 152, 207, 99, 30, 186, 19, 182]);
function getCollectFeesDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.COLLECT_FEES_DISCRIMINATOR); }
function getCollectFeesInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({ ...value, discriminator: exports.COLLECT_FEES_DISCRIMINATOR }));
}
function getCollectFeesInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)]]);
}
function getCollectFeesInstructionDataCodec() {
return (0, kit_1.combineCodec)(getCollectFeesInstructionDataEncoder(), getCollectFeesInstructionDataDecoder());
}
function getCollectFeesInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.WHIRLPOOL_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { whirlpool: { value: input.whirlpool ?? null, isWritable: false }, positionAuthority: { value: input.positionAuthority ?? null, isWritable: false }, position: { value: input.position ?? null, isWritable: true }, positionTokenAccount: { value: input.positionTokenAccount ?? null, isWritable: false }, tokenOwnerAccountA: { value: input.tokenOwnerAccountA ?? null, isWritable: true }, tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, tokenOwnerAccountB: { value: input.tokenOwnerAccountB ?? null, isWritable: true }, tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false } };
const accounts = originalAccounts;
// 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.whirlpool), getAccountMeta(accounts.positionAuthority), getAccountMeta(accounts.position), getAccountMeta(accounts.positionTokenAccount), getAccountMeta(accounts.tokenOwnerAccountA), getAccountMeta(accounts.tokenVaultA), getAccountMeta(accounts.tokenOwnerAccountB), getAccountMeta(accounts.tokenVaultB), getAccountMeta(accounts.tokenProgram)], data: getCollectFeesInstructionDataEncoder().encode({}), programAddress });
}
function parseCollectFeesInstruction(instruction) {
if (instruction.accounts.length < 9) {
// 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: { whirlpool: getNextAccount(), positionAuthority: getNextAccount(), position: getNextAccount(), positionTokenAccount: getNextAccount(), tokenOwnerAccountA: getNextAccount(), tokenVaultA: getNextAccount(), tokenOwnerAccountB: getNextAccount(), tokenVaultB: getNextAccount(), tokenProgram: getNextAccount() }, data: getCollectFeesInstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=collectFees.js.map