@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
59 lines • 3.95 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.GO_TO_A_BIN_DISCRIMINATOR = void 0;
exports.getGoToABinDiscriminatorBytes = getGoToABinDiscriminatorBytes;
exports.getGoToABinInstructionDataEncoder = getGoToABinInstructionDataEncoder;
exports.getGoToABinInstructionDataDecoder = getGoToABinInstructionDataDecoder;
exports.getGoToABinInstructionDataCodec = getGoToABinInstructionDataCodec;
exports.getGoToABinInstruction = getGoToABinInstruction;
exports.parseGoToABinInstruction = parseGoToABinInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.GO_TO_A_BIN_DISCRIMINATOR = new Uint8Array([146, 72, 174, 224, 40, 253, 84, 174]);
function getGoToABinDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.GO_TO_A_BIN_DISCRIMINATOR); }
function getGoToABinInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['binId', (0, kit_1.getI32Encoder)()]]), (value) => ({ ...value, discriminator: exports.GO_TO_A_BIN_DISCRIMINATOR }));
}
function getGoToABinInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['binId', (0, kit_1.getI32Decoder)()]]);
}
function getGoToABinInstructionDataCodec() {
return (0, kit_1.combineCodec)(getGoToABinInstructionDataEncoder(), getGoToABinInstructionDataDecoder());
}
function getGoToABinInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.LB_CLMM_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { lbPair: { value: input.lbPair ?? null, isWritable: true }, binArrayBitmapExtension: { value: input.binArrayBitmapExtension ?? null, isWritable: false }, fromBinArray: { value: input.fromBinArray ?? null, isWritable: false }, toBinArray: { value: input.toBinArray ?? 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.lbPair), getAccountMeta(accounts.binArrayBitmapExtension), getAccountMeta(accounts.fromBinArray), getAccountMeta(accounts.toBinArray), getAccountMeta(accounts.eventAuthority), getAccountMeta(accounts.program)], data: getGoToABinInstructionDataEncoder().encode(args), programAddress });
}
function parseGoToABinInstruction(instruction) {
if (instruction.accounts.length < 6) {
// 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: { lbPair: getNextAccount(), binArrayBitmapExtension: getNextOptionalAccount(), fromBinArray: getNextOptionalAccount(), toBinArray: getNextOptionalAccount(), eventAuthority: getNextAccount(), program: getNextAccount() }, data: getGoToABinInstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=goToABin.js.map