UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

56 lines 5.58 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.SWAP_V2_DISCRIMINATOR = void 0; exports.getSwapV2DiscriminatorBytes = getSwapV2DiscriminatorBytes; exports.getSwapV2InstructionDataEncoder = getSwapV2InstructionDataEncoder; exports.getSwapV2InstructionDataDecoder = getSwapV2InstructionDataDecoder; exports.getSwapV2InstructionDataCodec = getSwapV2InstructionDataCodec; exports.getSwapV2Instruction = getSwapV2Instruction; exports.parseSwapV2Instruction = parseSwapV2Instruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); const types_1 = require("../types"); exports.SWAP_V2_DISCRIMINATOR = new Uint8Array([43, 4, 237, 11, 26, 201, 30, 98]); function getSwapV2DiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.SWAP_V2_DISCRIMINATOR); } function getSwapV2InstructionDataEncoder() { 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)()], ['sqrtPriceLimit', (0, kit_1.getU128Encoder)()], ['amountSpecifiedIsInput', (0, kit_1.getBooleanEncoder)()], ['aToB', (0, kit_1.getBooleanEncoder)()], ['remainingAccountsInfo', (0, kit_1.getOptionEncoder)((0, types_1.getRemainingAccountsInfoEncoder)())]]), (value) => ({ ...value, discriminator: exports.SWAP_V2_DISCRIMINATOR })); } function getSwapV2InstructionDataDecoder() { 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)()], ['sqrtPriceLimit', (0, kit_1.getU128Decoder)()], ['amountSpecifiedIsInput', (0, kit_1.getBooleanDecoder)()], ['aToB', (0, kit_1.getBooleanDecoder)()], ['remainingAccountsInfo', (0, kit_1.getOptionDecoder)((0, types_1.getRemainingAccountsInfoDecoder)())]]); } function getSwapV2InstructionDataCodec() { return (0, kit_1.combineCodec)(getSwapV2InstructionDataEncoder(), getSwapV2InstructionDataDecoder()); } function getSwapV2Instruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, memoProgram: { value: input.memoProgram ?? null, isWritable: false }, tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, whirlpool: { value: input.whirlpool ?? null, isWritable: true }, tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, tokenMintB: { value: input.tokenMintB ?? 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 }, tickArray0: { value: input.tickArray0 ?? null, isWritable: true }, tickArray1: { value: input.tickArray1 ?? null, isWritable: true }, tickArray2: { value: input.tickArray2 ?? null, isWritable: true }, oracle: { value: input.oracle ?? null, isWritable: true } }; const accounts = originalAccounts; // Original args. const args = { ...input, }; const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta(accounts.tokenProgramA), getAccountMeta(accounts.tokenProgramB), getAccountMeta(accounts.memoProgram), getAccountMeta(accounts.tokenAuthority), getAccountMeta(accounts.whirlpool), getAccountMeta(accounts.tokenMintA), getAccountMeta(accounts.tokenMintB), getAccountMeta(accounts.tokenOwnerAccountA), getAccountMeta(accounts.tokenVaultA), getAccountMeta(accounts.tokenOwnerAccountB), getAccountMeta(accounts.tokenVaultB), getAccountMeta(accounts.tickArray0), getAccountMeta(accounts.tickArray1), getAccountMeta(accounts.tickArray2), getAccountMeta(accounts.oracle)], data: getSwapV2InstructionDataEncoder().encode(args), programAddress }); } function parseSwapV2Instruction(instruction) { if (instruction.accounts.length < 15) { // 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: { tokenProgramA: getNextAccount(), tokenProgramB: getNextAccount(), memoProgram: getNextAccount(), tokenAuthority: getNextAccount(), whirlpool: getNextAccount(), tokenMintA: getNextAccount(), tokenMintB: getNextAccount(), tokenOwnerAccountA: getNextAccount(), tokenVaultA: getNextAccount(), tokenOwnerAccountB: getNextAccount(), tokenVaultB: getNextAccount(), tickArray0: getNextAccount(), tickArray1: getNextAccount(), tickArray2: getNextAccount(), oracle: getNextAccount() }, data: getSwapV2InstructionDataDecoder().decode(instruction.data) }; } //# sourceMappingURL=swapV2.js.map