@kamino-finance/kliquidity-sdk 7.0.9 → 7.0.10
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 +2 -1
- package/dist/Kamino.d.ts.map +1 -1
- package/dist/Kamino.js +7 -3
- package/dist/Kamino.js.map +1 -1
- package/dist/services/JupService.d.ts +6 -5
- package/dist/services/JupService.d.ts.map +1 -1
- package/dist/services/JupService.js +16 -12
- package/dist/services/JupService.js.map +1 -1
- package/package.json +1 -1
- package/src/Kamino.ts +13 -4
- package/src/services/JupService.ts +25 -12
|
@@ -4,6 +4,7 @@ import Decimal from 'decimal.js';
|
|
|
4
4
|
import { DeserializedVersionedTransaction } from '../utils';
|
|
5
5
|
import { QuoteResponse, SwapInstructionsResponse, SwapResponse } from '@jup-ag/api';
|
|
6
6
|
import { PubkeyHashMap } from '../utils/pubkey';
|
|
7
|
+
export declare const DEFAULT_JUP_API_ENDPOINT = "https://api.jup.ag";
|
|
7
8
|
export type SwapTransactionsResponse = {
|
|
8
9
|
setupTransaction: string | undefined;
|
|
9
10
|
swapTransaction: string;
|
|
@@ -14,12 +15,12 @@ export declare class JupService {
|
|
|
14
15
|
private readonly _cluster;
|
|
15
16
|
constructor(connection: Connection, cluster: SolanaCluster);
|
|
16
17
|
static getBestRouteV6: (userPublicKey: PublicKey, amount: Decimal, inputMint: PublicKey, outputMint: PublicKey, slippageBps: number, asLegacyTransaction?: boolean, maxAccounts?: number, onlyDirectRoutes?: boolean) => Promise<SwapResponse>;
|
|
17
|
-
static getBestRouteQuoteV6: (amount: Decimal, inputMint: PublicKey, outputMint: PublicKey, slippageBps: number, asLegacyTransaction?: boolean, maxAccounts?: number, onlyDirectRoutes?: boolean) => Promise<QuoteResponse>;
|
|
18
|
+
static getBestRouteQuoteV6: (amount: Decimal, inputMint: PublicKey, outputMint: PublicKey, slippageBps: number, asLegacyTransaction?: boolean, maxAccounts?: number, onlyDirectRoutes?: boolean, jupEndpoint?: string) => Promise<QuoteResponse>;
|
|
18
19
|
static getSwapIxsFromQuote: (userPublicKey: PublicKey, quote: QuoteResponse, wrapUnwrapSOL?: boolean, asLegacyTransaction?: boolean) => Promise<SwapInstructionsResponse>;
|
|
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>>;
|
|
22
|
-
static getDollarPrice: (inputMint: PublicKey | string) => Promise<number>;
|
|
20
|
+
static getPrice: (inputMint: PublicKey | string, outputMint: PublicKey | string, jupEndpoint?: string) => Promise<number>;
|
|
21
|
+
static getPrices: (inputMints: (PublicKey | string)[], outputMint: PublicKey | string, jupEndpoint?: string) => Promise<PubkeyHashMap<PublicKey, Decimal>>;
|
|
22
|
+
static getDollarPrices(inputMints: (PublicKey | string)[], jupEndpoint?: string): Promise<PubkeyHashMap<PublicKey, Decimal>>;
|
|
23
|
+
static getDollarPrice: (inputMint: PublicKey | string, jupEndpoint?: string) => Promise<number>;
|
|
23
24
|
static buildTransactionsFromSerialized: (serializedTransactions: Array<string | undefined>) => Transaction[];
|
|
24
25
|
static deserealizeVersionedTransactions: (connection: Connection, serializedTransactions: Array<string | undefined>) => Promise<DeserializedVersionedTransaction>;
|
|
25
26
|
static getLookupTableAccount: (connection: Connection, address: string | PublicKey) => Promise<import("@solana/web3.js").AddressLookupTableAccount | null>;
|
|
@@ -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;AAE9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AO,CAAC,CAAC;IAI7C,MAAM,CAAC,cAAc,cAAqB,SAAS,GAAG,MAAM,gBAAgB,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,CAElG;IAEF,MAAM,CAAC,+BAA+B,2BAA4B,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,KAAG,WAAW,EAAE,CAKzG;IAEF,MAAM,CAAC,gCAAgC,eACzB,UAAU,0BACE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,KAChD,OAAO,CAAC,gCAAgC,CAAC,CA6B1C;IAEF,MAAM,CAAC,qBAAqB,eAAsB,UAAU,WAAW,MAAM,GAAG,SAAS,yEAEvF;CACH"}
|
|
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JupService = void 0;
|
|
6
|
+
exports.JupService = exports.DEFAULT_JUP_API_ENDPOINT = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
10
10
|
const api_1 = require("@jup-ag/api");
|
|
11
11
|
const pubkey_1 = require("../utils/pubkey");
|
|
12
12
|
const USDC_MINT = new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
13
|
+
exports.DEFAULT_JUP_API_ENDPOINT = 'https://api.jup.ag';
|
|
13
14
|
class JupService {
|
|
14
15
|
_connection;
|
|
15
16
|
_cluster;
|
|
@@ -37,9 +38,8 @@ class JupService {
|
|
|
37
38
|
throw error;
|
|
38
39
|
}
|
|
39
40
|
};
|
|
40
|
-
static getBestRouteQuoteV6 = async (amount, inputMint, outputMint, slippageBps, asLegacyTransaction, maxAccounts, onlyDirectRoutes) => {
|
|
41
|
+
static getBestRouteQuoteV6 = async (amount, inputMint, outputMint, slippageBps, asLegacyTransaction, maxAccounts, onlyDirectRoutes, jupEndpoint) => {
|
|
41
42
|
try {
|
|
42
|
-
const jupiterQuoteApi = (0, api_1.createJupiterApiClient)(); // config is optional
|
|
43
43
|
const params = {
|
|
44
44
|
inputMint: inputMint.toString(),
|
|
45
45
|
outputMint: outputMint.toString(),
|
|
@@ -49,7 +49,9 @@ class JupService {
|
|
|
49
49
|
asLegacyTransaction,
|
|
50
50
|
maxAccounts,
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
const baseURL = jupEndpoint || exports.DEFAULT_JUP_API_ENDPOINT;
|
|
53
|
+
const res = await axios_1.default.get(`${baseURL}/swap/v1/quote`, { params });
|
|
54
|
+
return res.data;
|
|
53
55
|
}
|
|
54
56
|
catch (error) {
|
|
55
57
|
console.log('getBestRouteQuoteV6 error', error);
|
|
@@ -73,7 +75,7 @@ class JupService {
|
|
|
73
75
|
throw error;
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
|
-
static getPrice = async (inputMint, outputMint) => {
|
|
78
|
+
static getPrice = async (inputMint, outputMint, jupEndpoint) => {
|
|
77
79
|
const params = {
|
|
78
80
|
ids: inputMint.toString(),
|
|
79
81
|
vsToken: outputMint.toString(),
|
|
@@ -83,10 +85,11 @@ class JupService {
|
|
|
83
85
|
if (outputMint.toString() === 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263') {
|
|
84
86
|
params.vsAmount = 100;
|
|
85
87
|
}
|
|
86
|
-
const
|
|
88
|
+
const baseURL = jupEndpoint || exports.DEFAULT_JUP_API_ENDPOINT;
|
|
89
|
+
const res = await axios_1.default.get(`${baseURL}/price/v2`, { params });
|
|
87
90
|
return res.data.data[inputMint.toString()].price;
|
|
88
91
|
};
|
|
89
|
-
static getPrices = async (inputMints, outputMint) => {
|
|
92
|
+
static getPrices = async (inputMints, outputMint, jupEndpoint) => {
|
|
90
93
|
const mintsCommaSeparated = inputMints.map((mint) => mint.toString()).join(',');
|
|
91
94
|
const params = {
|
|
92
95
|
ids: mintsCommaSeparated,
|
|
@@ -97,7 +100,8 @@ class JupService {
|
|
|
97
100
|
if (outputMint.toString() === 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263') {
|
|
98
101
|
params.vsAmount = 100;
|
|
99
102
|
}
|
|
100
|
-
const
|
|
103
|
+
const baseURL = jupEndpoint || exports.DEFAULT_JUP_API_ENDPOINT;
|
|
104
|
+
const res = await axios_1.default.get(`${baseURL}/price/v2`, { params });
|
|
101
105
|
const prices = new pubkey_1.PubkeyHashMap();
|
|
102
106
|
for (const mint of inputMints) {
|
|
103
107
|
try {
|
|
@@ -109,11 +113,11 @@ class JupService {
|
|
|
109
113
|
}
|
|
110
114
|
return prices;
|
|
111
115
|
};
|
|
112
|
-
static getDollarPrices(inputMints) {
|
|
113
|
-
return this.getPrices(inputMints, USDC_MINT);
|
|
116
|
+
static getDollarPrices(inputMints, jupEndpoint) {
|
|
117
|
+
return this.getPrices(inputMints, USDC_MINT, jupEndpoint);
|
|
114
118
|
}
|
|
115
|
-
static getDollarPrice = async (inputMint) => {
|
|
116
|
-
return this.getPrice(inputMint, USDC_MINT);
|
|
119
|
+
static getDollarPrice = async (inputMint, jupEndpoint) => {
|
|
120
|
+
return this.getPrice(inputMint, USDC_MINT, jupEndpoint);
|
|
117
121
|
};
|
|
118
122
|
static buildTransactionsFromSerialized = (serializedTransactions) => {
|
|
119
123
|
return serializedTransactions.filter(Boolean).map((tx) => {
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"JupService.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A0B,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;;AAjNJ,gCAkNC"}
|
package/package.json
CHANGED
package/src/Kamino.ts
CHANGED
|
@@ -237,7 +237,7 @@ import {
|
|
|
237
237
|
TakeProfitMethod,
|
|
238
238
|
} from './utils/CreationParameters';
|
|
239
239
|
import { DOLAR_BASED, PROPORTION_BASED } from './constants/deposit_method';
|
|
240
|
-
import { JupService } from './services/JupService';
|
|
240
|
+
import { DEFAULT_JUP_API_ENDPOINT, JupService } from './services/JupService';
|
|
241
241
|
import {
|
|
242
242
|
simulateManualPool,
|
|
243
243
|
simulatePercentagePool,
|
|
@@ -359,6 +359,7 @@ export class Kamino {
|
|
|
359
359
|
private readonly _orcaService: OrcaService;
|
|
360
360
|
private readonly _raydiumService: RaydiumService;
|
|
361
361
|
private readonly _meteoraService: MeteoraService;
|
|
362
|
+
private readonly _jupBaseAPI: string = DEFAULT_JUP_API_ENDPOINT;
|
|
362
363
|
|
|
363
364
|
/**
|
|
364
365
|
* Create a new instance of the Kamino SDK class.
|
|
@@ -376,7 +377,8 @@ export class Kamino {
|
|
|
376
377
|
programId?: PublicKey,
|
|
377
378
|
whirlpoolProgramId?: PublicKey,
|
|
378
379
|
raydiumProgramId?: PublicKey,
|
|
379
|
-
meteoraProgramId?: PublicKey
|
|
380
|
+
meteoraProgramId?: PublicKey,
|
|
381
|
+
jupBaseAPI?: string
|
|
380
382
|
) {
|
|
381
383
|
this._cluster = cluster;
|
|
382
384
|
this._connection = connection;
|
|
@@ -412,6 +414,10 @@ export class Kamino {
|
|
|
412
414
|
this._orcaService = new OrcaService(connection, cluster, whirlpoolProgramId);
|
|
413
415
|
this._raydiumService = new RaydiumService(connection, raydiumProgramId);
|
|
414
416
|
this._meteoraService = new MeteoraService(connection, meteoraProgramId);
|
|
417
|
+
|
|
418
|
+
if (jupBaseAPI) {
|
|
419
|
+
this._jupBaseAPI = jupBaseAPI;
|
|
420
|
+
}
|
|
415
421
|
}
|
|
416
422
|
|
|
417
423
|
getConnection = () => this._connection;
|
|
@@ -442,7 +448,10 @@ export class Kamino {
|
|
|
442
448
|
getDisabledTokensPrices = async (collateralInfos?: CollateralInfo[]) => {
|
|
443
449
|
const collInfos = collateralInfos ? collateralInfos : await this.getCollateralInfos();
|
|
444
450
|
const disabledTokens = collInfos.filter((x) => x.disabled && !x.mint.equals(PublicKey.default));
|
|
445
|
-
return JupService.getDollarPrices(
|
|
451
|
+
return JupService.getDollarPrices(
|
|
452
|
+
disabledTokens.map((x) => x.mint),
|
|
453
|
+
this._jupBaseAPI
|
|
454
|
+
);
|
|
446
455
|
};
|
|
447
456
|
|
|
448
457
|
getSupportedDexes = (): Dex[] => ['ORCA', 'RAYDIUM', 'METEORA'];
|
|
@@ -2189,7 +2198,7 @@ export class Kamino {
|
|
|
2189
2198
|
try {
|
|
2190
2199
|
const tokensPrices = disabledTokensPrices
|
|
2191
2200
|
? disabledTokensPrices
|
|
2192
|
-
: await JupService.getDollarPrices(disabledTokens);
|
|
2201
|
+
: await JupService.getDollarPrices(disabledTokens, this._jupBaseAPI);
|
|
2193
2202
|
for (const [token, price] of tokensPrices) {
|
|
2194
2203
|
const collInfo = collateralInfos.find((x) => x.mint.equals(token));
|
|
2195
2204
|
if (!collInfo) {
|
|
@@ -8,6 +8,8 @@ import { PubkeyHashMap } from '../utils/pubkey';
|
|
|
8
8
|
|
|
9
9
|
const USDC_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
10
10
|
|
|
11
|
+
export const DEFAULT_JUP_API_ENDPOINT = 'https://api.jup.ag';
|
|
12
|
+
|
|
11
13
|
export type SwapTransactionsResponse = {
|
|
12
14
|
setupTransaction: string | undefined;
|
|
13
15
|
swapTransaction: string;
|
|
@@ -71,11 +73,10 @@ export class JupService {
|
|
|
71
73
|
slippageBps: number,
|
|
72
74
|
asLegacyTransaction?: boolean,
|
|
73
75
|
maxAccounts?: number,
|
|
74
|
-
onlyDirectRoutes?: boolean
|
|
76
|
+
onlyDirectRoutes?: boolean,
|
|
77
|
+
jupEndpoint?: string
|
|
75
78
|
): Promise<QuoteResponse> => {
|
|
76
79
|
try {
|
|
77
|
-
const jupiterQuoteApi = createJupiterApiClient(); // config is optional
|
|
78
|
-
|
|
79
80
|
const params = {
|
|
80
81
|
inputMint: inputMint.toString(),
|
|
81
82
|
outputMint: outputMint.toString(),
|
|
@@ -86,7 +87,9 @@ export class JupService {
|
|
|
86
87
|
maxAccounts,
|
|
87
88
|
};
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
const baseURL = jupEndpoint || DEFAULT_JUP_API_ENDPOINT;
|
|
91
|
+
const res = await axios.get(`${baseURL}/swap/v1/quote`, { params });
|
|
92
|
+
return res.data as QuoteResponse;
|
|
90
93
|
} catch (error) {
|
|
91
94
|
console.log('getBestRouteQuoteV6 error', error);
|
|
92
95
|
throw error;
|
|
@@ -116,7 +119,11 @@ export class JupService {
|
|
|
116
119
|
}
|
|
117
120
|
};
|
|
118
121
|
|
|
119
|
-
static getPrice = async (
|
|
122
|
+
static getPrice = async (
|
|
123
|
+
inputMint: PublicKey | string,
|
|
124
|
+
outputMint: PublicKey | string,
|
|
125
|
+
jupEndpoint?: string
|
|
126
|
+
): Promise<number> => {
|
|
120
127
|
const params = {
|
|
121
128
|
ids: inputMint.toString(),
|
|
122
129
|
vsToken: outputMint.toString(),
|
|
@@ -128,13 +135,15 @@ export class JupService {
|
|
|
128
135
|
params.vsAmount = 100;
|
|
129
136
|
}
|
|
130
137
|
|
|
131
|
-
const
|
|
138
|
+
const baseURL = jupEndpoint || DEFAULT_JUP_API_ENDPOINT;
|
|
139
|
+
const res = await axios.get(`${baseURL}/price/v2`, { params });
|
|
132
140
|
return res.data.data[inputMint.toString()].price;
|
|
133
141
|
};
|
|
134
142
|
|
|
135
143
|
static getPrices = async (
|
|
136
144
|
inputMints: (PublicKey | string)[],
|
|
137
|
-
outputMint: PublicKey | string
|
|
145
|
+
outputMint: PublicKey | string,
|
|
146
|
+
jupEndpoint?: string
|
|
138
147
|
): Promise<PubkeyHashMap<PublicKey, Decimal>> => {
|
|
139
148
|
const mintsCommaSeparated = inputMints.map((mint) => mint.toString()).join(',');
|
|
140
149
|
const params = {
|
|
@@ -148,7 +157,8 @@ export class JupService {
|
|
|
148
157
|
params.vsAmount = 100;
|
|
149
158
|
}
|
|
150
159
|
|
|
151
|
-
const
|
|
160
|
+
const baseURL = jupEndpoint || DEFAULT_JUP_API_ENDPOINT;
|
|
161
|
+
const res = await axios.get(`${baseURL}/price/v2`, { params });
|
|
152
162
|
const prices: PubkeyHashMap<PublicKey, Decimal> = new PubkeyHashMap();
|
|
153
163
|
for (const mint of inputMints) {
|
|
154
164
|
try {
|
|
@@ -161,12 +171,15 @@ export class JupService {
|
|
|
161
171
|
return prices;
|
|
162
172
|
};
|
|
163
173
|
|
|
164
|
-
static getDollarPrices(
|
|
165
|
-
|
|
174
|
+
static getDollarPrices(
|
|
175
|
+
inputMints: (PublicKey | string)[],
|
|
176
|
+
jupEndpoint?: string
|
|
177
|
+
): Promise<PubkeyHashMap<PublicKey, Decimal>> {
|
|
178
|
+
return this.getPrices(inputMints, USDC_MINT, jupEndpoint);
|
|
166
179
|
}
|
|
167
180
|
|
|
168
|
-
static getDollarPrice = async (inputMint: PublicKey | string): Promise<number> => {
|
|
169
|
-
return this.getPrice(inputMint, USDC_MINT);
|
|
181
|
+
static getDollarPrice = async (inputMint: PublicKey | string, jupEndpoint?: string): Promise<number> => {
|
|
182
|
+
return this.getPrice(inputMint, USDC_MINT, jupEndpoint);
|
|
170
183
|
};
|
|
171
184
|
|
|
172
185
|
static buildTransactionsFromSerialized = (serializedTransactions: Array<string | undefined>): Transaction[] => {
|