UNPKG

@kamino-finance/kliquidity-sdk

Version:

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

59 lines 4.89 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_DISCRIMINATOR = void 0; exports.getSwapDiscriminatorBytes = getSwapDiscriminatorBytes; exports.getSwapInstructionDataEncoder = getSwapInstructionDataEncoder; exports.getSwapInstructionDataDecoder = getSwapInstructionDataDecoder; exports.getSwapInstructionDataCodec = getSwapInstructionDataCodec; exports.getSwapInstruction = getSwapInstruction; exports.parseSwapInstruction = parseSwapInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.SWAP_DISCRIMINATOR = new Uint8Array([248, 198, 158, 145, 225, 117, 135, 200]); function getSwapDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.SWAP_DISCRIMINATOR); } function getSwapInstructionDataEncoder() { 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)()]]), (value) => ({ ...value, discriminator: exports.SWAP_DISCRIMINATOR })); } function getSwapInstructionDataDecoder() { 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)()]]); } function getSwapInstructionDataCodec() { return (0, kit_1.combineCodec)(getSwapInstructionDataEncoder(), getSwapInstructionDataDecoder()); } function getSwapInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.WHIRLPOOL_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, whirlpool: { value: input.whirlpool ?? null, isWritable: true }, 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: 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.tokenProgram), getAccountMeta(accounts.tokenAuthority), getAccountMeta(accounts.whirlpool), 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: getSwapInstructionDataEncoder().encode(args), programAddress }); } function parseSwapInstruction(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: { tokenProgram: getNextAccount(), tokenAuthority: getNextAccount(), whirlpool: getNextAccount(), tokenOwnerAccountA: getNextAccount(), tokenVaultA: getNextAccount(), tokenOwnerAccountB: getNextAccount(), tokenVaultB: getNextAccount(), tickArray0: getNextAccount(), tickArray1: getNextAccount(), tickArray2: getNextAccount(), oracle: getNextAccount() }, data: getSwapInstructionDataDecoder().decode(instruction.data) }; } //# sourceMappingURL=swap.js.map