@cowprotocol/sdk-trading 0.3.1 → 0.3.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/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -5
- package/dist/index.mjs +17 -5
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -371,6 +371,7 @@ interface SuggestSlippageBps {
|
|
|
371
371
|
quote: OrderQuoteResponse;
|
|
372
372
|
trader: QuoterParameters;
|
|
373
373
|
advancedSettings?: SwapAdvancedSettings;
|
|
374
|
+
volumeMultiplierPercent?: number;
|
|
374
375
|
}
|
|
375
376
|
/**
|
|
376
377
|
* Return the slippage in BPS that would allow the fee to increase by the multiplying factor percent.
|
package/dist/index.d.ts
CHANGED
|
@@ -371,6 +371,7 @@ interface SuggestSlippageBps {
|
|
|
371
371
|
quote: OrderQuoteResponse;
|
|
372
372
|
trader: QuoterParameters;
|
|
373
373
|
advancedSettings?: SwapAdvancedSettings;
|
|
374
|
+
volumeMultiplierPercent?: number;
|
|
374
375
|
}
|
|
375
376
|
/**
|
|
376
377
|
* Return the slippage in BPS that would allow the fee to increase by the multiplying factor percent.
|
package/dist/index.js
CHANGED
|
@@ -539,6 +539,10 @@ async function getOrderTypedData(chainId, orderToSign) {
|
|
|
539
539
|
};
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
+
// src/resolveSlippageSuggestion.ts
|
|
543
|
+
var import_sdk_common10 = require("@cowprotocol/sdk-common");
|
|
544
|
+
var import_sdk_order_book6 = require("@cowprotocol/sdk-order-book");
|
|
545
|
+
|
|
542
546
|
// src/suggestSlippageBps.ts
|
|
543
547
|
var import_sdk_common9 = require("@cowprotocol/sdk-common");
|
|
544
548
|
var import_sdk_order_book5 = require("@cowprotocol/sdk-order-book");
|
|
@@ -575,7 +579,13 @@ var MAX_SLIPPAGE_BPS = 1e4;
|
|
|
575
579
|
var SLIPPAGE_FEE_MULTIPLIER_PERCENT = 50;
|
|
576
580
|
var SLIPPAGE_VOLUME_MULTIPLIER_PERCENT = 0.5;
|
|
577
581
|
function suggestSlippageBps(params) {
|
|
578
|
-
const {
|
|
582
|
+
const {
|
|
583
|
+
quote,
|
|
584
|
+
tradeParameters,
|
|
585
|
+
trader,
|
|
586
|
+
isEthFlow,
|
|
587
|
+
volumeMultiplierPercent = SLIPPAGE_VOLUME_MULTIPLIER_PERCENT
|
|
588
|
+
} = params;
|
|
579
589
|
const { sellTokenDecimals, buyTokenDecimals } = tradeParameters;
|
|
580
590
|
const { isSell, sellAmountBeforeNetworkCosts, sellAmountAfterNetworkCosts } = (0, import_sdk_order_book5.getQuoteAmountsWithCosts)({
|
|
581
591
|
sellDecimals: sellTokenDecimals,
|
|
@@ -592,7 +602,7 @@ function suggestSlippageBps(params) {
|
|
|
592
602
|
isSell,
|
|
593
603
|
sellAmountBeforeNetworkCosts,
|
|
594
604
|
sellAmountAfterNetworkCosts,
|
|
595
|
-
slippagePercent:
|
|
605
|
+
slippagePercent: volumeMultiplierPercent
|
|
596
606
|
});
|
|
597
607
|
const totalSlippageBps = slippageBpsFromFee + slippageBpsFromVolume;
|
|
598
608
|
const slippagePercent = getSlippagePercent({
|
|
@@ -607,8 +617,6 @@ function suggestSlippageBps(params) {
|
|
|
607
617
|
}
|
|
608
618
|
|
|
609
619
|
// src/resolveSlippageSuggestion.ts
|
|
610
|
-
var import_sdk_order_book6 = require("@cowprotocol/sdk-order-book");
|
|
611
|
-
var import_sdk_common10 = require("@cowprotocol/sdk-common");
|
|
612
620
|
async function resolveSlippageSuggestion(chainId, tradeParameters, trader, quote, isEthFlow, advancedSettings) {
|
|
613
621
|
const suggestSlippageParams = {
|
|
614
622
|
isEthFlow,
|
|
@@ -638,8 +646,12 @@ async function resolveSlippageSuggestion(chainId, tradeParameters, trader, quote
|
|
|
638
646
|
sellAmount: amountsAndCosts.afterSlippage.sellAmount,
|
|
639
647
|
buyAmount: amountsAndCosts.afterSlippage.buyAmount
|
|
640
648
|
});
|
|
649
|
+
const suggestedSlippageBps = suggestedSlippage.slippageBps;
|
|
641
650
|
return {
|
|
642
|
-
slippageBps:
|
|
651
|
+
slippageBps: suggestedSlippageBps ? suggestSlippageBps({
|
|
652
|
+
...suggestSlippageParams,
|
|
653
|
+
volumeMultiplierPercent: (0, import_sdk_common10.bpsToPercentage)(suggestedSlippageBps)
|
|
654
|
+
}) : defaultSuggestion
|
|
643
655
|
};
|
|
644
656
|
} catch (e) {
|
|
645
657
|
(0, import_sdk_common10.log)(`getSlippageSuggestion() error: ${e.message || String(e)}`);
|
package/dist/index.mjs
CHANGED
|
@@ -504,6 +504,10 @@ async function getOrderTypedData(chainId, orderToSign) {
|
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
+
// src/resolveSlippageSuggestion.ts
|
|
508
|
+
import { bpsToPercentage, log as log3 } from "@cowprotocol/sdk-common";
|
|
509
|
+
import { getQuoteAmountsAndCosts as getQuoteAmountsAndCosts2, PriceQuality } from "@cowprotocol/sdk-order-book";
|
|
510
|
+
|
|
507
511
|
// src/suggestSlippageBps.ts
|
|
508
512
|
import { percentageToBps } from "@cowprotocol/sdk-common";
|
|
509
513
|
import { getQuoteAmountsWithCosts } from "@cowprotocol/sdk-order-book";
|
|
@@ -540,7 +544,13 @@ var MAX_SLIPPAGE_BPS = 1e4;
|
|
|
540
544
|
var SLIPPAGE_FEE_MULTIPLIER_PERCENT = 50;
|
|
541
545
|
var SLIPPAGE_VOLUME_MULTIPLIER_PERCENT = 0.5;
|
|
542
546
|
function suggestSlippageBps(params) {
|
|
543
|
-
const {
|
|
547
|
+
const {
|
|
548
|
+
quote,
|
|
549
|
+
tradeParameters,
|
|
550
|
+
trader,
|
|
551
|
+
isEthFlow,
|
|
552
|
+
volumeMultiplierPercent = SLIPPAGE_VOLUME_MULTIPLIER_PERCENT
|
|
553
|
+
} = params;
|
|
544
554
|
const { sellTokenDecimals, buyTokenDecimals } = tradeParameters;
|
|
545
555
|
const { isSell, sellAmountBeforeNetworkCosts, sellAmountAfterNetworkCosts } = getQuoteAmountsWithCosts({
|
|
546
556
|
sellDecimals: sellTokenDecimals,
|
|
@@ -557,7 +567,7 @@ function suggestSlippageBps(params) {
|
|
|
557
567
|
isSell,
|
|
558
568
|
sellAmountBeforeNetworkCosts,
|
|
559
569
|
sellAmountAfterNetworkCosts,
|
|
560
|
-
slippagePercent:
|
|
570
|
+
slippagePercent: volumeMultiplierPercent
|
|
561
571
|
});
|
|
562
572
|
const totalSlippageBps = slippageBpsFromFee + slippageBpsFromVolume;
|
|
563
573
|
const slippagePercent = getSlippagePercent({
|
|
@@ -572,8 +582,6 @@ function suggestSlippageBps(params) {
|
|
|
572
582
|
}
|
|
573
583
|
|
|
574
584
|
// src/resolveSlippageSuggestion.ts
|
|
575
|
-
import { getQuoteAmountsAndCosts as getQuoteAmountsAndCosts2, PriceQuality } from "@cowprotocol/sdk-order-book";
|
|
576
|
-
import { log as log3 } from "@cowprotocol/sdk-common";
|
|
577
585
|
async function resolveSlippageSuggestion(chainId, tradeParameters, trader, quote, isEthFlow, advancedSettings) {
|
|
578
586
|
const suggestSlippageParams = {
|
|
579
587
|
isEthFlow,
|
|
@@ -603,8 +611,12 @@ async function resolveSlippageSuggestion(chainId, tradeParameters, trader, quote
|
|
|
603
611
|
sellAmount: amountsAndCosts.afterSlippage.sellAmount,
|
|
604
612
|
buyAmount: amountsAndCosts.afterSlippage.buyAmount
|
|
605
613
|
});
|
|
614
|
+
const suggestedSlippageBps = suggestedSlippage.slippageBps;
|
|
606
615
|
return {
|
|
607
|
-
slippageBps:
|
|
616
|
+
slippageBps: suggestedSlippageBps ? suggestSlippageBps({
|
|
617
|
+
...suggestSlippageParams,
|
|
618
|
+
volumeMultiplierPercent: bpsToPercentage(suggestedSlippageBps)
|
|
619
|
+
}) : defaultSuggestion
|
|
608
620
|
};
|
|
609
621
|
} catch (e) {
|
|
610
622
|
log3(`getSlippageSuggestion() error: ${e.message || String(e)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-trading",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "CowProtocol trading",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
"ts-jest": "^29.0.0",
|
|
30
30
|
"tsx": "^4.19.4",
|
|
31
31
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
32
|
-
"@cowprotocol/sdk-ethers-v6-adapter": "0.1.
|
|
33
|
-
"@cowprotocol/sdk-
|
|
34
|
-
"@cowprotocol/sdk-
|
|
32
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "0.1.2",
|
|
33
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "0.1.2",
|
|
34
|
+
"@cowprotocol/sdk-viem-adapter": "0.1.2"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"deepmerge": "^4.3.1",
|
|
38
|
-
"@cowprotocol/sdk-common": "0.2.
|
|
39
|
-
"@cowprotocol/sdk-
|
|
40
|
-
"@cowprotocol/sdk-
|
|
41
|
-
"@cowprotocol/sdk-
|
|
42
|
-
"@cowprotocol/sdk-order-
|
|
43
|
-
"@cowprotocol/sdk-
|
|
38
|
+
"@cowprotocol/sdk-common": "0.2.1",
|
|
39
|
+
"@cowprotocol/sdk-config": "0.1.0",
|
|
40
|
+
"@cowprotocol/sdk-order-book": "0.1.2",
|
|
41
|
+
"@cowprotocol/sdk-app-data": "4.1.1",
|
|
42
|
+
"@cowprotocol/sdk-order-signing": "0.1.5",
|
|
43
|
+
"@cowprotocol/sdk-contracts-ts": "0.3.1"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|