@kamino-finance/kliquidity-sdk 8.4.7-beta.0 → 8.4.8-beta.0

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.
@@ -1,6 +1,7 @@
1
1
  import Decimal from 'decimal.js';
2
2
  import { OraclePrices } from '@kamino-finance/scope-sdk';
3
3
  import { CollateralInfo } from '../kamino-client/types';
4
+ import { PublicKey } from '@solana/web3.js';
4
5
  export interface EnrichedScopePrice {
5
6
  /**
6
7
  * Price in USD
@@ -23,7 +24,7 @@ export interface KaminoPrices {
23
24
  }
24
25
  export type MintToPriceMap = Record<string, EnrichedScopePrice>;
25
26
  export interface OraclePricesAndCollateralInfos {
26
- oraclePrices: OraclePrices;
27
+ oraclePrices: [PublicKey, OraclePrices][];
27
28
  collateralInfos: CollateralInfo[];
28
29
  }
29
30
  //# sourceMappingURL=EnrichedScopePrice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnrichedScopePrice.d.ts","sourceRoot":"","sources":["../../src/models/EnrichedScopePrice.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,cAAc,CAAC;IACrB;;OAEG;IACH,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAEhE,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC"}
1
+ {"version":3,"file":"EnrichedScopePrice.d.ts","sourceRoot":"","sources":["../../src/models/EnrichedScopePrice.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,EAAE,cAAc,CAAC;IACrB;;OAEG;IACH,IAAI,EAAE,cAAc,CAAC;CACtB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAEhE,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,CAAC;IAC1C,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamino-finance/kliquidity-sdk",
3
- "version": "8.4.7-beta.0",
3
+ "version": "8.4.8-beta.0",
4
4
  "description": "Typescript SDK for interacting with the Kamino Liquidity (kliquidity) protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -50,7 +50,7 @@
50
50
  "@coral-xyz/borsh": "^0.30.1",
51
51
  "@hubbleprotocol/hubble-config": "^5.0.0",
52
52
  "@jup-ag/api": "^6.0.38",
53
- "@kamino-finance/scope-sdk": "^8.0.2",
53
+ "@kamino-finance/scope-sdk": "^8.1.0-beta.4",
54
54
  "@orca-so/whirlpool-client-sdk": "^0.0.8",
55
55
  "@orca-so/whirlpool-sdk": "^0.4.2",
56
56
  "@raydium-io/raydium-sdk-v2": "=0.1.111-alpha",
package/src/Kamino.ts CHANGED
@@ -349,6 +349,9 @@ import {
349
349
 
350
350
  export const KAMINO_IDL = KaminoIdl;
351
351
 
352
+ export const HUBBLE_SCOPE_FEED_ID = new PublicKey('3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C');
353
+ export const KAMINO_SCOPE_FEED_ID = new PublicKey('3t4JZcueEzTbVP6kLxXrL3VpWx45jDer4eqysweBchNH');
354
+
352
355
  export class Kamino {
353
356
  private readonly _cluster: SolanaCluster;
354
357
  private readonly _connection: Connection;
@@ -2150,7 +2153,8 @@ export class Kamino {
2150
2153
  };
2151
2154
  };
2152
2155
 
2153
- getAllOraclePrices = (): Promise<OraclePrices> => this._scope.getOraclePrices();
2156
+ getAllOraclePrices = (prices: PublicKey[]): Promise<[PublicKey, OraclePrices][]> =>
2157
+ this._scope.getOraclePrices(prices);
2154
2158
 
2155
2159
  /**
2156
2160
  * Get all Kamino token spot and twap prices
@@ -2167,15 +2171,21 @@ export class Kamino {
2167
2171
  const twaps: MintToPriceMap = {};
2168
2172
 
2169
2173
  const disabledTokens: PublicKey[] = [];
2170
- ({ oraclePrices, collateralInfos } = await this.getOraclePricesAndCollateralInfos(oraclePrices, collateralInfos));
2171
- for (const collateralInfo of collateralInfos) {
2174
+ const oraclePricesAndCollateralInfos = await this.getOraclePricesAndCollateralInfos(
2175
+ oraclePrices ? [[HUBBLE_SCOPE_FEED_ID, oraclePrices]] : undefined,
2176
+ collateralInfos,
2177
+ true
2178
+ );
2179
+ const { oraclePrices: allOraclePrices, collateralInfos: hubbleCollateralInfos } = oraclePricesAndCollateralInfos;
2180
+ for (const collateralInfo of hubbleCollateralInfos) {
2172
2181
  if (
2173
2182
  collateralInfo.scopePriceChain &&
2174
2183
  Scope.isScopeChainValid(collateralInfo.scopePriceChain) &&
2175
2184
  collateralInfo.disabled === 0
2176
2185
  ) {
2177
2186
  const collInfoMintString = collateralInfo.mint.toString();
2178
- const spotPrice = await this._scope.getPriceFromChain(collateralInfo.scopePriceChain, oraclePrices);
2187
+ const hubbleOraclePrices = allOraclePrices?.find((x) => x[0].equals(HUBBLE_SCOPE_FEED_ID))?.[1];
2188
+ const spotPrice = await this._scope.getPriceFromChain(collateralInfo.scopePriceChain, hubbleOraclePrices!);
2179
2189
  spotPrices[collInfoMintString] = {
2180
2190
  price: spotPrice.price,
2181
2191
  name: getTokenNameFromCollateralInfo(collateralInfo),
@@ -2183,7 +2193,7 @@ export class Kamino {
2183
2193
 
2184
2194
  const filteredTwapChain = collateralInfo?.scopeTwapPriceChain?.filter((x) => x > 0);
2185
2195
  if (filteredTwapChain && Scope.isScopeChainValid(filteredTwapChain)) {
2186
- const twap = await this._scope.getPriceFromChain(filteredTwapChain, oraclePrices);
2196
+ const twap = await this._scope.getPriceFromChain(filteredTwapChain, hubbleOraclePrices!);
2187
2197
  twaps[collInfoMintString] = {
2188
2198
  price: twap.price,
2189
2199
  name: getTokenNameFromCollateralInfo(collateralInfo),
@@ -2202,7 +2212,7 @@ export class Kamino {
2202
2212
  ? disabledTokensPrices
2203
2213
  : await JupService.getDollarPrices(disabledTokens, this._jupBaseAPI);
2204
2214
  for (const [token, price] of tokensPrices) {
2205
- const collInfo = collateralInfos.find((x) => x.mint.equals(token));
2215
+ const collInfo = hubbleCollateralInfos.find((x) => x.mint.equals(token));
2206
2216
  if (!collInfo) {
2207
2217
  console.log(`Could not find collateral info for token ${token.toString()}`);
2208
2218
  continue;
@@ -2224,11 +2234,13 @@ export class Kamino {
2224
2234
  };
2225
2235
 
2226
2236
  private async getOraclePricesAndCollateralInfos(
2227
- oraclePrices?: OraclePrices,
2228
- collateralInfos?: CollateralInfo[]
2237
+ oraclePrices?: [PublicKey, OraclePrices][],
2238
+ collateralInfos?: CollateralInfo[],
2239
+ readAllFeeds: boolean = false
2229
2240
  ): Promise<OraclePricesAndCollateralInfos> {
2230
2241
  if (!oraclePrices) {
2231
- oraclePrices = await this.getAllOraclePrices();
2242
+ const allFeeds = readAllFeeds ? [HUBBLE_SCOPE_FEED_ID, KAMINO_SCOPE_FEED_ID] : [HUBBLE_SCOPE_FEED_ID];
2243
+ oraclePrices = await this.getAllOraclePrices(allFeeds);
2232
2244
  }
2233
2245
  if (!collateralInfos) {
2234
2246
  collateralInfos = await this.getCollateralInfos();
@@ -2258,7 +2270,7 @@ export class Kamino {
2258
2270
  if (scopePrices) {
2259
2271
  prices = scopePrices;
2260
2272
  } else {
2261
- prices = await this._scope.getOraclePrices({ prices: strategy.scopePrices });
2273
+ prices = (await this._scope.getOraclePrices([strategy.scopePrices]))[0][1];
2262
2274
  }
2263
2275
 
2264
2276
  let jupPrices: PubkeyHashMap<PublicKey, Decimal> = new PubkeyHashMap();
@@ -1,6 +1,7 @@
1
1
  import Decimal from 'decimal.js';
2
2
  import { OraclePrices } from '@kamino-finance/scope-sdk';
3
3
  import { CollateralInfo } from '../kamino-client/types';
4
+ import { PublicKey } from '@solana/web3.js';
4
5
 
5
6
  export interface EnrichedScopePrice {
6
7
  /**
@@ -27,6 +28,6 @@ export interface KaminoPrices {
27
28
  export type MintToPriceMap = Record<string, EnrichedScopePrice>;
28
29
 
29
30
  export interface OraclePricesAndCollateralInfos {
30
- oraclePrices: OraclePrices;
31
+ oraclePrices: [PublicKey, OraclePrices][];
31
32
  collateralInfos: CollateralInfo[];
32
33
  }