@kamino-finance/kliquidity-sdk 8.5.1 → 8.5.2
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.
- package/dist/Kamino.d.ts +3 -1
- package/dist/Kamino.d.ts.map +1 -1
- package/dist/Kamino.js +14 -9
- package/dist/Kamino.js.map +1 -1
- package/dist/models/EnrichedScopePrice.d.ts +2 -1
- package/dist/models/EnrichedScopePrice.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Kamino.ts +20 -10
- package/src/models/EnrichedScopePrice.ts +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
import { OraclePrices } from '@kamino-finance/scope-sdk/dist/@codegen/scope/accounts/OraclePrices';
|
|
3
3
|
import { CollateralInfo } from '../@codegen/kliquidity/types';
|
|
4
|
+
import { Address } from '@solana/kit';
|
|
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: [Address, 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,qEAAqE,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;
|
|
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,qEAAqE,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,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,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC;IACxC,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.5.
|
|
3
|
+
"version": "8.5.2",
|
|
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.39",
|
|
53
|
-
"@kamino-finance/scope-sdk": "^10.0
|
|
53
|
+
"@kamino-finance/scope-sdk": "^10.1.0",
|
|
54
54
|
"@orca-so/common-sdk": "^0.6.11",
|
|
55
55
|
"@orca-so/whirlpools": "^2.0.0",
|
|
56
56
|
"@orca-so/whirlpools-core": "^2.0.0",
|
package/src/Kamino.ts
CHANGED
|
@@ -350,6 +350,9 @@ import { IncreaseLiquidityQuoteParam } from '@orca-so/whirlpools';
|
|
|
350
350
|
|
|
351
351
|
const addressEncoder = getAddressEncoder();
|
|
352
352
|
|
|
353
|
+
export const HUBBLE_SCOPE_FEED_ID = address('3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C');
|
|
354
|
+
export const KAMINO_SCOPE_FEED_ID = address('3t4JZcueEzTbVP6kLxXrL3VpWx45jDer4eqysweBchNH');
|
|
355
|
+
|
|
353
356
|
export class Kamino {
|
|
354
357
|
private readonly _cluster: SolanaCluster;
|
|
355
358
|
private readonly _rpc: Rpc<SolanaRpcApi>;
|
|
@@ -2139,8 +2142,7 @@ export class Kamino {
|
|
|
2139
2142
|
};
|
|
2140
2143
|
};
|
|
2141
2144
|
|
|
2142
|
-
getAllOraclePrices = (): Promise<OraclePrices> =>
|
|
2143
|
-
this._scope.getSingleOraclePrices({ prices: fromLegacyPublicKey(this._config.scope.oraclePrices) });
|
|
2145
|
+
getAllOraclePrices = (prices: Address[]): Promise<[Address, OraclePrices][]> => this._scope.getOraclePrices(prices);
|
|
2144
2146
|
|
|
2145
2147
|
/**
|
|
2146
2148
|
* Get all Kamino token spot and twap prices
|
|
@@ -2157,15 +2159,21 @@ export class Kamino {
|
|
|
2157
2159
|
const twaps: MintToPriceMap = {};
|
|
2158
2160
|
|
|
2159
2161
|
const disabledTokens: Address[] = [];
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
+
const oraclePricesAndCollateralInfos = await this.getOraclePricesAndCollateralInfos(
|
|
2163
|
+
oraclePrices ? [[HUBBLE_SCOPE_FEED_ID, oraclePrices]] : undefined,
|
|
2164
|
+
collateralInfos,
|
|
2165
|
+
true
|
|
2166
|
+
);
|
|
2167
|
+
const { oraclePrices: allOraclePrices, collateralInfos: hubbleCollateralInfos } = oraclePricesAndCollateralInfos;
|
|
2168
|
+
for (const collateralInfo of hubbleCollateralInfos) {
|
|
2162
2169
|
if (
|
|
2163
2170
|
collateralInfo.scopePriceChain &&
|
|
2164
2171
|
Scope.isScopeChainValid(collateralInfo.scopePriceChain) &&
|
|
2165
2172
|
collateralInfo.disabled === 0
|
|
2166
2173
|
) {
|
|
2167
2174
|
const collInfoMintString = collateralInfo.mint.toString();
|
|
2168
|
-
const
|
|
2175
|
+
const hubbleOraclePrices = allOraclePrices?.find((x) => x[0] === HUBBLE_SCOPE_FEED_ID)?.[1];
|
|
2176
|
+
const spotPrice = await this._scope.getPriceFromChain(collateralInfo.scopePriceChain, hubbleOraclePrices!);
|
|
2169
2177
|
spotPrices[collInfoMintString] = {
|
|
2170
2178
|
price: spotPrice.price,
|
|
2171
2179
|
name: getTokenNameFromCollateralInfo(collateralInfo),
|
|
@@ -2173,7 +2181,7 @@ export class Kamino {
|
|
|
2173
2181
|
|
|
2174
2182
|
const filteredTwapChain = collateralInfo?.scopeTwapPriceChain?.filter((x) => x > 0);
|
|
2175
2183
|
if (filteredTwapChain && Scope.isScopeChainValid(filteredTwapChain)) {
|
|
2176
|
-
const twap = await this._scope.getPriceFromChain(filteredTwapChain,
|
|
2184
|
+
const twap = await this._scope.getPriceFromChain(filteredTwapChain, hubbleOraclePrices!);
|
|
2177
2185
|
twaps[collInfoMintString] = {
|
|
2178
2186
|
price: twap.price,
|
|
2179
2187
|
name: getTokenNameFromCollateralInfo(collateralInfo),
|
|
@@ -2192,7 +2200,7 @@ export class Kamino {
|
|
|
2192
2200
|
? disabledTokensPrices
|
|
2193
2201
|
: await JupService.getDollarPrices(disabledTokens, this._jupBaseAPI);
|
|
2194
2202
|
for (const [token, price] of tokensPrices) {
|
|
2195
|
-
const collInfo =
|
|
2203
|
+
const collInfo = hubbleCollateralInfos.find((x) => x.mint === token);
|
|
2196
2204
|
if (!collInfo) {
|
|
2197
2205
|
console.log(`Could not find collateral info for token ${token.toString()}`);
|
|
2198
2206
|
continue;
|
|
@@ -2214,11 +2222,13 @@ export class Kamino {
|
|
|
2214
2222
|
};
|
|
2215
2223
|
|
|
2216
2224
|
private async getOraclePricesAndCollateralInfos(
|
|
2217
|
-
oraclePrices?: OraclePrices,
|
|
2218
|
-
collateralInfos?: CollateralInfo[]
|
|
2225
|
+
oraclePrices?: [Address, OraclePrices][],
|
|
2226
|
+
collateralInfos?: CollateralInfo[],
|
|
2227
|
+
readAllFeeds: boolean = false
|
|
2219
2228
|
): Promise<OraclePricesAndCollateralInfos> {
|
|
2220
2229
|
if (!oraclePrices) {
|
|
2221
|
-
|
|
2230
|
+
const allFeeds = readAllFeeds ? [HUBBLE_SCOPE_FEED_ID, KAMINO_SCOPE_FEED_ID] : [HUBBLE_SCOPE_FEED_ID];
|
|
2231
|
+
oraclePrices = await this.getAllOraclePrices(allFeeds);
|
|
2222
2232
|
}
|
|
2223
2233
|
if (!collateralInfos) {
|
|
2224
2234
|
collateralInfos = await this.getCollateralInfos();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
import { OraclePrices } from '@kamino-finance/scope-sdk/dist/@codegen/scope/accounts/OraclePrices';
|
|
3
3
|
import { CollateralInfo } from '../@codegen/kliquidity/types';
|
|
4
|
+
import { Address } from '@solana/kit';
|
|
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: [Address, OraclePrices][];
|
|
31
32
|
collateralInfos: CollateralInfo[];
|
|
32
33
|
}
|