@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
62 lines • 5.37 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.INITIALIZE_POOL_V2_DISCRIMINATOR = void 0;
exports.getInitializePoolV2DiscriminatorBytes = getInitializePoolV2DiscriminatorBytes;
exports.getInitializePoolV2InstructionDataEncoder = getInitializePoolV2InstructionDataEncoder;
exports.getInitializePoolV2InstructionDataDecoder = getInitializePoolV2InstructionDataDecoder;
exports.getInitializePoolV2InstructionDataCodec = getInitializePoolV2InstructionDataCodec;
exports.getInitializePoolV2Instruction = getInitializePoolV2Instruction;
exports.parseInitializePoolV2Instruction = parseInitializePoolV2Instruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.INITIALIZE_POOL_V2_DISCRIMINATOR = new Uint8Array([207, 45, 87, 242, 27, 63, 204, 67]);
function getInitializePoolV2DiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.INITIALIZE_POOL_V2_DISCRIMINATOR); }
function getInitializePoolV2InstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['tickSpacing', (0, kit_1.getU16Encoder)()], ['initialSqrtPrice', (0, kit_1.getU128Encoder)()]]), (value) => ({ ...value, discriminator: exports.INITIALIZE_POOL_V2_DISCRIMINATOR }));
}
function getInitializePoolV2InstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['tickSpacing', (0, kit_1.getU16Decoder)()], ['initialSqrtPrice', (0, kit_1.getU128Decoder)()]]);
}
function getInitializePoolV2InstructionDataCodec() {
return (0, kit_1.combineCodec)(getInitializePoolV2InstructionDataEncoder(), getInitializePoolV2InstructionDataDecoder());
}
function getInitializePoolV2Instruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.WHIRLPOOL_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { whirlpoolsConfig: { value: input.whirlpoolsConfig ?? null, isWritable: false }, tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, tokenBadgeA: { value: input.tokenBadgeA ?? null, isWritable: false }, tokenBadgeB: { value: input.tokenBadgeB ?? null, isWritable: false }, funder: { value: input.funder ?? null, isWritable: true }, whirlpool: { value: input.whirlpool ?? null, isWritable: true }, tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, feeTier: { value: input.feeTier ?? null, isWritable: false }, tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, rent: { value: input.rent ?? null, isWritable: false } };
const accounts = originalAccounts;
// Original args.
const args = { ...input, };
// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value = '11111111111111111111111111111111';
}
if (!accounts.rent.value) {
accounts.rent.value = 'SysvarRent111111111111111111111111111111111';
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.whirlpoolsConfig), getAccountMeta(accounts.tokenMintA), getAccountMeta(accounts.tokenMintB), getAccountMeta(accounts.tokenBadgeA), getAccountMeta(accounts.tokenBadgeB), getAccountMeta(accounts.funder), getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.tokenVaultA), getAccountMeta(accounts.tokenVaultB), getAccountMeta(accounts.feeTier), getAccountMeta(accounts.tokenProgramA), getAccountMeta(accounts.tokenProgramB), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent)], data: getInitializePoolV2InstructionDataEncoder().encode(args), programAddress });
}
function parseInitializePoolV2Instruction(instruction) {
if (instruction.accounts.length < 14) {
// 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: { whirlpoolsConfig: getNextAccount(), tokenMintA: getNextAccount(), tokenMintB: getNextAccount(), tokenBadgeA: getNextAccount(), tokenBadgeB: getNextAccount(), funder: getNextAccount(), whirlpool: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), feeTier: getNextAccount(), tokenProgramA: getNextAccount(), tokenProgramB: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount() }, data: getInitializePoolV2InstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=initializePoolV2.js.map