@kamino-finance/kliquidity-sdk 7.0.6 → 7.0.8
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 +4 -3
- package/dist/Kamino.d.ts.map +1 -1
- package/dist/Kamino.js +73 -39
- package/dist/Kamino.js.map +1 -1
- package/dist/services/JupService.d.ts +3 -0
- package/dist/services/JupService.d.ts.map +1 -1
- package/dist/services/JupService.js +29 -1
- package/dist/services/JupService.js.map +1 -1
- package/package.json +1 -1
- package/src/Kamino.ts +118 -39
- package/src/services/JupService.ts +36 -1
|
@@ -3,6 +3,7 @@ import { SolanaCluster } from '@hubbleprotocol/hubble-config';
|
|
|
3
3
|
import Decimal from 'decimal.js';
|
|
4
4
|
import { DeserializedVersionedTransaction } from '../utils';
|
|
5
5
|
import { QuoteResponse, SwapInstructionsResponse, SwapResponse } from '@jup-ag/api';
|
|
6
|
+
import { PubkeyHashMap } from '../utils/pubkey';
|
|
6
7
|
export type SwapTransactionsResponse = {
|
|
7
8
|
setupTransaction: string | undefined;
|
|
8
9
|
swapTransaction: string;
|
|
@@ -16,6 +17,8 @@ export declare class JupService {
|
|
|
16
17
|
static getBestRouteQuoteV6: (amount: Decimal, inputMint: PublicKey, outputMint: PublicKey, slippageBps: number, asLegacyTransaction?: boolean, maxAccounts?: number, onlyDirectRoutes?: boolean) => Promise<QuoteResponse>;
|
|
17
18
|
static getSwapIxsFromQuote: (userPublicKey: PublicKey, quote: QuoteResponse, wrapUnwrapSOL?: boolean, asLegacyTransaction?: boolean) => Promise<SwapInstructionsResponse>;
|
|
18
19
|
static getPrice: (inputMint: PublicKey | string, outputMint: PublicKey | string) => Promise<number>;
|
|
20
|
+
static getPrices: (inputMints: (PublicKey | string)[], outputMint: PublicKey | string) => Promise<PubkeyHashMap<PublicKey, Decimal>>;
|
|
21
|
+
static getDollarPrices(inputMints: (PublicKey | string)[]): Promise<PubkeyHashMap<PublicKey, Decimal>>;
|
|
19
22
|
static getDollarPrice: (inputMint: PublicKey | string) => Promise<number>;
|
|
20
23
|
static buildTransactionsFromSerialized: (serializedTransactions: Array<string | undefined>) => Transaction[];
|
|
21
24
|
static deserealizeVersionedTransactions: (connection: Connection, serializedTransactions: Array<string | undefined>) => Promise<DeserializedVersionedTransaction>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JupService.d.ts","sourceRoot":"","sources":["../../src/services/JupService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAA4C,MAAM,iBAAiB,CAAC;AAC/G,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,YAAY,EAA0B,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"JupService.d.ts","sourceRoot":"","sources":["../../src/services/JupService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAA4C,MAAM,iBAAiB,CAAC;AAC/G,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,YAAY,EAA0B,MAAM,aAAa,CAAC;AAC5G,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhD,MAAM,MAAM,wBAAwB,GAAG;IACrC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,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AEF,MAAM,CAAC,qBAAqB,eAAsB,UAAU,WAAW,MAAM,GAAG,SAAS,yEAEvF;CACH"}
|
|
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.JupService = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
9
10
|
const api_1 = require("@jup-ag/api");
|
|
11
|
+
const pubkey_1 = require("../utils/pubkey");
|
|
12
|
+
const USDC_MINT = new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
10
13
|
class JupService {
|
|
11
14
|
_connection;
|
|
12
15
|
_cluster;
|
|
@@ -83,8 +86,33 @@ class JupService {
|
|
|
83
86
|
const res = await axios_1.default.get('https://api.jup.ag/price/v2', { params });
|
|
84
87
|
return res.data.data[inputMint.toString()].price;
|
|
85
88
|
};
|
|
89
|
+
static getPrices = async (inputMints, outputMint) => {
|
|
90
|
+
const mintsCommaSeparated = inputMints.map((mint) => mint.toString()).join(',');
|
|
91
|
+
const params = {
|
|
92
|
+
ids: mintsCommaSeparated,
|
|
93
|
+
vsToken: outputMint.toString(),
|
|
94
|
+
vsAmount: 1,
|
|
95
|
+
};
|
|
96
|
+
// BONK token
|
|
97
|
+
if (outputMint.toString() === 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263') {
|
|
98
|
+
params.vsAmount = 100;
|
|
99
|
+
}
|
|
100
|
+
const res = await axios_1.default.get('https://api.jup.ag/price/v2', { params });
|
|
101
|
+
const prices = new pubkey_1.PubkeyHashMap();
|
|
102
|
+
for (const mint of inputMints) {
|
|
103
|
+
try {
|
|
104
|
+
prices.set(new web3_js_1.PublicKey(mint), new decimal_js_1.default(res.data.data[mint.toString()].price));
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
prices.set(new web3_js_1.PublicKey(mint), new decimal_js_1.default(0));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return prices;
|
|
111
|
+
};
|
|
112
|
+
static getDollarPrices(inputMints) {
|
|
113
|
+
return this.getPrices(inputMints, USDC_MINT);
|
|
114
|
+
}
|
|
86
115
|
static getDollarPrice = async (inputMint) => {
|
|
87
|
-
const USDC_MINT = new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
88
116
|
return this.getPrice(inputMint, USDC_MINT);
|
|
89
117
|
};
|
|
90
118
|
static buildTransactionsFromSerialized = (serializedTransactions) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JupService.js","sourceRoot":"","sources":["../../src/services/JupService.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA+G;AAE/G,kDAA0B;
|
|
1
|
+
{"version":3,"file":"JupService.js","sourceRoot":"","sources":["../../src/services/JupService.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA+G;AAE/G,kDAA0B;AAC1B,4DAAiC;AAEjC,qCAA4G;AAC5G,4CAAgD;AAEhD,MAAM,SAAS,GAAG,IAAI,mBAAS,CAAC,8CAA8C,CAAC,CAAC;AAQhF,MAAa,UAAU;IACJ,WAAW,CAAa;IACxB,QAAQ,CAAgB;IAEzC,YAAY,UAAsB,EAAE,OAAsB;QACxD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,cAAc,GAAG,KAAK,EAC3B,aAAwB,EACxB,MAAe,EACf,SAAoB,EACpB,UAAqB,EACrB,WAAmB,EACnB,mBAA6B,EAC7B,WAAoB,EACpB,gBAA0B,EACH,EAAE;QACzB,IAAI,CAAC;YACH,MAAM,eAAe,GAAG,IAAA,4BAAsB,GAAE,CAAC,CAAC,qBAAqB;YAEvE,yOAAyO;YAE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AAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACvE,CAAC,CAAC,CAAC;YAEH,MAAM,mBAAmB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;YAE3E,MAAM,iBAAiB,GAAG,4BAAkB,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE;gBAC1E,aAAa;gBACb,0BAA0B,EAAE,mBAAmB;aAChD,CAAC,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IACtD,CAAC,CAAC;IAEF,MAAM,CAAC,qBAAqB,GAAG,KAAK,EAAE,UAAsB,EAAE,OAA2B,EAAE,EAAE;QAC3F,OAAO,UAAU,CAAC,qBAAqB,CAAC,IAAI,mBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3F,CAAC,CAAC;;AAtMJ,gCAuMC"}
|
package/package.json
CHANGED
package/src/Kamino.ts
CHANGED
|
@@ -439,6 +439,12 @@ export class Kamino {
|
|
|
439
439
|
return this.getCollateralInfo(config.tokenInfos);
|
|
440
440
|
};
|
|
441
441
|
|
|
442
|
+
getDisabledTokensPrices = async (collateralInfos?: CollateralInfo[]) => {
|
|
443
|
+
const collInfos = collateralInfos ? collateralInfos : await this.getCollateralInfos();
|
|
444
|
+
const disabledTokens = collInfos.filter((x) => x.disabled && !x.mint.equals(PublicKey.default));
|
|
445
|
+
return JupService.getDollarPrices(disabledTokens.map((x) => x.mint));
|
|
446
|
+
};
|
|
447
|
+
|
|
442
448
|
getSupportedDexes = (): Dex[] => ['ORCA', 'RAYDIUM', 'METEORA'];
|
|
443
449
|
|
|
444
450
|
// todo: see if we can read this dynamically
|
|
@@ -1362,7 +1368,8 @@ export class Kamino {
|
|
|
1362
1368
|
getStrategiesShareData = async (
|
|
1363
1369
|
strategyFilters: StrategiesFilters | PublicKey[],
|
|
1364
1370
|
stratsWithAddresses?: StrategyWithAddress[],
|
|
1365
|
-
collateralInfos?: CollateralInfo[]
|
|
1371
|
+
collateralInfos?: CollateralInfo[],
|
|
1372
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1366
1373
|
): Promise<Array<ShareDataWithAddress>> => {
|
|
1367
1374
|
const result: Array<ShareDataWithAddress> = [];
|
|
1368
1375
|
const strategiesWithAddresses = stratsWithAddresses
|
|
@@ -1411,11 +1418,13 @@ export class Kamino {
|
|
|
1411
1418
|
|
|
1412
1419
|
const inactiveStrategies = strategiesWithAddresses.filter((x) => x.strategy.position.equals(PublicKey.default));
|
|
1413
1420
|
const collInfos = collateralInfos ? collateralInfos : await this.getCollateralInfos();
|
|
1421
|
+
const disabledPrices = disabledTokensPrices ? disabledTokensPrices : await this.getDisabledTokensPrices(collInfos);
|
|
1414
1422
|
for (const { strategy, address } of inactiveStrategies) {
|
|
1415
1423
|
const strategyPrices = await this.getStrategyPrices(
|
|
1416
1424
|
strategy,
|
|
1417
1425
|
collInfos,
|
|
1418
|
-
scopePricesMap[strategy.scopePrices.toBase58()]
|
|
1426
|
+
scopePricesMap[strategy.scopePrices.toBase58()],
|
|
1427
|
+
disabledPrices
|
|
1419
1428
|
);
|
|
1420
1429
|
result.push({
|
|
1421
1430
|
address,
|
|
@@ -1439,7 +1448,8 @@ export class Kamino {
|
|
|
1439
1448
|
raydiumPositions,
|
|
1440
1449
|
this.getRaydiumBalances,
|
|
1441
1450
|
collInfos,
|
|
1442
|
-
scopePricesMap
|
|
1451
|
+
scopePricesMap,
|
|
1452
|
+
disabledTokensPrices
|
|
1443
1453
|
)
|
|
1444
1454
|
);
|
|
1445
1455
|
|
|
@@ -1450,7 +1460,8 @@ export class Kamino {
|
|
|
1450
1460
|
orcaPositions,
|
|
1451
1461
|
this.getOrcaBalances,
|
|
1452
1462
|
collInfos,
|
|
1453
|
-
scopePricesMap
|
|
1463
|
+
scopePricesMap,
|
|
1464
|
+
disabledTokensPrices
|
|
1454
1465
|
)
|
|
1455
1466
|
);
|
|
1456
1467
|
|
|
@@ -1461,7 +1472,8 @@ export class Kamino {
|
|
|
1461
1472
|
meteoraPositions,
|
|
1462
1473
|
this.getMeteoraBalances,
|
|
1463
1474
|
collInfos,
|
|
1464
|
-
scopePricesMap
|
|
1475
|
+
scopePricesMap,
|
|
1476
|
+
disabledTokensPrices
|
|
1465
1477
|
)
|
|
1466
1478
|
);
|
|
1467
1479
|
|
|
@@ -1497,10 +1509,12 @@ export class Kamino {
|
|
|
1497
1509
|
pool: PoolT,
|
|
1498
1510
|
position: PositionT,
|
|
1499
1511
|
collateralInfos: CollateralInfo[],
|
|
1500
|
-
prices?: OraclePrices
|
|
1512
|
+
prices?: OraclePrices,
|
|
1513
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1501
1514
|
) => Promise<StrategyBalances>,
|
|
1502
1515
|
collateralInfos: CollateralInfo[],
|
|
1503
|
-
prices?: Record<string, OraclePrices
|
|
1516
|
+
prices?: Record<string, OraclePrices>,
|
|
1517
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1504
1518
|
): Promise<StrategyBalanceWithAddress>[] => {
|
|
1505
1519
|
const fetchBalances: Promise<StrategyBalanceWithAddress>[] = [];
|
|
1506
1520
|
|
|
@@ -1522,7 +1536,8 @@ export class Kamino {
|
|
|
1522
1536
|
pool as PoolT,
|
|
1523
1537
|
position as PositionT,
|
|
1524
1538
|
collateralInfos,
|
|
1525
|
-
prices ? prices[strategy.scopePrices.toBase58()] : undefined
|
|
1539
|
+
prices ? prices[strategy.scopePrices.toBase58()] : undefined,
|
|
1540
|
+
disabledTokensPrices
|
|
1526
1541
|
).then((balance) => {
|
|
1527
1542
|
return { balance, strategyWithAddress: { strategy, address } };
|
|
1528
1543
|
})
|
|
@@ -1536,9 +1551,10 @@ export class Kamino {
|
|
|
1536
1551
|
pool: PoolState,
|
|
1537
1552
|
position: PersonalPositionState,
|
|
1538
1553
|
collateralInfos: CollateralInfo[],
|
|
1539
|
-
prices?: OraclePrices
|
|
1554
|
+
prices?: OraclePrices,
|
|
1555
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1540
1556
|
): Promise<StrategyBalances> => {
|
|
1541
|
-
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices);
|
|
1557
|
+
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices, disabledTokensPrices);
|
|
1542
1558
|
const rebalanceKind = numberToRebalanceType(strategy.rebalanceType);
|
|
1543
1559
|
const tokenHoldings = this.getRaydiumTokensBalances(strategy, pool, position);
|
|
1544
1560
|
|
|
@@ -1608,9 +1624,10 @@ export class Kamino {
|
|
|
1608
1624
|
pool: LbPair,
|
|
1609
1625
|
position: PositionV2 | undefined, // the undefined is for scenarios where the position is not initialised yet
|
|
1610
1626
|
collateralInfos: CollateralInfo[],
|
|
1611
|
-
prices?: OraclePrices
|
|
1627
|
+
prices?: OraclePrices,
|
|
1628
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1612
1629
|
): Promise<StrategyBalances> => {
|
|
1613
|
-
const strategyPricesPromise = this.getStrategyPrices(strategy, collateralInfos, prices);
|
|
1630
|
+
const strategyPricesPromise = this.getStrategyPrices(strategy, collateralInfos, prices, disabledTokensPrices);
|
|
1614
1631
|
const rebalanceKind = numberToRebalanceType(strategy.rebalanceType);
|
|
1615
1632
|
const tokenHoldingsPromise = this.getMeteoraTokensBalances(strategy);
|
|
1616
1633
|
const [strategyPrices, tokenHoldings] = await Promise.all([strategyPricesPromise, tokenHoldingsPromise]);
|
|
@@ -1746,9 +1763,10 @@ export class Kamino {
|
|
|
1746
1763
|
position: Position,
|
|
1747
1764
|
collateralInfos: CollateralInfo[],
|
|
1748
1765
|
prices?: OraclePrices,
|
|
1766
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>,
|
|
1749
1767
|
mode: 'DEPOSIT' | 'WITHDRAW' = 'WITHDRAW'
|
|
1750
1768
|
): Promise<StrategyBalances> => {
|
|
1751
|
-
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices);
|
|
1769
|
+
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices, disabledTokensPrices);
|
|
1752
1770
|
const rebalanceKind = numberToRebalanceType(strategy.rebalanceType);
|
|
1753
1771
|
|
|
1754
1772
|
const tokenHoldings = this.getOrcaTokensBalances(strategy, pool, position, mode);
|
|
@@ -1892,15 +1910,21 @@ export class Kamino {
|
|
|
1892
1910
|
|
|
1893
1911
|
private getStrategyBalances = async (
|
|
1894
1912
|
strategy: WhirlpoolStrategy,
|
|
1895
|
-
scopePrices?: OraclePrices
|
|
1913
|
+
scopePrices?: OraclePrices,
|
|
1914
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1896
1915
|
): Promise<StrategyBalances> => {
|
|
1897
1916
|
const collateralInfos = await this.getCollateralInfos();
|
|
1917
|
+
let disabledPrices = disabledTokensPrices;
|
|
1918
|
+
if (!disabledPrices) {
|
|
1919
|
+
disabledPrices = await this.getDisabledTokensPrices(collateralInfos);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1898
1922
|
if (strategy.strategyDex.toNumber() == dexToNumber('ORCA')) {
|
|
1899
|
-
return this.getStrategyBalancesOrca(strategy, collateralInfos, scopePrices);
|
|
1923
|
+
return this.getStrategyBalancesOrca(strategy, collateralInfos, scopePrices, disabledPrices);
|
|
1900
1924
|
} else if (strategy.strategyDex.toNumber() == dexToNumber('RAYDIUM')) {
|
|
1901
|
-
return this.getStrategyBalancesRaydium(strategy, collateralInfos, scopePrices);
|
|
1925
|
+
return this.getStrategyBalancesRaydium(strategy, collateralInfos, scopePrices, disabledPrices);
|
|
1902
1926
|
} else if (strategy.strategyDex.toNumber() == dexToNumber('METEORA')) {
|
|
1903
|
-
return this.getStrategyBalancesMeteora(strategy, collateralInfos, scopePrices);
|
|
1927
|
+
return this.getStrategyBalancesMeteora(strategy, collateralInfos, scopePrices, disabledPrices);
|
|
1904
1928
|
} else {
|
|
1905
1929
|
throw new Error(`Invalid dex ${strategy.strategyDex.toString()}`);
|
|
1906
1930
|
}
|
|
@@ -1989,7 +2013,8 @@ export class Kamino {
|
|
|
1989
2013
|
private getStrategyBalancesOrca = async (
|
|
1990
2014
|
strategy: WhirlpoolStrategy,
|
|
1991
2015
|
collateralInfos: CollateralInfo[],
|
|
1992
|
-
scopePrices?: OraclePrices
|
|
2016
|
+
scopePrices?: OraclePrices,
|
|
2017
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1993
2018
|
): Promise<StrategyBalances> => {
|
|
1994
2019
|
const [whirlpoolAcc, positionAcc] = await this.getConnection().getMultipleAccountsInfo([
|
|
1995
2020
|
strategy.pool,
|
|
@@ -2006,13 +2031,22 @@ export class Kamino {
|
|
|
2006
2031
|
Position.decode(positionAcc.data),
|
|
2007
2032
|
]);
|
|
2008
2033
|
|
|
2009
|
-
return this.getOrcaBalances(
|
|
2034
|
+
return this.getOrcaBalances(
|
|
2035
|
+
strategy,
|
|
2036
|
+
whirlpool,
|
|
2037
|
+
position,
|
|
2038
|
+
collateralInfos,
|
|
2039
|
+
scopePrices,
|
|
2040
|
+
disabledTokensPrices,
|
|
2041
|
+
undefined
|
|
2042
|
+
);
|
|
2010
2043
|
};
|
|
2011
2044
|
|
|
2012
2045
|
private getStrategyBalancesRaydium = async (
|
|
2013
2046
|
strategy: WhirlpoolStrategy,
|
|
2014
2047
|
collateralInfos: CollateralInfo[],
|
|
2015
|
-
scopePrices?: OraclePrices
|
|
2048
|
+
scopePrices?: OraclePrices,
|
|
2049
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2016
2050
|
): Promise<StrategyBalances> => {
|
|
2017
2051
|
const [poolStateAcc, positionAcc] = await this.getConnection().getMultipleAccountsInfo([
|
|
2018
2052
|
strategy.pool,
|
|
@@ -2029,13 +2063,14 @@ export class Kamino {
|
|
|
2029
2063
|
PersonalPositionState.decode(positionAcc.data),
|
|
2030
2064
|
]);
|
|
2031
2065
|
|
|
2032
|
-
return this.getRaydiumBalances(strategy, poolState, position, collateralInfos, scopePrices);
|
|
2066
|
+
return this.getRaydiumBalances(strategy, poolState, position, collateralInfos, scopePrices, disabledTokensPrices);
|
|
2033
2067
|
};
|
|
2034
2068
|
|
|
2035
2069
|
private getStrategyBalancesMeteora = async (
|
|
2036
2070
|
strategy: WhirlpoolStrategy,
|
|
2037
2071
|
collateralInfos: CollateralInfo[],
|
|
2038
|
-
scopePrices?: OraclePrices
|
|
2072
|
+
scopePrices?: OraclePrices,
|
|
2073
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2039
2074
|
): Promise<StrategyBalances> => {
|
|
2040
2075
|
const [poolStateAcc, positionAcc] = await this.getConnection().getMultipleAccountsInfo([
|
|
2041
2076
|
strategy.pool,
|
|
@@ -2054,10 +2089,17 @@ export class Kamino {
|
|
|
2054
2089
|
PositionV2.decode(positionAcc.data),
|
|
2055
2090
|
]);
|
|
2056
2091
|
|
|
2057
|
-
return this.getMeteoraBalances(strategy, poolState, position, collateralInfos, scopePrices);
|
|
2092
|
+
return this.getMeteoraBalances(strategy, poolState, position, collateralInfos, scopePrices, disabledTokensPrices);
|
|
2058
2093
|
} catch (e) {
|
|
2059
2094
|
const poolState = LbPair.decode(poolStateAcc.data);
|
|
2060
|
-
return this.getMeteoraBalances(
|
|
2095
|
+
return this.getMeteoraBalances(
|
|
2096
|
+
strategy,
|
|
2097
|
+
poolState,
|
|
2098
|
+
undefined,
|
|
2099
|
+
collateralInfos,
|
|
2100
|
+
scopePrices,
|
|
2101
|
+
disabledTokensPrices
|
|
2102
|
+
);
|
|
2061
2103
|
}
|
|
2062
2104
|
};
|
|
2063
2105
|
|
|
@@ -2104,10 +2146,16 @@ export class Kamino {
|
|
|
2104
2146
|
* @param oraclePrices (optional) Scope Oracle prices
|
|
2105
2147
|
* @param collateralInfos (optional) Kamino Collateral Infos
|
|
2106
2148
|
*/
|
|
2107
|
-
getAllPrices = async (
|
|
2149
|
+
getAllPrices = async (
|
|
2150
|
+
oraclePrices?: OraclePrices,
|
|
2151
|
+
collateralInfos?: CollateralInfo[],
|
|
2152
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2153
|
+
): Promise<KaminoPrices> => {
|
|
2108
2154
|
// todo: make MintToPriceMap have Pubkey as key
|
|
2109
2155
|
const spotPrices: MintToPriceMap = {};
|
|
2110
2156
|
const twaps: MintToPriceMap = {};
|
|
2157
|
+
|
|
2158
|
+
const disabledTokens: PublicKey[] = [];
|
|
2111
2159
|
({ oraclePrices, collateralInfos } = await this.getOraclePricesAndCollateralInfos(oraclePrices, collateralInfos));
|
|
2112
2160
|
for (const collateralInfo of collateralInfos) {
|
|
2113
2161
|
if (
|
|
@@ -2131,17 +2179,32 @@ export class Kamino {
|
|
|
2131
2179
|
};
|
|
2132
2180
|
}
|
|
2133
2181
|
} else {
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2182
|
+
if (collateralInfo.mint.equals(PublicKey.default)) {
|
|
2183
|
+
continue;
|
|
2184
|
+
}
|
|
2185
|
+
disabledTokens.push(collateralInfo.mint);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
try {
|
|
2190
|
+
const tokensPrices = disabledTokensPrices
|
|
2191
|
+
? disabledTokensPrices
|
|
2192
|
+
: await JupService.getDollarPrices(disabledTokens);
|
|
2193
|
+
for (const [token, price] of tokensPrices) {
|
|
2194
|
+
const collInfo = collateralInfos.find((x) => x.mint.equals(token));
|
|
2195
|
+
if (!collInfo) {
|
|
2196
|
+
console.log(`Could not find collateral info for token ${token.toString()}`);
|
|
2197
|
+
continue;
|
|
2142
2198
|
}
|
|
2199
|
+
spotPrices[token.toString()] = {
|
|
2200
|
+
price: new Decimal(price),
|
|
2201
|
+
name: getTokenNameFromCollateralInfo(collInfo),
|
|
2202
|
+
};
|
|
2143
2203
|
}
|
|
2204
|
+
} catch (e) {
|
|
2205
|
+
console.error('Failed to get prices for disabled tokens from Jup', e);
|
|
2144
2206
|
}
|
|
2207
|
+
|
|
2145
2208
|
return { spot: spotPrices, twap: twaps };
|
|
2146
2209
|
};
|
|
2147
2210
|
|
|
@@ -2167,7 +2230,8 @@ export class Kamino {
|
|
|
2167
2230
|
getStrategyPrices = async (
|
|
2168
2231
|
strategy: WhirlpoolStrategy,
|
|
2169
2232
|
collateralInfos: CollateralInfo[],
|
|
2170
|
-
scopePrices?: OraclePrices
|
|
2233
|
+
scopePrices?: OraclePrices,
|
|
2234
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2171
2235
|
): Promise<StrategyPrices> => {
|
|
2172
2236
|
const tokenA = collateralInfos[strategy.tokenACollateralId.toNumber()];
|
|
2173
2237
|
const tokenB = collateralInfos[strategy.tokenBCollateralId.toNumber()];
|
|
@@ -2181,12 +2245,27 @@ export class Kamino {
|
|
|
2181
2245
|
} else {
|
|
2182
2246
|
prices = await this._scope.getOraclePrices({ prices: strategy.scopePrices });
|
|
2183
2247
|
}
|
|
2248
|
+
|
|
2249
|
+
const validTokens = [tokenA, tokenB, rewardToken0, rewardToken1, rewardToken2].filter(
|
|
2250
|
+
(x) => x.mint.equals(PublicKey.default) === false
|
|
2251
|
+
);
|
|
2252
|
+
let jupPrices: PubkeyHashMap<PublicKey, Decimal> = new PubkeyHashMap();
|
|
2253
|
+
|
|
2254
|
+
if (!disabledTokensPrices) {
|
|
2255
|
+
jupPrices = await JupService.getDollarPrices(validTokens.map((x) => x.mint));
|
|
2256
|
+
}
|
|
2257
|
+
const fallbackTokenAPrice = jupPrices.get(tokenA.mint) ?? new Decimal(0);
|
|
2258
|
+
const fallbackTokenBPrice = jupPrices.get(tokenB.mint) ?? new Decimal(0);
|
|
2259
|
+
const fallbackReward0Price = jupPrices.get(rewardToken0.mint) ?? new Decimal(0);
|
|
2260
|
+
const fallbackReward1Price = jupPrices.get(rewardToken1.mint) ?? new Decimal(0);
|
|
2261
|
+
const fallbackReward2Price = jupPrices.get(rewardToken2.mint) ?? new Decimal(0);
|
|
2262
|
+
|
|
2184
2263
|
const aPrice = Scope.isScopeChainValid(tokenA.scopePriceChain)
|
|
2185
2264
|
? (await this._scope.getPriceFromChain(tokenA.scopePriceChain, prices)).price
|
|
2186
|
-
:
|
|
2265
|
+
: fallbackTokenAPrice;
|
|
2187
2266
|
const bPrice = Scope.isScopeChainValid(tokenB.scopePriceChain)
|
|
2188
2267
|
? (await this._scope.getPriceFromChain(tokenB.scopePriceChain, prices)).price
|
|
2189
|
-
:
|
|
2268
|
+
: fallbackTokenBPrice;
|
|
2190
2269
|
const tokenATwap = stripTwapZeros(tokenA.scopeTwapPriceChain);
|
|
2191
2270
|
const tokenBTwap = stripTwapZeros(tokenB.scopeTwapPriceChain);
|
|
2192
2271
|
const aTwapPrice = Scope.isScopeChainValid(tokenATwap)
|
|
@@ -2200,19 +2279,19 @@ export class Kamino {
|
|
|
2200
2279
|
if (strategy.reward0Decimals.toNumber() !== 0) {
|
|
2201
2280
|
reward0Price = Scope.isScopeChainValid(rewardToken0.scopePriceChain)
|
|
2202
2281
|
? (await this._scope.getPriceFromChain(rewardToken0.scopePriceChain, prices)).price
|
|
2203
|
-
:
|
|
2282
|
+
: fallbackReward0Price;
|
|
2204
2283
|
}
|
|
2205
2284
|
let reward1Price = null;
|
|
2206
2285
|
if (strategy.reward1Decimals.toNumber() !== 0) {
|
|
2207
2286
|
reward1Price = Scope.isScopeChainValid(rewardToken1.scopePriceChain)
|
|
2208
2287
|
? (await this._scope.getPriceFromChain(rewardToken1.scopePriceChain, prices)).price
|
|
2209
|
-
:
|
|
2288
|
+
: fallbackReward1Price;
|
|
2210
2289
|
}
|
|
2211
2290
|
let reward2Price = null;
|
|
2212
2291
|
if (strategy.reward2Decimals.toNumber() !== 0) {
|
|
2213
2292
|
reward2Price = Scope.isScopeChainValid(rewardToken2.scopePriceChain)
|
|
2214
2293
|
? (await this._scope.getPriceFromChain(rewardToken2.scopePriceChain, prices)).price
|
|
2215
|
-
:
|
|
2294
|
+
: fallbackReward2Price;
|
|
2216
2295
|
}
|
|
2217
2296
|
|
|
2218
2297
|
return {
|
|
@@ -4,6 +4,9 @@ import axios from 'axios';
|
|
|
4
4
|
import Decimal from 'decimal.js';
|
|
5
5
|
import { DeserializedVersionedTransaction } from '../utils';
|
|
6
6
|
import { QuoteResponse, SwapInstructionsResponse, SwapResponse, createJupiterApiClient } from '@jup-ag/api';
|
|
7
|
+
import { PubkeyHashMap } from '../utils/pubkey';
|
|
8
|
+
|
|
9
|
+
const USDC_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
7
10
|
|
|
8
11
|
export type SwapTransactionsResponse = {
|
|
9
12
|
setupTransaction: string | undefined;
|
|
@@ -129,8 +132,40 @@ export class JupService {
|
|
|
129
132
|
return res.data.data[inputMint.toString()].price;
|
|
130
133
|
};
|
|
131
134
|
|
|
135
|
+
static getPrices = async (
|
|
136
|
+
inputMints: (PublicKey | string)[],
|
|
137
|
+
outputMint: PublicKey | string
|
|
138
|
+
): Promise<PubkeyHashMap<PublicKey, Decimal>> => {
|
|
139
|
+
const mintsCommaSeparated = inputMints.map((mint) => mint.toString()).join(',');
|
|
140
|
+
const params = {
|
|
141
|
+
ids: mintsCommaSeparated,
|
|
142
|
+
vsToken: outputMint.toString(),
|
|
143
|
+
vsAmount: 1,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// BONK token
|
|
147
|
+
if (outputMint.toString() === 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263') {
|
|
148
|
+
params.vsAmount = 100;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const res = await axios.get('https://api.jup.ag/price/v2', { params });
|
|
152
|
+
const prices: PubkeyHashMap<PublicKey, Decimal> = new PubkeyHashMap();
|
|
153
|
+
for (const mint of inputMints) {
|
|
154
|
+
try {
|
|
155
|
+
prices.set(new PublicKey(mint), new Decimal(res.data.data[mint.toString()].price));
|
|
156
|
+
} catch (e) {
|
|
157
|
+
prices.set(new PublicKey(mint), new Decimal(0));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return prices;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
static getDollarPrices(inputMints: (PublicKey | string)[]): Promise<PubkeyHashMap<PublicKey, Decimal>> {
|
|
165
|
+
return this.getPrices(inputMints, USDC_MINT);
|
|
166
|
+
}
|
|
167
|
+
|
|
132
168
|
static getDollarPrice = async (inputMint: PublicKey | string): Promise<number> => {
|
|
133
|
-
const USDC_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
134
169
|
return this.getPrice(inputMint, USDC_MINT);
|
|
135
170
|
};
|
|
136
171
|
|