UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

59 lines 4.23 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_ROUTER_BASE_IN_DISCRIMINATOR = void 0; exports.getSwapRouterBaseInDiscriminatorBytes = getSwapRouterBaseInDiscriminatorBytes; exports.getSwapRouterBaseInInstructionDataEncoder = getSwapRouterBaseInInstructionDataEncoder; exports.getSwapRouterBaseInInstructionDataDecoder = getSwapRouterBaseInInstructionDataDecoder; exports.getSwapRouterBaseInInstructionDataCodec = getSwapRouterBaseInInstructionDataCodec; exports.getSwapRouterBaseInInstruction = getSwapRouterBaseInInstruction; exports.parseSwapRouterBaseInInstruction = parseSwapRouterBaseInInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.SWAP_ROUTER_BASE_IN_DISCRIMINATOR = new Uint8Array([69, 125, 115, 218, 245, 186, 242, 196]); function getSwapRouterBaseInDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.SWAP_ROUTER_BASE_IN_DISCRIMINATOR); } function getSwapRouterBaseInInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['amountIn', (0, kit_1.getU64Encoder)()], ['amountOutMinimum', (0, kit_1.getU64Encoder)()]]), (value) => ({ ...value, discriminator: exports.SWAP_ROUTER_BASE_IN_DISCRIMINATOR })); } function getSwapRouterBaseInInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['amountIn', (0, kit_1.getU64Decoder)()], ['amountOutMinimum', (0, kit_1.getU64Decoder)()]]); } function getSwapRouterBaseInInstructionDataCodec() { return (0, kit_1.combineCodec)(getSwapRouterBaseInInstructionDataEncoder(), getSwapRouterBaseInInstructionDataDecoder()); } function getSwapRouterBaseInInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.AMM_V3_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: false }, inputTokenAccount: { value: input.inputTokenAccount ?? null, isWritable: true }, inputTokenMint: { value: input.inputTokenMint ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, tokenProgram2022: { value: input.tokenProgram2022 ?? null, isWritable: false }, memoProgram: { value: input.memoProgram ?? null, isWritable: false } }; const accounts = originalAccounts; // Original args. const args = { ...input, }; // 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.payer), getAccountMeta(accounts.inputTokenAccount), getAccountMeta(accounts.inputTokenMint), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.tokenProgram2022), getAccountMeta(accounts.memoProgram)], data: getSwapRouterBaseInInstructionDataEncoder().encode(args), programAddress }); } function parseSwapRouterBaseInInstruction(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; }; return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), inputTokenAccount: getNextAccount(), inputTokenMint: getNextAccount(), tokenProgram: getNextAccount(), tokenProgram2022: getNextAccount(), memoProgram: getNextAccount() }, data: getSwapRouterBaseInInstructionDataDecoder().decode(instruction.data) }; } //# sourceMappingURL=swapRouterBaseIn.js.map