UNPKG

@kamino-finance/kliquidity-sdk

Version:

Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol

65 lines 5.11 kB
"use strict"; /** * 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_DISCRIMINATOR = void 0; exports.getInitializePoolDiscriminatorBytes = getInitializePoolDiscriminatorBytes; exports.getInitializePoolInstructionDataEncoder = getInitializePoolInstructionDataEncoder; exports.getInitializePoolInstructionDataDecoder = getInitializePoolInstructionDataDecoder; exports.getInitializePoolInstructionDataCodec = getInitializePoolInstructionDataCodec; exports.getInitializePoolInstruction = getInitializePoolInstruction; exports.parseInitializePoolInstruction = parseInitializePoolInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.INITIALIZE_POOL_DISCRIMINATOR = new Uint8Array([95, 180, 10, 172, 84, 174, 232, 40]); function getInitializePoolDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.INITIALIZE_POOL_DISCRIMINATOR); } function getInitializePoolInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['whirlpoolBump', (0, kit_1.getU8Encoder)()], ['tickSpacing', (0, kit_1.getU16Encoder)()], ['initialSqrtPrice', (0, kit_1.getU128Encoder)()]]), (value) => ({ ...value, discriminator: exports.INITIALIZE_POOL_DISCRIMINATOR })); } function getInitializePoolInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['whirlpoolBump', (0, kit_1.getU8Decoder)()], ['tickSpacing', (0, kit_1.getU16Decoder)()], ['initialSqrtPrice', (0, kit_1.getU128Decoder)()]]); } function getInitializePoolInstructionDataCodec() { return (0, kit_1.combineCodec)(getInitializePoolInstructionDataEncoder(), getInitializePoolInstructionDataDecoder()); } function getInitializePoolInstruction(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 }, 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 }, tokenProgram: { value: input.tokenProgram ?? 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.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } 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.funder), getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.tokenVaultA), getAccountMeta(accounts.tokenVaultB), getAccountMeta(accounts.feeTier), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.rent)], data: getInitializePoolInstructionDataEncoder().encode(args), programAddress }); } function parseInitializePoolInstruction(instruction) { if (instruction.accounts.length < 11) { // 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(), funder: getNextAccount(), whirlpool: getNextAccount(), tokenVaultA: getNextAccount(), tokenVaultB: getNextAccount(), feeTier: getNextAccount(), tokenProgram: getNextAccount(), systemProgram: getNextAccount(), rent: getNextAccount() }, data: getInitializePoolInstructionDataDecoder().decode(instruction.data) }; } //# sourceMappingURL=initializePool.js.map