@kamino-finance/kliquidity-sdk 7.0.5 → 7.0.7
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 +72 -26
- 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 +30 -1
- package/dist/services/JupService.js.map +1 -1
- package/package.json +1 -1
- package/src/Kamino.ts +109 -26
- package/src/services/JupService.ts +37 -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,34 @@ 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
|
+
console.log('Error getting price for mint', mint);
|
|
108
|
+
prices.set(new web3_js_1.PublicKey(mint), new decimal_js_1.default(0));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return prices;
|
|
112
|
+
};
|
|
113
|
+
static getDollarPrices(inputMints) {
|
|
114
|
+
return this.getPrices(inputMints, USDC_MINT);
|
|
115
|
+
}
|
|
86
116
|
static getDollarPrice = async (inputMint) => {
|
|
87
|
-
const USDC_MINT = new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
88
117
|
return this.getPrice(inputMint, USDC_MINT);
|
|
89
118
|
};
|
|
90
119
|
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,C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AAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACnE,OAAO,UAAU,CAAC,qBAAqB,CAAC,UAAU,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;;AAvMJ,gCAwMC"}
|
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,
|
|
@@ -1536,9 +1545,10 @@ export class Kamino {
|
|
|
1536
1545
|
pool: PoolState,
|
|
1537
1546
|
position: PersonalPositionState,
|
|
1538
1547
|
collateralInfos: CollateralInfo[],
|
|
1539
|
-
prices?: OraclePrices
|
|
1548
|
+
prices?: OraclePrices,
|
|
1549
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1540
1550
|
): Promise<StrategyBalances> => {
|
|
1541
|
-
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices);
|
|
1551
|
+
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices, disabledTokensPrices);
|
|
1542
1552
|
const rebalanceKind = numberToRebalanceType(strategy.rebalanceType);
|
|
1543
1553
|
const tokenHoldings = this.getRaydiumTokensBalances(strategy, pool, position);
|
|
1544
1554
|
|
|
@@ -1608,9 +1618,10 @@ export class Kamino {
|
|
|
1608
1618
|
pool: LbPair,
|
|
1609
1619
|
position: PositionV2 | undefined, // the undefined is for scenarios where the position is not initialised yet
|
|
1610
1620
|
collateralInfos: CollateralInfo[],
|
|
1611
|
-
prices?: OraclePrices
|
|
1621
|
+
prices?: OraclePrices,
|
|
1622
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1612
1623
|
): Promise<StrategyBalances> => {
|
|
1613
|
-
const strategyPricesPromise = this.getStrategyPrices(strategy, collateralInfos, prices);
|
|
1624
|
+
const strategyPricesPromise = this.getStrategyPrices(strategy, collateralInfos, prices, disabledTokensPrices);
|
|
1614
1625
|
const rebalanceKind = numberToRebalanceType(strategy.rebalanceType);
|
|
1615
1626
|
const tokenHoldingsPromise = this.getMeteoraTokensBalances(strategy);
|
|
1616
1627
|
const [strategyPrices, tokenHoldings] = await Promise.all([strategyPricesPromise, tokenHoldingsPromise]);
|
|
@@ -1746,9 +1757,10 @@ export class Kamino {
|
|
|
1746
1757
|
position: Position,
|
|
1747
1758
|
collateralInfos: CollateralInfo[],
|
|
1748
1759
|
prices?: OraclePrices,
|
|
1749
|
-
mode: 'DEPOSIT' | 'WITHDRAW' = 'WITHDRAW'
|
|
1760
|
+
mode: 'DEPOSIT' | 'WITHDRAW' = 'WITHDRAW',
|
|
1761
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1750
1762
|
): Promise<StrategyBalances> => {
|
|
1751
|
-
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices);
|
|
1763
|
+
const strategyPrices = await this.getStrategyPrices(strategy, collateralInfos, prices, disabledTokensPrices);
|
|
1752
1764
|
const rebalanceKind = numberToRebalanceType(strategy.rebalanceType);
|
|
1753
1765
|
|
|
1754
1766
|
const tokenHoldings = this.getOrcaTokensBalances(strategy, pool, position, mode);
|
|
@@ -1892,15 +1904,21 @@ export class Kamino {
|
|
|
1892
1904
|
|
|
1893
1905
|
private getStrategyBalances = async (
|
|
1894
1906
|
strategy: WhirlpoolStrategy,
|
|
1895
|
-
scopePrices?: OraclePrices
|
|
1907
|
+
scopePrices?: OraclePrices,
|
|
1908
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1896
1909
|
): Promise<StrategyBalances> => {
|
|
1897
1910
|
const collateralInfos = await this.getCollateralInfos();
|
|
1911
|
+
let disabledPrices = disabledTokensPrices;
|
|
1912
|
+
if (!disabledPrices) {
|
|
1913
|
+
disabledPrices = await this.getDisabledTokensPrices(collateralInfos);
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1898
1916
|
if (strategy.strategyDex.toNumber() == dexToNumber('ORCA')) {
|
|
1899
|
-
return this.getStrategyBalancesOrca(strategy, collateralInfos, scopePrices);
|
|
1917
|
+
return this.getStrategyBalancesOrca(strategy, collateralInfos, scopePrices, disabledPrices);
|
|
1900
1918
|
} else if (strategy.strategyDex.toNumber() == dexToNumber('RAYDIUM')) {
|
|
1901
|
-
return this.getStrategyBalancesRaydium(strategy, collateralInfos, scopePrices);
|
|
1919
|
+
return this.getStrategyBalancesRaydium(strategy, collateralInfos, scopePrices, disabledPrices);
|
|
1902
1920
|
} else if (strategy.strategyDex.toNumber() == dexToNumber('METEORA')) {
|
|
1903
|
-
return this.getStrategyBalancesMeteora(strategy, collateralInfos, scopePrices);
|
|
1921
|
+
return this.getStrategyBalancesMeteora(strategy, collateralInfos, scopePrices, disabledPrices);
|
|
1904
1922
|
} else {
|
|
1905
1923
|
throw new Error(`Invalid dex ${strategy.strategyDex.toString()}`);
|
|
1906
1924
|
}
|
|
@@ -1989,7 +2007,8 @@ export class Kamino {
|
|
|
1989
2007
|
private getStrategyBalancesOrca = async (
|
|
1990
2008
|
strategy: WhirlpoolStrategy,
|
|
1991
2009
|
collateralInfos: CollateralInfo[],
|
|
1992
|
-
scopePrices?: OraclePrices
|
|
2010
|
+
scopePrices?: OraclePrices,
|
|
2011
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
1993
2012
|
): Promise<StrategyBalances> => {
|
|
1994
2013
|
const [whirlpoolAcc, positionAcc] = await this.getConnection().getMultipleAccountsInfo([
|
|
1995
2014
|
strategy.pool,
|
|
@@ -2006,13 +2025,22 @@ export class Kamino {
|
|
|
2006
2025
|
Position.decode(positionAcc.data),
|
|
2007
2026
|
]);
|
|
2008
2027
|
|
|
2009
|
-
return this.getOrcaBalances(
|
|
2028
|
+
return this.getOrcaBalances(
|
|
2029
|
+
strategy,
|
|
2030
|
+
whirlpool,
|
|
2031
|
+
position,
|
|
2032
|
+
collateralInfos,
|
|
2033
|
+
scopePrices,
|
|
2034
|
+
undefined,
|
|
2035
|
+
disabledTokensPrices
|
|
2036
|
+
);
|
|
2010
2037
|
};
|
|
2011
2038
|
|
|
2012
2039
|
private getStrategyBalancesRaydium = async (
|
|
2013
2040
|
strategy: WhirlpoolStrategy,
|
|
2014
2041
|
collateralInfos: CollateralInfo[],
|
|
2015
|
-
scopePrices?: OraclePrices
|
|
2042
|
+
scopePrices?: OraclePrices,
|
|
2043
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2016
2044
|
): Promise<StrategyBalances> => {
|
|
2017
2045
|
const [poolStateAcc, positionAcc] = await this.getConnection().getMultipleAccountsInfo([
|
|
2018
2046
|
strategy.pool,
|
|
@@ -2029,13 +2057,14 @@ export class Kamino {
|
|
|
2029
2057
|
PersonalPositionState.decode(positionAcc.data),
|
|
2030
2058
|
]);
|
|
2031
2059
|
|
|
2032
|
-
return this.getRaydiumBalances(strategy, poolState, position, collateralInfos, scopePrices);
|
|
2060
|
+
return this.getRaydiumBalances(strategy, poolState, position, collateralInfos, scopePrices, disabledTokensPrices);
|
|
2033
2061
|
};
|
|
2034
2062
|
|
|
2035
2063
|
private getStrategyBalancesMeteora = async (
|
|
2036
2064
|
strategy: WhirlpoolStrategy,
|
|
2037
2065
|
collateralInfos: CollateralInfo[],
|
|
2038
|
-
scopePrices?: OraclePrices
|
|
2066
|
+
scopePrices?: OraclePrices,
|
|
2067
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2039
2068
|
): Promise<StrategyBalances> => {
|
|
2040
2069
|
const [poolStateAcc, positionAcc] = await this.getConnection().getMultipleAccountsInfo([
|
|
2041
2070
|
strategy.pool,
|
|
@@ -2054,10 +2083,17 @@ export class Kamino {
|
|
|
2054
2083
|
PositionV2.decode(positionAcc.data),
|
|
2055
2084
|
]);
|
|
2056
2085
|
|
|
2057
|
-
return this.getMeteoraBalances(strategy, poolState, position, collateralInfos, scopePrices);
|
|
2086
|
+
return this.getMeteoraBalances(strategy, poolState, position, collateralInfos, scopePrices, disabledTokensPrices);
|
|
2058
2087
|
} catch (e) {
|
|
2059
2088
|
const poolState = LbPair.decode(poolStateAcc.data);
|
|
2060
|
-
return this.getMeteoraBalances(
|
|
2089
|
+
return this.getMeteoraBalances(
|
|
2090
|
+
strategy,
|
|
2091
|
+
poolState,
|
|
2092
|
+
undefined,
|
|
2093
|
+
collateralInfos,
|
|
2094
|
+
scopePrices,
|
|
2095
|
+
disabledTokensPrices
|
|
2096
|
+
);
|
|
2061
2097
|
}
|
|
2062
2098
|
};
|
|
2063
2099
|
|
|
@@ -2104,10 +2140,16 @@ export class Kamino {
|
|
|
2104
2140
|
* @param oraclePrices (optional) Scope Oracle prices
|
|
2105
2141
|
* @param collateralInfos (optional) Kamino Collateral Infos
|
|
2106
2142
|
*/
|
|
2107
|
-
getAllPrices = async (
|
|
2143
|
+
getAllPrices = async (
|
|
2144
|
+
oraclePrices?: OraclePrices,
|
|
2145
|
+
collateralInfos?: CollateralInfo[],
|
|
2146
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2147
|
+
): Promise<KaminoPrices> => {
|
|
2108
2148
|
// todo: make MintToPriceMap have Pubkey as key
|
|
2109
2149
|
const spotPrices: MintToPriceMap = {};
|
|
2110
2150
|
const twaps: MintToPriceMap = {};
|
|
2151
|
+
|
|
2152
|
+
const disabledTokens: PublicKey[] = [];
|
|
2111
2153
|
({ oraclePrices, collateralInfos } = await this.getOraclePricesAndCollateralInfos(oraclePrices, collateralInfos));
|
|
2112
2154
|
for (const collateralInfo of collateralInfos) {
|
|
2113
2155
|
if (
|
|
@@ -2130,8 +2172,33 @@ export class Kamino {
|
|
|
2130
2172
|
name: getTokenNameFromCollateralInfo(collateralInfo),
|
|
2131
2173
|
};
|
|
2132
2174
|
}
|
|
2175
|
+
} else {
|
|
2176
|
+
if (collateralInfo.mint.equals(PublicKey.default)) {
|
|
2177
|
+
continue;
|
|
2178
|
+
}
|
|
2179
|
+
disabledTokens.push(collateralInfo.mint);
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
try {
|
|
2184
|
+
const tokensPrices = disabledTokensPrices
|
|
2185
|
+
? disabledTokensPrices
|
|
2186
|
+
: await JupService.getDollarPrices(disabledTokens);
|
|
2187
|
+
for (const [token, price] of tokensPrices) {
|
|
2188
|
+
const collInfo = collateralInfos.find((x) => x.mint.equals(token));
|
|
2189
|
+
if (!collInfo) {
|
|
2190
|
+
console.log(`Could not find collateral info for token ${token.toString()}`);
|
|
2191
|
+
continue;
|
|
2192
|
+
}
|
|
2193
|
+
spotPrices[token.toString()] = {
|
|
2194
|
+
price: new Decimal(price),
|
|
2195
|
+
name: getTokenNameFromCollateralInfo(collInfo),
|
|
2196
|
+
};
|
|
2133
2197
|
}
|
|
2198
|
+
} catch (e) {
|
|
2199
|
+
console.error('Failed to get prices for disabled tokens from Jup', e);
|
|
2134
2200
|
}
|
|
2201
|
+
|
|
2135
2202
|
return { spot: spotPrices, twap: twaps };
|
|
2136
2203
|
};
|
|
2137
2204
|
|
|
@@ -2157,7 +2224,8 @@ export class Kamino {
|
|
|
2157
2224
|
getStrategyPrices = async (
|
|
2158
2225
|
strategy: WhirlpoolStrategy,
|
|
2159
2226
|
collateralInfos: CollateralInfo[],
|
|
2160
|
-
scopePrices?: OraclePrices
|
|
2227
|
+
scopePrices?: OraclePrices,
|
|
2228
|
+
disabledTokensPrices?: PubkeyHashMap<PublicKey, Decimal>
|
|
2161
2229
|
): Promise<StrategyPrices> => {
|
|
2162
2230
|
const tokenA = collateralInfos[strategy.tokenACollateralId.toNumber()];
|
|
2163
2231
|
const tokenB = collateralInfos[strategy.tokenBCollateralId.toNumber()];
|
|
@@ -2171,12 +2239,27 @@ export class Kamino {
|
|
|
2171
2239
|
} else {
|
|
2172
2240
|
prices = await this._scope.getOraclePrices({ prices: strategy.scopePrices });
|
|
2173
2241
|
}
|
|
2242
|
+
|
|
2243
|
+
const validTokens = [tokenA, tokenB, rewardToken0, rewardToken1, rewardToken2].filter(
|
|
2244
|
+
(x) => x.mint.equals(PublicKey.default) === false
|
|
2245
|
+
);
|
|
2246
|
+
let jupPrices: PubkeyHashMap<PublicKey, Decimal> = new PubkeyHashMap();
|
|
2247
|
+
|
|
2248
|
+
if (!disabledTokensPrices) {
|
|
2249
|
+
jupPrices = await JupService.getDollarPrices(validTokens.map((x) => x.mint));
|
|
2250
|
+
}
|
|
2251
|
+
const fallbackTokenAPrice = jupPrices.get(tokenA.mint) ?? new Decimal(0);
|
|
2252
|
+
const fallbackTokenBPrice = jupPrices.get(tokenB.mint) ?? new Decimal(0);
|
|
2253
|
+
const fallbackReward0Price = jupPrices.get(rewardToken0.mint) ?? new Decimal(0);
|
|
2254
|
+
const fallbackReward1Price = jupPrices.get(rewardToken1.mint) ?? new Decimal(0);
|
|
2255
|
+
const fallbackReward2Price = jupPrices.get(rewardToken2.mint) ?? new Decimal(0);
|
|
2256
|
+
|
|
2174
2257
|
const aPrice = Scope.isScopeChainValid(tokenA.scopePriceChain)
|
|
2175
2258
|
? (await this._scope.getPriceFromChain(tokenA.scopePriceChain, prices)).price
|
|
2176
|
-
:
|
|
2259
|
+
: fallbackTokenAPrice;
|
|
2177
2260
|
const bPrice = Scope.isScopeChainValid(tokenB.scopePriceChain)
|
|
2178
2261
|
? (await this._scope.getPriceFromChain(tokenB.scopePriceChain, prices)).price
|
|
2179
|
-
:
|
|
2262
|
+
: fallbackTokenBPrice;
|
|
2180
2263
|
const tokenATwap = stripTwapZeros(tokenA.scopeTwapPriceChain);
|
|
2181
2264
|
const tokenBTwap = stripTwapZeros(tokenB.scopeTwapPriceChain);
|
|
2182
2265
|
const aTwapPrice = Scope.isScopeChainValid(tokenATwap)
|
|
@@ -2190,19 +2273,19 @@ export class Kamino {
|
|
|
2190
2273
|
if (strategy.reward0Decimals.toNumber() !== 0) {
|
|
2191
2274
|
reward0Price = Scope.isScopeChainValid(rewardToken0.scopePriceChain)
|
|
2192
2275
|
? (await this._scope.getPriceFromChain(rewardToken0.scopePriceChain, prices)).price
|
|
2193
|
-
:
|
|
2276
|
+
: fallbackReward0Price;
|
|
2194
2277
|
}
|
|
2195
2278
|
let reward1Price = null;
|
|
2196
2279
|
if (strategy.reward1Decimals.toNumber() !== 0) {
|
|
2197
2280
|
reward1Price = Scope.isScopeChainValid(rewardToken1.scopePriceChain)
|
|
2198
2281
|
? (await this._scope.getPriceFromChain(rewardToken1.scopePriceChain, prices)).price
|
|
2199
|
-
:
|
|
2282
|
+
: fallbackReward1Price;
|
|
2200
2283
|
}
|
|
2201
2284
|
let reward2Price = null;
|
|
2202
2285
|
if (strategy.reward2Decimals.toNumber() !== 0) {
|
|
2203
2286
|
reward2Price = Scope.isScopeChainValid(rewardToken2.scopePriceChain)
|
|
2204
2287
|
? (await this._scope.getPriceFromChain(rewardToken2.scopePriceChain, prices)).price
|
|
2205
|
-
:
|
|
2288
|
+
: fallbackReward2Price;
|
|
2206
2289
|
}
|
|
2207
2290
|
|
|
2208
2291
|
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,41 @@ 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
|
+
console.log('Error getting price for mint', mint);
|
|
158
|
+
prices.set(new PublicKey(mint), new Decimal(0));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return prices;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
static getDollarPrices(inputMints: (PublicKey | string)[]): Promise<PubkeyHashMap<PublicKey, Decimal>> {
|
|
166
|
+
return this.getPrices(inputMints, USDC_MINT);
|
|
167
|
+
}
|
|
168
|
+
|
|
132
169
|
static getDollarPrice = async (inputMint: PublicKey | string): Promise<number> => {
|
|
133
|
-
const USDC_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
134
170
|
return this.getPrice(inputMint, USDC_MINT);
|
|
135
171
|
};
|
|
136
172
|
|