@kamino-finance/kliquidity-sdk 8.5.5 → 8.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import Decimal from 'decimal.js';
2
+ import { Address } from '@solana/kit';
3
+ export declare const getTokensPrices: (apiBaseUrl: string, tokens: Address[]) => Promise<Map<Address, Decimal>>;
4
+ //# sourceMappingURL=kSwap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kSwap.d.ts","sourceRoot":"","sources":["../../src/services/kSwap.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAgBtC,eAAO,MAAM,eAAe,GAAU,YAAY,MAAM,EAAE,QAAQ,OAAO,EAAE,KAAG,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAiC1G,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getTokensPrices = void 0;
7
+ const decimal_js_1 = __importDefault(require("decimal.js"));
8
+ const getTokensPrices = async (apiBaseUrl, tokens) => {
9
+ const tokensParams = tokens.map((token) => `tokens=${encodeURIComponent(token)}`).join('&');
10
+ const url = `${apiBaseUrl}/batch-token-prices?${tokensParams}`;
11
+ const response = await fetch(url, {
12
+ method: 'GET',
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ },
16
+ });
17
+ if (!response.ok) {
18
+ console.error(`Failed to fetch tokens batch price: ${response.statusText}`);
19
+ return new Map();
20
+ }
21
+ const data = (await response.json());
22
+ const prices = new Map();
23
+ for (const token of tokens) {
24
+ const tokenData = data.data[token];
25
+ if (tokenData && tokenData.value !== null && tokenData.value !== undefined) {
26
+ try {
27
+ const price = new decimal_js_1.default(tokenData.value);
28
+ prices.set(token, price);
29
+ }
30
+ catch (error) {
31
+ console.error(`Failed to parse price for token, setting to 0: ${token}: ${error}`);
32
+ prices.set(token, new decimal_js_1.default(0));
33
+ }
34
+ }
35
+ else {
36
+ console.warn(`No price data available for token ${token}, setting to 0`);
37
+ prices.set(token, new decimal_js_1.default(0));
38
+ }
39
+ }
40
+ return prices;
41
+ };
42
+ exports.getTokensPrices = getTokensPrices;
43
+ //# sourceMappingURL=kSwap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kSwap.js","sourceRoot":"","sources":["../../src/services/kSwap.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAiC;AAiB1B,MAAM,eAAe,GAAG,KAAK,EAAE,UAAkB,EAAE,MAAiB,EAAkC,EAAE;IAC7G,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5F,MAAM,GAAG,GAAG,GAAG,UAAU,uBAAuB,YAAY,EAAE,CAAC;IAC/D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,uCAAuC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QAC5E,OAAO,IAAI,GAAG,EAAoB,CAAC;IACrC,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA4B,CAAC;IAEhE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC3C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,KAAK,KAAK,IAAI,IAAI,SAAS,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC3E,IAAI,CAAC;gBACH,MAAM,KAAK,GAAG,IAAI,oBAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBAC3C,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,kDAAkD,KAAK,KAAK,KAAK,EAAE,CAAC,CAAC;gBACnF,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,oBAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,qCAAqC,KAAK,gBAAgB,CAAC,CAAC;YACzE,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,oBAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAjCW,QAAA,eAAe,mBAiC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamino-finance/kliquidity-sdk",
3
- "version": "8.5.5",
3
+ "version": "8.5.6",
4
4
  "description": "Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol",
5
5
  "repository": {
6
6
  "type": "git",
package/src/Kamino.ts CHANGED
@@ -347,11 +347,13 @@ import { fetchMultipleLookupTableAccounts } from './utils/lookupTable';
347
347
  import type { AccountInfoBase, AccountInfoWithJsonData, AccountInfoWithPubkey } from '@solana/rpc-types';
348
348
  import { toLegacyPublicKey } from './utils/compat';
349
349
  import { IncreaseLiquidityQuoteParam } from '@orca-so/whirlpools';
350
+ import { getTokensPrices } from './services/kSwap';
350
351
 
351
352
  const addressEncoder = getAddressEncoder();
352
353
 
353
354
  export const HUBBLE_SCOPE_FEED_ID = address('3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C');
354
355
  export const KAMINO_SCOPE_FEED_ID = address('3t4JZcueEzTbVP6kLxXrL3VpWx45jDer4eqysweBchNH');
356
+ export const KSWAP_BASE_API = "https://api.kamino.finance/kswap";
355
357
 
356
358
  export class Kamino {
357
359
  private readonly _cluster: SolanaCluster;
@@ -364,6 +366,7 @@ export class Kamino {
364
366
  private readonly _raydiumService: RaydiumService;
365
367
  private readonly _meteoraService: MeteoraService;
366
368
  private readonly _jupBaseAPI: string = DEFAULT_JUP_API_ENDPOINT;
369
+ private readonly _kSwapBaseAPI: string = KSWAP_BASE_API;
367
370
 
368
371
  /**
369
372
  * Create a new instance of the Kamino SDK class.
@@ -384,7 +387,8 @@ export class Kamino {
384
387
  whirlpoolProgramId?: Address,
385
388
  raydiumProgramId?: Address,
386
389
  meteoraProgramId?: Address,
387
- jupBaseAPI?: string
390
+ jupBaseAPI?: string,
391
+ kSwapBaseAPI?: string
388
392
  ) {
389
393
  this._cluster = cluster;
390
394
  this._rpc = rpc;
@@ -406,6 +410,10 @@ export class Kamino {
406
410
  if (jupBaseAPI) {
407
411
  this._jupBaseAPI = jupBaseAPI;
408
412
  }
413
+
414
+ if (kSwapBaseAPI) {
415
+ this._kSwapBaseAPI = kSwapBaseAPI;
416
+ }
409
417
  }
410
418
 
411
419
  getConnection = () => this._rpc;
@@ -431,13 +439,15 @@ export class Kamino {
431
439
  return this.getCollateralInfo(config.tokenInfos);
432
440
  };
433
441
 
434
- getDisabledTokensPrices = async (collateralInfos?: CollateralInfo[]) => {
442
+ /**
443
+ * Get the prices of all disabled tokens in the specified collateral infos
444
+ * @param collateralInfos
445
+ * @returns {Map<Address, Decimal>} - token prices by mint address
446
+ */
447
+ getDisabledTokensPrices = async (collateralInfos?: CollateralInfo[]): Promise<Map<Address, Decimal>> => {
435
448
  const collInfos = collateralInfos ? collateralInfos : await this.getCollateralInfos();
436
- const disabledTokens = collInfos.filter((x) => x.disabled && x.mint !== DEFAULT_PUBLIC_KEY);
437
- return JupService.getDollarPrices(
438
- disabledTokens.map((x) => x.mint),
439
- this._jupBaseAPI
440
- );
449
+ const disabledTokensMints = collInfos.filter((x) => x.disabled && x.mint !== DEFAULT_PUBLIC_KEY).map((x) => x.mint);
450
+ return getTokensPrices(this._kSwapBaseAPI, disabledTokensMints);
441
451
  };
442
452
 
443
453
  getSupportedDexes = (): Dex[] => ['ORCA', 'RAYDIUM', 'METEORA'];
@@ -0,0 +1,51 @@
1
+ import Decimal from 'decimal.js';
2
+ import { Address } from '@solana/kit';
3
+
4
+ interface KSwapTokenPriceData {
5
+ isScaledUiToken: boolean;
6
+ value: number;
7
+ updateUnixTime: number;
8
+ updateHumanTime: string;
9
+ priceInNative: number;
10
+ priceChange24h: number;
11
+ }
12
+
13
+ interface KSwapBatchPriceResponse {
14
+ success: boolean;
15
+ data: { [key: string]: KSwapTokenPriceData | null };
16
+ }
17
+
18
+ export const getTokensPrices = async (apiBaseUrl: string, tokens: Address[]): Promise<Map<Address, Decimal>> => {
19
+ const tokensParams = tokens.map((token) => `tokens=${encodeURIComponent(token)}`).join('&');
20
+ const url = `${apiBaseUrl}/batch-token-prices?${tokensParams}`;
21
+ const response = await fetch(url, {
22
+ method: 'GET',
23
+ headers: {
24
+ 'Content-Type': 'application/json',
25
+ },
26
+ });
27
+ if (!response.ok) {
28
+ console.error(`Failed to fetch tokens batch price: ${response.statusText}`);
29
+ return new Map<Address, Decimal>();
30
+ }
31
+
32
+ const data = (await response.json()) as KSwapBatchPriceResponse;
33
+
34
+ const prices = new Map<Address, Decimal>();
35
+ for (const token of tokens) {
36
+ const tokenData = data.data[token];
37
+ if (tokenData && tokenData.value !== null && tokenData.value !== undefined) {
38
+ try {
39
+ const price = new Decimal(tokenData.value);
40
+ prices.set(token, price);
41
+ } catch (error) {
42
+ console.error(`Failed to parse price for token, setting to 0: ${token}: ${error}`);
43
+ prices.set(token, new Decimal(0));
44
+ }
45
+ } else {
46
+ console.warn(`No price data available for token ${token}, setting to 0`);
47
+ prices.set(token, new Decimal(0));
48
+ }
49
+ }
50
+ return prices;
51
+ };