@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
62 lines • 6.68 kB
JavaScript
"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.DEPOSIT_DISCRIMINATOR = void 0;
exports.getDepositDiscriminatorBytes = getDepositDiscriminatorBytes;
exports.getDepositInstructionDataEncoder = getDepositInstructionDataEncoder;
exports.getDepositInstructionDataDecoder = getDepositInstructionDataDecoder;
exports.getDepositInstructionDataCodec = getDepositInstructionDataCodec;
exports.getDepositInstruction = getDepositInstruction;
exports.parseDepositInstruction = parseDepositInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.DEPOSIT_DISCRIMINATOR = new Uint8Array([242, 35, 198, 137, 82, 225, 242, 182]);
function getDepositDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.DEPOSIT_DISCRIMINATOR); }
function getDepositInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['tokenMaxA', (0, kit_1.getU64Encoder)()], ['tokenMaxB', (0, kit_1.getU64Encoder)()]]), (value) => ({ ...value, discriminator: exports.DEPOSIT_DISCRIMINATOR }));
}
function getDepositInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['tokenMaxA', (0, kit_1.getU64Decoder)()], ['tokenMaxB', (0, kit_1.getU64Decoder)()]]);
}
function getDepositInstructionDataCodec() {
return (0, kit_1.combineCodec)(getDepositInstructionDataEncoder(), getDepositInstructionDataDecoder());
}
function getDepositInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.YVAULTS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { user: { value: input.user ?? null, isWritable: true }, strategy: { value: input.strategy ?? null, isWritable: true }, globalConfig: { value: input.globalConfig ?? null, isWritable: false }, pool: { value: input.pool ?? null, isWritable: false }, position: { value: input.position ?? null, isWritable: false }, tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: false }, tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: false }, tokenAVault: { value: input.tokenAVault ?? null, isWritable: true }, tokenBVault: { value: input.tokenBVault ?? null, isWritable: true }, baseVaultAuthority: { value: input.baseVaultAuthority ?? null, isWritable: false }, tokenAAta: { value: input.tokenAAta ?? null, isWritable: true }, tokenBAta: { value: input.tokenBAta ?? null, isWritable: true }, tokenAMint: { value: input.tokenAMint ?? null, isWritable: false }, tokenBMint: { value: input.tokenBMint ?? null, isWritable: false }, userSharesAta: { value: input.userSharesAta ?? null, isWritable: true }, sharesMint: { value: input.sharesMint ?? null, isWritable: true }, sharesMintAuthority: { value: input.sharesMintAuthority ?? null, isWritable: false }, scopePricesA: { value: input.scopePricesA ?? null, isWritable: false }, scopePricesB: { value: input.scopePricesB ?? null, isWritable: false }, tokenInfos: { value: input.tokenInfos ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, tokenATokenProgram: { value: input.tokenATokenProgram ?? null, isWritable: false }, tokenBTokenProgram: { value: input.tokenBTokenProgram ?? null, isWritable: false }, instructionSysvarAccount: { value: input.instructionSysvarAccount ?? null, isWritable: false } };
const accounts = originalAccounts;
// Original args.
const args = { ...input, };
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
if (!accounts.instructionSysvarAccount.value) {
accounts.instructionSysvarAccount.value = 'Sysvar1nstructions1111111111111111111111111';
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.user), getAccountMeta(accounts.strategy), getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.pool), getAccountMeta(accounts.position), getAccountMeta(accounts.tickArrayLower), getAccountMeta(accounts.tickArrayUpper), getAccountMeta(accounts.tokenAVault), getAccountMeta(accounts.tokenBVault), getAccountMeta(accounts.baseVaultAuthority), getAccountMeta(accounts.tokenAAta), getAccountMeta(accounts.tokenBAta), getAccountMeta(accounts.tokenAMint), getAccountMeta(accounts.tokenBMint), getAccountMeta(accounts.userSharesAta), getAccountMeta(accounts.sharesMint), getAccountMeta(accounts.sharesMintAuthority), getAccountMeta(accounts.scopePricesA), getAccountMeta(accounts.scopePricesB), getAccountMeta(accounts.tokenInfos), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.tokenATokenProgram), getAccountMeta(accounts.tokenBTokenProgram), getAccountMeta(accounts.instructionSysvarAccount)], data: getDepositInstructionDataEncoder().encode(args), programAddress });
}
function parseDepositInstruction(instruction) {
if (instruction.accounts.length < 24) {
// 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: { user: getNextAccount(), strategy: getNextAccount(), globalConfig: getNextAccount(), pool: getNextAccount(), position: getNextAccount(), tickArrayLower: getNextAccount(), tickArrayUpper: getNextAccount(), tokenAVault: getNextAccount(), tokenBVault: getNextAccount(), baseVaultAuthority: getNextAccount(), tokenAAta: getNextAccount(), tokenBAta: getNextAccount(), tokenAMint: getNextAccount(), tokenBMint: getNextAccount(), userSharesAta: getNextAccount(), sharesMint: getNextAccount(), sharesMintAuthority: getNextAccount(), scopePricesA: getNextAccount(), scopePricesB: getNextAccount(), tokenInfos: getNextAccount(), tokenProgram: getNextAccount(), tokenATokenProgram: getNextAccount(), tokenBTokenProgram: getNextAccount(), instructionSysvarAccount: getNextAccount() }, data: getDepositInstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=deposit.js.map