@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
59 lines • 6.74 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.TWO_HOP_SWAP_DISCRIMINATOR = void 0;
exports.getTwoHopSwapDiscriminatorBytes = getTwoHopSwapDiscriminatorBytes;
exports.getTwoHopSwapInstructionDataEncoder = getTwoHopSwapInstructionDataEncoder;
exports.getTwoHopSwapInstructionDataDecoder = getTwoHopSwapInstructionDataDecoder;
exports.getTwoHopSwapInstructionDataCodec = getTwoHopSwapInstructionDataCodec;
exports.getTwoHopSwapInstruction = getTwoHopSwapInstruction;
exports.parseTwoHopSwapInstruction = parseTwoHopSwapInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.TWO_HOP_SWAP_DISCRIMINATOR = new Uint8Array([195, 96, 237, 108, 68, 162, 219, 230]);
function getTwoHopSwapDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.TWO_HOP_SWAP_DISCRIMINATOR); }
function getTwoHopSwapInstructionDataEncoder() {
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)()], ['amountSpecifiedIsInput', (0, kit_1.getBooleanEncoder)()], ['aToBOne', (0, kit_1.getBooleanEncoder)()], ['aToBTwo', (0, kit_1.getBooleanEncoder)()], ['sqrtPriceLimitOne', (0, kit_1.getU128Encoder)()], ['sqrtPriceLimitTwo', (0, kit_1.getU128Encoder)()]]), (value) => ({ ...value, discriminator: exports.TWO_HOP_SWAP_DISCRIMINATOR }));
}
function getTwoHopSwapInstructionDataDecoder() {
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)()], ['amountSpecifiedIsInput', (0, kit_1.getBooleanDecoder)()], ['aToBOne', (0, kit_1.getBooleanDecoder)()], ['aToBTwo', (0, kit_1.getBooleanDecoder)()], ['sqrtPriceLimitOne', (0, kit_1.getU128Decoder)()], ['sqrtPriceLimitTwo', (0, kit_1.getU128Decoder)()]]);
}
function getTwoHopSwapInstructionDataCodec() {
return (0, kit_1.combineCodec)(getTwoHopSwapInstructionDataEncoder(), getTwoHopSwapInstructionDataDecoder());
}
function getTwoHopSwapInstruction(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 }, whirlpoolOne: { value: input.whirlpoolOne ?? null, isWritable: true }, whirlpoolTwo: { value: input.whirlpoolTwo ?? null, isWritable: true }, tokenOwnerAccountOneA: { value: input.tokenOwnerAccountOneA ?? null, isWritable: true }, tokenVaultOneA: { value: input.tokenVaultOneA ?? null, isWritable: true }, tokenOwnerAccountOneB: { value: input.tokenOwnerAccountOneB ?? null, isWritable: true }, tokenVaultOneB: { value: input.tokenVaultOneB ?? null, isWritable: true }, tokenOwnerAccountTwoA: { value: input.tokenOwnerAccountTwoA ?? null, isWritable: true }, tokenVaultTwoA: { value: input.tokenVaultTwoA ?? null, isWritable: true }, tokenOwnerAccountTwoB: { value: input.tokenOwnerAccountTwoB ?? null, isWritable: true }, tokenVaultTwoB: { value: input.tokenVaultTwoB ?? null, isWritable: true }, tickArrayOne0: { value: input.tickArrayOne0 ?? null, isWritable: true }, tickArrayOne1: { value: input.tickArrayOne1 ?? null, isWritable: true }, tickArrayOne2: { value: input.tickArrayOne2 ?? null, isWritable: true }, tickArrayTwo0: { value: input.tickArrayTwo0 ?? null, isWritable: true }, tickArrayTwo1: { value: input.tickArrayTwo1 ?? null, isWritable: true }, tickArrayTwo2: { value: input.tickArrayTwo2 ?? null, isWritable: true }, oracleOne: { value: input.oracleOne ?? null, isWritable: false }, oracleTwo: { value: input.oracleTwo ?? 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.whirlpoolOne), getAccountMeta(accounts.whirlpoolTwo), getAccountMeta(accounts.tokenOwnerAccountOneA), getAccountMeta(accounts.tokenVaultOneA), getAccountMeta(accounts.tokenOwnerAccountOneB), getAccountMeta(accounts.tokenVaultOneB), getAccountMeta(accounts.tokenOwnerAccountTwoA), getAccountMeta(accounts.tokenVaultTwoA), getAccountMeta(accounts.tokenOwnerAccountTwoB), getAccountMeta(accounts.tokenVaultTwoB), getAccountMeta(accounts.tickArrayOne0), getAccountMeta(accounts.tickArrayOne1), getAccountMeta(accounts.tickArrayOne2), getAccountMeta(accounts.tickArrayTwo0), getAccountMeta(accounts.tickArrayTwo1), getAccountMeta(accounts.tickArrayTwo2), getAccountMeta(accounts.oracleOne), getAccountMeta(accounts.oracleTwo)], data: getTwoHopSwapInstructionDataEncoder().encode(args), programAddress });
}
function parseTwoHopSwapInstruction(instruction) {
if (instruction.accounts.length < 20) {
// 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(), whirlpoolOne: getNextAccount(), whirlpoolTwo: getNextAccount(), tokenOwnerAccountOneA: getNextAccount(), tokenVaultOneA: getNextAccount(), tokenOwnerAccountOneB: getNextAccount(), tokenVaultOneB: getNextAccount(), tokenOwnerAccountTwoA: getNextAccount(), tokenVaultTwoA: getNextAccount(), tokenOwnerAccountTwoB: getNextAccount(), tokenVaultTwoB: getNextAccount(), tickArrayOne0: getNextAccount(), tickArrayOne1: getNextAccount(), tickArrayOne2: getNextAccount(), tickArrayTwo0: getNextAccount(), tickArrayTwo1: getNextAccount(), tickArrayTwo2: getNextAccount(), oracleOne: getNextAccount(), oracleTwo: getNextAccount() }, data: getTwoHopSwapInstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=twoHopSwap.js.map