@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
55 lines • 6.33 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.EMERGENCY_SWAP_DISCRIMINATOR = void 0;
exports.getEmergencySwapDiscriminatorBytes = getEmergencySwapDiscriminatorBytes;
exports.getEmergencySwapInstructionDataEncoder = getEmergencySwapInstructionDataEncoder;
exports.getEmergencySwapInstructionDataDecoder = getEmergencySwapInstructionDataDecoder;
exports.getEmergencySwapInstructionDataCodec = getEmergencySwapInstructionDataCodec;
exports.getEmergencySwapInstruction = getEmergencySwapInstruction;
exports.parseEmergencySwapInstruction = parseEmergencySwapInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.EMERGENCY_SWAP_DISCRIMINATOR = new Uint8Array([73, 226, 248, 215, 5, 197, 211, 229]);
function getEmergencySwapDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.EMERGENCY_SWAP_DISCRIMINATOR); }
function getEmergencySwapInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['aToB', (0, kit_1.getBooleanEncoder)()], ['targetLimitBps', (0, kit_1.getU64Encoder)()]]), (value) => ({ ...value, discriminator: exports.EMERGENCY_SWAP_DISCRIMINATOR }));
}
function getEmergencySwapInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['aToB', (0, kit_1.getBooleanDecoder)()], ['targetLimitBps', (0, kit_1.getU64Decoder)()]]);
}
function getEmergencySwapInstructionDataCodec() {
return (0, kit_1.combineCodec)(getEmergencySwapInstructionDataEncoder(), getEmergencySwapInstructionDataDecoder());
}
function getEmergencySwapInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.YVAULTS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = { adminAuthority: { value: input.adminAuthority ?? null, isWritable: true }, strategy: { value: input.strategy ?? null, isWritable: true }, globalConfig: { value: input.globalConfig ?? null, isWritable: false }, tokenAMint: { value: input.tokenAMint ?? null, isWritable: false }, tokenBMint: { value: input.tokenBMint ?? null, isWritable: false }, tokenAVault: { value: input.tokenAVault ?? null, isWritable: true }, tokenBVault: { value: input.tokenBVault ?? null, isWritable: true }, baseVaultAuthority: { value: input.baseVaultAuthority ?? null, isWritable: true }, pool: { value: input.pool ?? null, isWritable: true }, position: { value: input.position ?? null, isWritable: true }, poolTokenVaultA: { value: input.poolTokenVaultA ?? null, isWritable: true }, poolTokenVaultB: { value: input.poolTokenVaultB ?? 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 }, poolProgram: { value: input.poolProgram ?? null, isWritable: false }, scopePricesA: { value: input.scopePricesA ?? null, isWritable: false }, scopePricesB: { value: input.scopePricesB ?? null, isWritable: false }, tokenInfos: { value: input.tokenInfos ?? null, isWritable: false }, tokenATokenProgram: { value: input.tokenATokenProgram ?? null, isWritable: false }, tokenBTokenProgram: { value: input.tokenBTokenProgram ?? null, isWritable: false }, memoProgram: { value: input.memoProgram ?? null, isWritable: false } };
const accounts = originalAccounts;
// Original args.
const args = { ...input, };
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({ accounts: [getAccountMeta(accounts.adminAuthority), getAccountMeta(accounts.strategy), getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.tokenAMint), getAccountMeta(accounts.tokenBMint), getAccountMeta(accounts.tokenAVault), getAccountMeta(accounts.tokenBVault), getAccountMeta(accounts.baseVaultAuthority), getAccountMeta(accounts.pool), getAccountMeta(accounts.position), getAccountMeta(accounts.poolTokenVaultA), getAccountMeta(accounts.poolTokenVaultB), getAccountMeta(accounts.tickArray0), getAccountMeta(accounts.tickArray1), getAccountMeta(accounts.tickArray2), getAccountMeta(accounts.oracle), getAccountMeta(accounts.poolProgram), getAccountMeta(accounts.scopePricesA), getAccountMeta(accounts.scopePricesB), getAccountMeta(accounts.tokenInfos), getAccountMeta(accounts.tokenATokenProgram), getAccountMeta(accounts.tokenBTokenProgram), getAccountMeta(accounts.memoProgram)], data: getEmergencySwapInstructionDataEncoder().encode(args), programAddress });
}
function parseEmergencySwapInstruction(instruction) {
if (instruction.accounts.length < 23) {
// 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: { adminAuthority: getNextAccount(), strategy: getNextAccount(), globalConfig: getNextAccount(), tokenAMint: getNextAccount(), tokenBMint: getNextAccount(), tokenAVault: getNextAccount(), tokenBVault: getNextAccount(), baseVaultAuthority: getNextAccount(), pool: getNextAccount(), position: getNextAccount(), poolTokenVaultA: getNextAccount(), poolTokenVaultB: getNextAccount(), tickArray0: getNextAccount(), tickArray1: getNextAccount(), tickArray2: getNextAccount(), oracle: getNextAccount(), poolProgram: getNextAccount(), scopePricesA: getNextAccount(), scopePricesB: getNextAccount(), tokenInfos: getNextAccount(), tokenATokenProgram: getNextAccount(), tokenBTokenProgram: getNextAccount(), memoProgram: getNextAccount() }, data: getEmergencySwapInstructionDataDecoder().decode(instruction.data) };
}
//# sourceMappingURL=emergencySwap.js.map