@cowprotocol/sdk-trading-solana 0.5.1 → 0.7.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.
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/index.mjs +9 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -84,6 +84,8 @@ interface SolanaQuoteParameters {
|
|
|
84
84
|
partiallyFillable?: boolean;
|
|
85
85
|
/** Order lifetime from now, in seconds. Defaults to 30 minutes. */
|
|
86
86
|
validForSeconds?: number;
|
|
87
|
+
/** Slippage tolerance to sign, in basis points. Defaults to the one the quote reports. */
|
|
88
|
+
slippageBps?: number;
|
|
87
89
|
/** Token program owning `sellMint`'s accounts (classic SPL Token vs Token-2022). Defaults to the
|
|
88
90
|
* classic SPL Token program — pass `TOKEN_2022_PROGRAM_ID` explicitly for Token-2022 mints, since the
|
|
89
91
|
* associated token account address differs by program. */
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ interface SolanaQuoteParameters {
|
|
|
84
84
|
partiallyFillable?: boolean;
|
|
85
85
|
/** Order lifetime from now, in seconds. Defaults to 30 minutes. */
|
|
86
86
|
validForSeconds?: number;
|
|
87
|
+
/** Slippage tolerance to sign, in basis points. Defaults to the one the quote reports. */
|
|
88
|
+
slippageBps?: number;
|
|
87
89
|
/** Token program owning `sellMint`'s accounts (classic SPL Token vs Token-2022). Defaults to the
|
|
88
90
|
* classic SPL Token program — pass `TOKEN_2022_PROGRAM_ID` explicitly for Token-2022 mints, since the
|
|
89
91
|
* associated token account address differs by program. */
|
package/dist/index.js
CHANGED
|
@@ -226,6 +226,7 @@ var ZERO_APP_DATA = new Uint8Array(32);
|
|
|
226
226
|
var jupiterApi = new JupiterAPI();
|
|
227
227
|
async function getSolanaQuote(params, options = {}) {
|
|
228
228
|
const {
|
|
229
|
+
slippageBps: slippageBpsOverride,
|
|
229
230
|
ownerAddress,
|
|
230
231
|
receiverAddress,
|
|
231
232
|
sellTokenDecimals,
|
|
@@ -240,6 +241,9 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
240
241
|
if (!Number.isFinite(validForSeconds) || validForSeconds <= 0) {
|
|
241
242
|
throw new Error("validForSeconds must be a finite number greater than zero");
|
|
242
243
|
}
|
|
244
|
+
if (slippageBpsOverride !== void 0 && (!Number.isFinite(slippageBpsOverride) || slippageBpsOverride < 0)) {
|
|
245
|
+
throw new Error("slippageBps must be a finite number greater than or equal to zero");
|
|
246
|
+
}
|
|
243
247
|
const owner = new import_web35.PublicKey(ownerAddress);
|
|
244
248
|
const receiver = new import_web35.PublicKey(receiverAddress);
|
|
245
249
|
const requestedSellMint = new import_web35.PublicKey(params.sellTokenAddress);
|
|
@@ -255,6 +259,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
255
259
|
amount: amount.toString(),
|
|
256
260
|
swapMode: kind === import_sdk_order_book2.OrderKind.SELL ? "ExactIn" : "ExactOut"
|
|
257
261
|
});
|
|
262
|
+
const signedSlippageBps = slippageBpsOverride ?? jupiterOrder.slippageBps;
|
|
258
263
|
const validTo = Math.floor(Date.now() / 1e3) + validForSeconds;
|
|
259
264
|
const orderParams = {
|
|
260
265
|
sellToken: sellTokenAddress,
|
|
@@ -275,7 +280,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
275
280
|
};
|
|
276
281
|
const amountsAndCosts = (0, import_sdk_order_book2.getQuoteAmountsAndCosts)({
|
|
277
282
|
orderParams,
|
|
278
|
-
slippagePercentBps:
|
|
283
|
+
slippagePercentBps: signedSlippageBps,
|
|
279
284
|
// TODO: implement fees
|
|
280
285
|
partnerFeeBps: 0,
|
|
281
286
|
protocolFeeBps: 0
|
|
@@ -314,6 +319,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
314
319
|
verified: false
|
|
315
320
|
};
|
|
316
321
|
const tradeParameters = {
|
|
322
|
+
...slippageBpsOverride !== void 0 ? { slippageBps: slippageBpsOverride } : void 0,
|
|
317
323
|
kind,
|
|
318
324
|
owner: owner.toBase58(),
|
|
319
325
|
// The mint the caller asked for, not the substituted one: callers compare the returned parameters
|
|
@@ -331,6 +337,8 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
331
337
|
const quoteResults = {
|
|
332
338
|
quoteResponse,
|
|
333
339
|
amountsAndCosts,
|
|
340
|
+
// What the quote provider suggested, never the caller's own `slippageBps`: consumers read this as a
|
|
341
|
+
// recommendation and would otherwise be handed their own input back as advice.
|
|
334
342
|
suggestedSlippageBps: jupiterOrder.slippageBps,
|
|
335
343
|
tradeParameters,
|
|
336
344
|
orderToSign: {},
|
package/dist/index.mjs
CHANGED
|
@@ -187,6 +187,7 @@ var ZERO_APP_DATA = new Uint8Array(32);
|
|
|
187
187
|
var jupiterApi = new JupiterAPI();
|
|
188
188
|
async function getSolanaQuote(params, options = {}) {
|
|
189
189
|
const {
|
|
190
|
+
slippageBps: slippageBpsOverride,
|
|
190
191
|
ownerAddress,
|
|
191
192
|
receiverAddress,
|
|
192
193
|
sellTokenDecimals,
|
|
@@ -201,6 +202,9 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
201
202
|
if (!Number.isFinite(validForSeconds) || validForSeconds <= 0) {
|
|
202
203
|
throw new Error("validForSeconds must be a finite number greater than zero");
|
|
203
204
|
}
|
|
205
|
+
if (slippageBpsOverride !== void 0 && (!Number.isFinite(slippageBpsOverride) || slippageBpsOverride < 0)) {
|
|
206
|
+
throw new Error("slippageBps must be a finite number greater than or equal to zero");
|
|
207
|
+
}
|
|
204
208
|
const owner = new PublicKey5(ownerAddress);
|
|
205
209
|
const receiver = new PublicKey5(receiverAddress);
|
|
206
210
|
const requestedSellMint = new PublicKey5(params.sellTokenAddress);
|
|
@@ -216,6 +220,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
216
220
|
amount: amount.toString(),
|
|
217
221
|
swapMode: kind === OrderKind2.SELL ? "ExactIn" : "ExactOut"
|
|
218
222
|
});
|
|
223
|
+
const signedSlippageBps = slippageBpsOverride ?? jupiterOrder.slippageBps;
|
|
219
224
|
const validTo = Math.floor(Date.now() / 1e3) + validForSeconds;
|
|
220
225
|
const orderParams = {
|
|
221
226
|
sellToken: sellTokenAddress,
|
|
@@ -236,7 +241,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
236
241
|
};
|
|
237
242
|
const amountsAndCosts = getQuoteAmountsAndCosts({
|
|
238
243
|
orderParams,
|
|
239
|
-
slippagePercentBps:
|
|
244
|
+
slippagePercentBps: signedSlippageBps,
|
|
240
245
|
// TODO: implement fees
|
|
241
246
|
partnerFeeBps: 0,
|
|
242
247
|
protocolFeeBps: 0
|
|
@@ -275,6 +280,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
275
280
|
verified: false
|
|
276
281
|
};
|
|
277
282
|
const tradeParameters = {
|
|
283
|
+
...slippageBpsOverride !== void 0 ? { slippageBps: slippageBpsOverride } : void 0,
|
|
278
284
|
kind,
|
|
279
285
|
owner: owner.toBase58(),
|
|
280
286
|
// The mint the caller asked for, not the substituted one: callers compare the returned parameters
|
|
@@ -292,6 +298,8 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
292
298
|
const quoteResults = {
|
|
293
299
|
quoteResponse,
|
|
294
300
|
amountsAndCosts,
|
|
301
|
+
// What the quote provider suggested, never the caller's own `slippageBps`: consumers read this as a
|
|
302
|
+
// recommendation and would otherwise be handed their own input back as advice.
|
|
295
303
|
suggestedSlippageBps: jupiterOrder.slippageBps,
|
|
296
304
|
tradeParameters,
|
|
297
305
|
orderToSign: {},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-trading-solana",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "CowProtocol Solana trading: Jupiter-sourced quotes and on-chain CreateOrder posting against the Solana settlement program",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@cowprotocol/sdk-config": "2.6.0",
|
|
41
|
-
"@cowprotocol/sdk-order-book": "4.0.
|
|
42
|
-
"@cowprotocol/sdk-trading": "2.
|
|
41
|
+
"@cowprotocol/sdk-order-book": "4.0.5",
|
|
42
|
+
"@cowprotocol/sdk-trading": "2.5.0",
|
|
43
43
|
"@solana/spl-token": "0.4.14",
|
|
44
44
|
"@solana/web3.js": "1.98.4"
|
|
45
45
|
},
|