@kamino-finance/kliquidity-sdk
Version:
Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol
318 lines • 14.4 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PoolState = void 0;
/* eslint-disable @typescript-eslint/no-unused-vars */
const kit_1 = require("@solana/kit");
/* eslint-enable @typescript-eslint/no-unused-vars */
const bn_js_1 = __importDefault(require("bn.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
const utils_1 = require("../utils"); // eslint-disable-line @typescript-eslint/no-unused-vars
const types = __importStar(require("../types")); // eslint-disable-line @typescript-eslint/no-unused-vars
const programId_1 = require("../programId");
class PoolState {
bump;
ammConfig;
owner;
tokenMint0;
tokenMint1;
tokenVault0;
tokenVault1;
observationKey;
mintDecimals0;
mintDecimals1;
tickSpacing;
liquidity;
sqrtPriceX64;
tickCurrent;
observationIndex;
observationUpdateDuration;
feeGrowthGlobal0X64;
feeGrowthGlobal1X64;
protocolFeesToken0;
protocolFeesToken1;
swapInAmountToken0;
swapOutAmountToken1;
swapInAmountToken1;
swapOutAmountToken0;
status;
padding;
rewardInfos;
tickArrayBitmap;
totalFeesToken0;
totalFeesClaimedToken0;
totalFeesToken1;
totalFeesClaimedToken1;
fundFeesToken0;
fundFeesToken1;
openTime;
padding1;
padding2;
static discriminator = Buffer.from([
247, 237, 227, 245, 215, 195, 222, 70,
]);
static layout = borsh.struct([
borsh.array(borsh.u8(), 1, "bump"),
(0, utils_1.borshAddress)("ammConfig"),
(0, utils_1.borshAddress)("owner"),
(0, utils_1.borshAddress)("tokenMint0"),
(0, utils_1.borshAddress)("tokenMint1"),
(0, utils_1.borshAddress)("tokenVault0"),
(0, utils_1.borshAddress)("tokenVault1"),
(0, utils_1.borshAddress)("observationKey"),
borsh.u8("mintDecimals0"),
borsh.u8("mintDecimals1"),
borsh.u16("tickSpacing"),
borsh.u128("liquidity"),
borsh.u128("sqrtPriceX64"),
borsh.i32("tickCurrent"),
borsh.u16("observationIndex"),
borsh.u16("observationUpdateDuration"),
borsh.u128("feeGrowthGlobal0X64"),
borsh.u128("feeGrowthGlobal1X64"),
borsh.u64("protocolFeesToken0"),
borsh.u64("protocolFeesToken1"),
borsh.u128("swapInAmountToken0"),
borsh.u128("swapOutAmountToken1"),
borsh.u128("swapInAmountToken1"),
borsh.u128("swapOutAmountToken0"),
borsh.u8("status"),
borsh.array(borsh.u8(), 7, "padding"),
borsh.array(types.RewardInfo.layout(), 3, "rewardInfos"),
borsh.array(borsh.u64(), 16, "tickArrayBitmap"),
borsh.u64("totalFeesToken0"),
borsh.u64("totalFeesClaimedToken0"),
borsh.u64("totalFeesToken1"),
borsh.u64("totalFeesClaimedToken1"),
borsh.u64("fundFeesToken0"),
borsh.u64("fundFeesToken1"),
borsh.u64("openTime"),
borsh.array(borsh.u64(), 25, "padding1"),
borsh.array(borsh.u64(), 32, "padding2"),
]);
constructor(fields) {
this.bump = fields.bump;
this.ammConfig = fields.ammConfig;
this.owner = fields.owner;
this.tokenMint0 = fields.tokenMint0;
this.tokenMint1 = fields.tokenMint1;
this.tokenVault0 = fields.tokenVault0;
this.tokenVault1 = fields.tokenVault1;
this.observationKey = fields.observationKey;
this.mintDecimals0 = fields.mintDecimals0;
this.mintDecimals1 = fields.mintDecimals1;
this.tickSpacing = fields.tickSpacing;
this.liquidity = fields.liquidity;
this.sqrtPriceX64 = fields.sqrtPriceX64;
this.tickCurrent = fields.tickCurrent;
this.observationIndex = fields.observationIndex;
this.observationUpdateDuration = fields.observationUpdateDuration;
this.feeGrowthGlobal0X64 = fields.feeGrowthGlobal0X64;
this.feeGrowthGlobal1X64 = fields.feeGrowthGlobal1X64;
this.protocolFeesToken0 = fields.protocolFeesToken0;
this.protocolFeesToken1 = fields.protocolFeesToken1;
this.swapInAmountToken0 = fields.swapInAmountToken0;
this.swapOutAmountToken1 = fields.swapOutAmountToken1;
this.swapInAmountToken1 = fields.swapInAmountToken1;
this.swapOutAmountToken0 = fields.swapOutAmountToken0;
this.status = fields.status;
this.padding = fields.padding;
this.rewardInfos = fields.rewardInfos.map((item) => new types.RewardInfo({ ...item }));
this.tickArrayBitmap = fields.tickArrayBitmap;
this.totalFeesToken0 = fields.totalFeesToken0;
this.totalFeesClaimedToken0 = fields.totalFeesClaimedToken0;
this.totalFeesToken1 = fields.totalFeesToken1;
this.totalFeesClaimedToken1 = fields.totalFeesClaimedToken1;
this.fundFeesToken0 = fields.fundFeesToken0;
this.fundFeesToken1 = fields.fundFeesToken1;
this.openTime = fields.openTime;
this.padding1 = fields.padding1;
this.padding2 = fields.padding2;
}
static async fetch(rpc, address, programId = programId_1.PROGRAM_ID) {
const info = await (0, kit_1.fetchEncodedAccount)(rpc, address);
if (!info.exists) {
return null;
}
if (info.programAddress !== programId) {
throw new Error("account doesn't belong to this program");
}
return this.decode(Buffer.from(info.data));
}
static async fetchMultiple(rpc, addresses, programId = programId_1.PROGRAM_ID) {
const infos = await (0, kit_1.fetchEncodedAccounts)(rpc, addresses);
return infos.map((info) => {
if (!info.exists) {
return null;
}
if (info.programAddress !== programId) {
throw new Error("account doesn't belong to this program");
}
return this.decode(Buffer.from(info.data));
});
}
static decode(data) {
if (!data.slice(0, 8).equals(PoolState.discriminator)) {
throw new Error("invalid account discriminator");
}
const dec = PoolState.layout.decode(data.slice(8));
return new PoolState({
bump: dec.bump,
ammConfig: dec.ammConfig,
owner: dec.owner,
tokenMint0: dec.tokenMint0,
tokenMint1: dec.tokenMint1,
tokenVault0: dec.tokenVault0,
tokenVault1: dec.tokenVault1,
observationKey: dec.observationKey,
mintDecimals0: dec.mintDecimals0,
mintDecimals1: dec.mintDecimals1,
tickSpacing: dec.tickSpacing,
liquidity: dec.liquidity,
sqrtPriceX64: dec.sqrtPriceX64,
tickCurrent: dec.tickCurrent,
observationIndex: dec.observationIndex,
observationUpdateDuration: dec.observationUpdateDuration,
feeGrowthGlobal0X64: dec.feeGrowthGlobal0X64,
feeGrowthGlobal1X64: dec.feeGrowthGlobal1X64,
protocolFeesToken0: dec.protocolFeesToken0,
protocolFeesToken1: dec.protocolFeesToken1,
swapInAmountToken0: dec.swapInAmountToken0,
swapOutAmountToken1: dec.swapOutAmountToken1,
swapInAmountToken1: dec.swapInAmountToken1,
swapOutAmountToken0: dec.swapOutAmountToken0,
status: dec.status,
padding: dec.padding,
rewardInfos: dec.rewardInfos.map((item /* eslint-disable-line @typescript-eslint/no-explicit-any */) => types.RewardInfo.fromDecoded(item)),
tickArrayBitmap: dec.tickArrayBitmap,
totalFeesToken0: dec.totalFeesToken0,
totalFeesClaimedToken0: dec.totalFeesClaimedToken0,
totalFeesToken1: dec.totalFeesToken1,
totalFeesClaimedToken1: dec.totalFeesClaimedToken1,
fundFeesToken0: dec.fundFeesToken0,
fundFeesToken1: dec.fundFeesToken1,
openTime: dec.openTime,
padding1: dec.padding1,
padding2: dec.padding2,
});
}
toJSON() {
return {
bump: this.bump,
ammConfig: this.ammConfig,
owner: this.owner,
tokenMint0: this.tokenMint0,
tokenMint1: this.tokenMint1,
tokenVault0: this.tokenVault0,
tokenVault1: this.tokenVault1,
observationKey: this.observationKey,
mintDecimals0: this.mintDecimals0,
mintDecimals1: this.mintDecimals1,
tickSpacing: this.tickSpacing,
liquidity: this.liquidity.toString(),
sqrtPriceX64: this.sqrtPriceX64.toString(),
tickCurrent: this.tickCurrent,
observationIndex: this.observationIndex,
observationUpdateDuration: this.observationUpdateDuration,
feeGrowthGlobal0X64: this.feeGrowthGlobal0X64.toString(),
feeGrowthGlobal1X64: this.feeGrowthGlobal1X64.toString(),
protocolFeesToken0: this.protocolFeesToken0.toString(),
protocolFeesToken1: this.protocolFeesToken1.toString(),
swapInAmountToken0: this.swapInAmountToken0.toString(),
swapOutAmountToken1: this.swapOutAmountToken1.toString(),
swapInAmountToken1: this.swapInAmountToken1.toString(),
swapOutAmountToken0: this.swapOutAmountToken0.toString(),
status: this.status,
padding: this.padding,
rewardInfos: this.rewardInfos.map((item) => item.toJSON()),
tickArrayBitmap: this.tickArrayBitmap.map((item) => item.toString()),
totalFeesToken0: this.totalFeesToken0.toString(),
totalFeesClaimedToken0: this.totalFeesClaimedToken0.toString(),
totalFeesToken1: this.totalFeesToken1.toString(),
totalFeesClaimedToken1: this.totalFeesClaimedToken1.toString(),
fundFeesToken0: this.fundFeesToken0.toString(),
fundFeesToken1: this.fundFeesToken1.toString(),
openTime: this.openTime.toString(),
padding1: this.padding1.map((item) => item.toString()),
padding2: this.padding2.map((item) => item.toString()),
};
}
static fromJSON(obj) {
return new PoolState({
bump: obj.bump,
ammConfig: (0, kit_1.address)(obj.ammConfig),
owner: (0, kit_1.address)(obj.owner),
tokenMint0: (0, kit_1.address)(obj.tokenMint0),
tokenMint1: (0, kit_1.address)(obj.tokenMint1),
tokenVault0: (0, kit_1.address)(obj.tokenVault0),
tokenVault1: (0, kit_1.address)(obj.tokenVault1),
observationKey: (0, kit_1.address)(obj.observationKey),
mintDecimals0: obj.mintDecimals0,
mintDecimals1: obj.mintDecimals1,
tickSpacing: obj.tickSpacing,
liquidity: new bn_js_1.default(obj.liquidity),
sqrtPriceX64: new bn_js_1.default(obj.sqrtPriceX64),
tickCurrent: obj.tickCurrent,
observationIndex: obj.observationIndex,
observationUpdateDuration: obj.observationUpdateDuration,
feeGrowthGlobal0X64: new bn_js_1.default(obj.feeGrowthGlobal0X64),
feeGrowthGlobal1X64: new bn_js_1.default(obj.feeGrowthGlobal1X64),
protocolFeesToken0: new bn_js_1.default(obj.protocolFeesToken0),
protocolFeesToken1: new bn_js_1.default(obj.protocolFeesToken1),
swapInAmountToken0: new bn_js_1.default(obj.swapInAmountToken0),
swapOutAmountToken1: new bn_js_1.default(obj.swapOutAmountToken1),
swapInAmountToken1: new bn_js_1.default(obj.swapInAmountToken1),
swapOutAmountToken0: new bn_js_1.default(obj.swapOutAmountToken0),
status: obj.status,
padding: obj.padding,
rewardInfos: obj.rewardInfos.map((item) => types.RewardInfo.fromJSON(item)),
tickArrayBitmap: obj.tickArrayBitmap.map((item) => new bn_js_1.default(item)),
totalFeesToken0: new bn_js_1.default(obj.totalFeesToken0),
totalFeesClaimedToken0: new bn_js_1.default(obj.totalFeesClaimedToken0),
totalFeesToken1: new bn_js_1.default(obj.totalFeesToken1),
totalFeesClaimedToken1: new bn_js_1.default(obj.totalFeesClaimedToken1),
fundFeesToken0: new bn_js_1.default(obj.fundFeesToken0),
fundFeesToken1: new bn_js_1.default(obj.fundFeesToken1),
openTime: new bn_js_1.default(obj.openTime),
padding1: obj.padding1.map((item) => new bn_js_1.default(item)),
padding2: obj.padding2.map((item) => new bn_js_1.default(item)),
});
}
}
exports.PoolState = PoolState;
//# sourceMappingURL=PoolState.js.map