@cowprotocol/sdk-order-book 3.2.2 → 4.0.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/README.md +6 -0
- package/dist/index.d.mts +73 -5
- package/dist/index.d.ts +73 -5
- package/dist/index.js +7 -8
- package/dist/index.mjs +7 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
# SDK Order Book
|
|
6
6
|
|
|
7
|
+
## Test coverage
|
|
8
|
+
|
|
9
|
+
| Statements | Branches | Functions | Lines |
|
|
10
|
+
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
11
|
+
|  |  |  |  |
|
|
12
|
+
|
|
7
13
|
This package provides a comprehensive API client for interacting with the CoW Protocol Order Book. It handles order submission, retrieval, cancellation, and trading data with built-in rate limiting, retries, and error handling.
|
|
8
14
|
|
|
9
15
|
## Installation
|
package/dist/index.d.mts
CHANGED
|
@@ -832,7 +832,7 @@ type DebugOrderResponse = {
|
|
|
832
832
|
/**
|
|
833
833
|
* How was the order signed?
|
|
834
834
|
*/
|
|
835
|
-
declare enum EcdsaSigningScheme {
|
|
835
|
+
declare enum EcdsaSigningScheme$1 {
|
|
836
836
|
EIP712 = "eip712",
|
|
837
837
|
ETHSIGN = "ethsign"
|
|
838
838
|
}
|
|
@@ -859,12 +859,12 @@ type NativePriceResponse = {
|
|
|
859
859
|
* `OrderCancellation(bytes orderUid)` from the order's owner.
|
|
860
860
|
*
|
|
861
861
|
*/
|
|
862
|
-
type OrderCancellation = {
|
|
862
|
+
type OrderCancellation$1 = {
|
|
863
863
|
/**
|
|
864
864
|
* OrderCancellation signed by owner
|
|
865
865
|
*/
|
|
866
866
|
signature: EcdsaSignature;
|
|
867
|
-
signingScheme: EcdsaSigningScheme;
|
|
867
|
+
signingScheme: EcdsaSigningScheme$1;
|
|
868
868
|
};
|
|
869
869
|
|
|
870
870
|
type OrderCancellationError = {
|
|
@@ -887,7 +887,7 @@ declare namespace OrderCancellationError {
|
|
|
887
887
|
* EIP-712 signature of struct OrderCancellations { orderUid: bytes[] } from the order's owner.
|
|
888
888
|
*
|
|
889
889
|
*/
|
|
890
|
-
type OrderCancellations = {
|
|
890
|
+
type OrderCancellations$1 = {
|
|
891
891
|
/**
|
|
892
892
|
* Up to 128 UIDs of orders to cancel.
|
|
893
893
|
*/
|
|
@@ -896,7 +896,7 @@ type OrderCancellations = {
|
|
|
896
896
|
* `OrderCancellation` signed by the owner.
|
|
897
897
|
*/
|
|
898
898
|
signature: EcdsaSignature;
|
|
899
|
-
signingScheme: EcdsaSigningScheme;
|
|
899
|
+
signingScheme: EcdsaSigningScheme$1;
|
|
900
900
|
};
|
|
901
901
|
|
|
902
902
|
/**
|
|
@@ -1609,6 +1609,74 @@ interface QuoteAmountsAndCosts<T = bigint> {
|
|
|
1609
1609
|
amountsToSign: Amounts<T>;
|
|
1610
1610
|
}
|
|
1611
1611
|
|
|
1612
|
+
/**
|
|
1613
|
+
* The subset of {@link SigningScheme} values that can be produced by signing an
|
|
1614
|
+
* order with an ECDSA key (i.e. `eip712` and `ethsign`).
|
|
1615
|
+
*
|
|
1616
|
+
* The orderbook OpenAPI spec models `EcdsaSigningScheme` and `SigningScheme` as
|
|
1617
|
+
* two independent string enums. When generated as TypeScript `enum`s they become
|
|
1618
|
+
* nominally unrelated types, so an `EcdsaSigningScheme` value is not assignable
|
|
1619
|
+
* to a `SigningScheme` field even though every `EcdsaSigningScheme` value is a
|
|
1620
|
+
* valid `SigningScheme` value.
|
|
1621
|
+
*
|
|
1622
|
+
* This caused a type error in the documented low-level flow, where the result of
|
|
1623
|
+
* `OrderSigningUtils.signOrder()` (which carries `EcdsaSigningScheme`) is spread
|
|
1624
|
+
* into the `OrderCreation` body of `OrderBookApi.sendOrder()` (which expects
|
|
1625
|
+
* `SigningScheme`):
|
|
1626
|
+
*
|
|
1627
|
+
* ```ts
|
|
1628
|
+
* const { quote } = await orderBookApi.getQuote(quoteRequest)
|
|
1629
|
+
* const orderSigningResult = await OrderSigningUtils.signOrder(quote, chainId, signer)
|
|
1630
|
+
* // previously failed: EcdsaSigningScheme not assignable to SigningScheme
|
|
1631
|
+
* const orderId = await orderBookApi.sendOrder({ ...quote, ...orderSigningResult })
|
|
1632
|
+
* ```
|
|
1633
|
+
*
|
|
1634
|
+
* To fix this `EcdsaSigningScheme` is defined here as a genuine subset of
|
|
1635
|
+
* `SigningScheme` rather than a standalone enum. It keeps the same runtime values
|
|
1636
|
+
* and member names, so existing usages (`EcdsaSigningScheme.EIP712`,
|
|
1637
|
+
* `Record<EcdsaSigningScheme, T>`, etc.) keep working, while values are now
|
|
1638
|
+
* assignable to `SigningScheme`.
|
|
1639
|
+
*
|
|
1640
|
+
* @see https://github.com/cowprotocol/cow-sdk/issues/187
|
|
1641
|
+
*/
|
|
1642
|
+
declare const EcdsaSigningScheme: {
|
|
1643
|
+
readonly EIP712: SigningScheme.EIP712;
|
|
1644
|
+
readonly ETHSIGN: SigningScheme.ETHSIGN;
|
|
1645
|
+
};
|
|
1646
|
+
/**
|
|
1647
|
+
* How was the order signed?
|
|
1648
|
+
*
|
|
1649
|
+
* Subset of {@link SigningScheme} restricted to the schemes produced by ECDSA
|
|
1650
|
+
* signing (`eip712` and `ethsign`). Values are assignable to `SigningScheme`.
|
|
1651
|
+
*/
|
|
1652
|
+
type EcdsaSigningScheme = (typeof EcdsaSigningScheme)[keyof typeof EcdsaSigningScheme];
|
|
1653
|
+
/**
|
|
1654
|
+
* Data a user provides when cancelling a single order.
|
|
1655
|
+
*
|
|
1656
|
+
* Re-typed on top of the generated `OrderCancellation` so its `signingScheme`
|
|
1657
|
+
* uses the {@link EcdsaSigningScheme} subset of `SigningScheme`. This keeps the
|
|
1658
|
+
* result of `OrderSigningUtils.signOrderCancellation()` directly assignable to
|
|
1659
|
+
* this type.
|
|
1660
|
+
*
|
|
1661
|
+
* @see https://github.com/cowprotocol/cow-sdk/issues/187
|
|
1662
|
+
*/
|
|
1663
|
+
type OrderCancellation = Omit<OrderCancellation$1, 'signingScheme'> & {
|
|
1664
|
+
signingScheme: EcdsaSigningScheme;
|
|
1665
|
+
};
|
|
1666
|
+
/**
|
|
1667
|
+
* Data a user provides when cancelling multiple orders.
|
|
1668
|
+
*
|
|
1669
|
+
* Re-typed on top of the generated `OrderCancellations` so its `signingScheme`
|
|
1670
|
+
* uses the {@link EcdsaSigningScheme} subset of `SigningScheme`. This keeps the
|
|
1671
|
+
* result of `OrderSigningUtils.signOrderCancellations()` directly assignable to
|
|
1672
|
+
* this type.
|
|
1673
|
+
*
|
|
1674
|
+
* @see https://github.com/cowprotocol/cow-sdk/issues/187
|
|
1675
|
+
*/
|
|
1676
|
+
type OrderCancellations = Omit<OrderCancellations$1, 'signingScheme'> & {
|
|
1677
|
+
signingScheme: EcdsaSigningScheme;
|
|
1678
|
+
};
|
|
1679
|
+
|
|
1612
1680
|
/**
|
|
1613
1681
|
* An object containing *production* environment base URLs for each supported `chainId`.
|
|
1614
1682
|
* @see {@link https://api.cow.fi/docs/#/}
|
package/dist/index.d.ts
CHANGED
|
@@ -832,7 +832,7 @@ type DebugOrderResponse = {
|
|
|
832
832
|
/**
|
|
833
833
|
* How was the order signed?
|
|
834
834
|
*/
|
|
835
|
-
declare enum EcdsaSigningScheme {
|
|
835
|
+
declare enum EcdsaSigningScheme$1 {
|
|
836
836
|
EIP712 = "eip712",
|
|
837
837
|
ETHSIGN = "ethsign"
|
|
838
838
|
}
|
|
@@ -859,12 +859,12 @@ type NativePriceResponse = {
|
|
|
859
859
|
* `OrderCancellation(bytes orderUid)` from the order's owner.
|
|
860
860
|
*
|
|
861
861
|
*/
|
|
862
|
-
type OrderCancellation = {
|
|
862
|
+
type OrderCancellation$1 = {
|
|
863
863
|
/**
|
|
864
864
|
* OrderCancellation signed by owner
|
|
865
865
|
*/
|
|
866
866
|
signature: EcdsaSignature;
|
|
867
|
-
signingScheme: EcdsaSigningScheme;
|
|
867
|
+
signingScheme: EcdsaSigningScheme$1;
|
|
868
868
|
};
|
|
869
869
|
|
|
870
870
|
type OrderCancellationError = {
|
|
@@ -887,7 +887,7 @@ declare namespace OrderCancellationError {
|
|
|
887
887
|
* EIP-712 signature of struct OrderCancellations { orderUid: bytes[] } from the order's owner.
|
|
888
888
|
*
|
|
889
889
|
*/
|
|
890
|
-
type OrderCancellations = {
|
|
890
|
+
type OrderCancellations$1 = {
|
|
891
891
|
/**
|
|
892
892
|
* Up to 128 UIDs of orders to cancel.
|
|
893
893
|
*/
|
|
@@ -896,7 +896,7 @@ type OrderCancellations = {
|
|
|
896
896
|
* `OrderCancellation` signed by the owner.
|
|
897
897
|
*/
|
|
898
898
|
signature: EcdsaSignature;
|
|
899
|
-
signingScheme: EcdsaSigningScheme;
|
|
899
|
+
signingScheme: EcdsaSigningScheme$1;
|
|
900
900
|
};
|
|
901
901
|
|
|
902
902
|
/**
|
|
@@ -1609,6 +1609,74 @@ interface QuoteAmountsAndCosts<T = bigint> {
|
|
|
1609
1609
|
amountsToSign: Amounts<T>;
|
|
1610
1610
|
}
|
|
1611
1611
|
|
|
1612
|
+
/**
|
|
1613
|
+
* The subset of {@link SigningScheme} values that can be produced by signing an
|
|
1614
|
+
* order with an ECDSA key (i.e. `eip712` and `ethsign`).
|
|
1615
|
+
*
|
|
1616
|
+
* The orderbook OpenAPI spec models `EcdsaSigningScheme` and `SigningScheme` as
|
|
1617
|
+
* two independent string enums. When generated as TypeScript `enum`s they become
|
|
1618
|
+
* nominally unrelated types, so an `EcdsaSigningScheme` value is not assignable
|
|
1619
|
+
* to a `SigningScheme` field even though every `EcdsaSigningScheme` value is a
|
|
1620
|
+
* valid `SigningScheme` value.
|
|
1621
|
+
*
|
|
1622
|
+
* This caused a type error in the documented low-level flow, where the result of
|
|
1623
|
+
* `OrderSigningUtils.signOrder()` (which carries `EcdsaSigningScheme`) is spread
|
|
1624
|
+
* into the `OrderCreation` body of `OrderBookApi.sendOrder()` (which expects
|
|
1625
|
+
* `SigningScheme`):
|
|
1626
|
+
*
|
|
1627
|
+
* ```ts
|
|
1628
|
+
* const { quote } = await orderBookApi.getQuote(quoteRequest)
|
|
1629
|
+
* const orderSigningResult = await OrderSigningUtils.signOrder(quote, chainId, signer)
|
|
1630
|
+
* // previously failed: EcdsaSigningScheme not assignable to SigningScheme
|
|
1631
|
+
* const orderId = await orderBookApi.sendOrder({ ...quote, ...orderSigningResult })
|
|
1632
|
+
* ```
|
|
1633
|
+
*
|
|
1634
|
+
* To fix this `EcdsaSigningScheme` is defined here as a genuine subset of
|
|
1635
|
+
* `SigningScheme` rather than a standalone enum. It keeps the same runtime values
|
|
1636
|
+
* and member names, so existing usages (`EcdsaSigningScheme.EIP712`,
|
|
1637
|
+
* `Record<EcdsaSigningScheme, T>`, etc.) keep working, while values are now
|
|
1638
|
+
* assignable to `SigningScheme`.
|
|
1639
|
+
*
|
|
1640
|
+
* @see https://github.com/cowprotocol/cow-sdk/issues/187
|
|
1641
|
+
*/
|
|
1642
|
+
declare const EcdsaSigningScheme: {
|
|
1643
|
+
readonly EIP712: SigningScheme.EIP712;
|
|
1644
|
+
readonly ETHSIGN: SigningScheme.ETHSIGN;
|
|
1645
|
+
};
|
|
1646
|
+
/**
|
|
1647
|
+
* How was the order signed?
|
|
1648
|
+
*
|
|
1649
|
+
* Subset of {@link SigningScheme} restricted to the schemes produced by ECDSA
|
|
1650
|
+
* signing (`eip712` and `ethsign`). Values are assignable to `SigningScheme`.
|
|
1651
|
+
*/
|
|
1652
|
+
type EcdsaSigningScheme = (typeof EcdsaSigningScheme)[keyof typeof EcdsaSigningScheme];
|
|
1653
|
+
/**
|
|
1654
|
+
* Data a user provides when cancelling a single order.
|
|
1655
|
+
*
|
|
1656
|
+
* Re-typed on top of the generated `OrderCancellation` so its `signingScheme`
|
|
1657
|
+
* uses the {@link EcdsaSigningScheme} subset of `SigningScheme`. This keeps the
|
|
1658
|
+
* result of `OrderSigningUtils.signOrderCancellation()` directly assignable to
|
|
1659
|
+
* this type.
|
|
1660
|
+
*
|
|
1661
|
+
* @see https://github.com/cowprotocol/cow-sdk/issues/187
|
|
1662
|
+
*/
|
|
1663
|
+
type OrderCancellation = Omit<OrderCancellation$1, 'signingScheme'> & {
|
|
1664
|
+
signingScheme: EcdsaSigningScheme;
|
|
1665
|
+
};
|
|
1666
|
+
/**
|
|
1667
|
+
* Data a user provides when cancelling multiple orders.
|
|
1668
|
+
*
|
|
1669
|
+
* Re-typed on top of the generated `OrderCancellations` so its `signingScheme`
|
|
1670
|
+
* uses the {@link EcdsaSigningScheme} subset of `SigningScheme`. This keeps the
|
|
1671
|
+
* result of `OrderSigningUtils.signOrderCancellations()` directly assignable to
|
|
1672
|
+
* this type.
|
|
1673
|
+
*
|
|
1674
|
+
* @see https://github.com/cowprotocol/cow-sdk/issues/187
|
|
1675
|
+
*/
|
|
1676
|
+
type OrderCancellations = Omit<OrderCancellations$1, 'signingScheme'> & {
|
|
1677
|
+
signingScheme: EcdsaSigningScheme;
|
|
1678
|
+
};
|
|
1679
|
+
|
|
1612
1680
|
/**
|
|
1613
1681
|
* An object containing *production* environment base URLs for each supported `chainId`.
|
|
1614
1682
|
* @see {@link https://api.cow.fi/docs/#/}
|
package/dist/index.js
CHANGED
|
@@ -450,7 +450,7 @@ var OrderBookApi = class {
|
|
|
450
450
|
getSolverCompetition(auctionIdorTx, contextOverride = {}) {
|
|
451
451
|
return this.fetch(
|
|
452
452
|
{
|
|
453
|
-
path: `/api/
|
|
453
|
+
path: `/api/v2/solver_competition${typeof auctionIdorTx === "string" ? "/by_tx_hash" : ""}/${auctionIdorTx}`,
|
|
454
454
|
method: "GET"
|
|
455
455
|
},
|
|
456
456
|
contextOverride
|
|
@@ -542,13 +542,6 @@ var DebugFeePolicy;
|
|
|
542
542
|
})(kind = DebugFeePolicy2.kind || (DebugFeePolicy2.kind = {}));
|
|
543
543
|
})(DebugFeePolicy || (DebugFeePolicy = {}));
|
|
544
544
|
|
|
545
|
-
// src/generated/models/EcdsaSigningScheme.ts
|
|
546
|
-
var EcdsaSigningScheme = /* @__PURE__ */ ((EcdsaSigningScheme2) => {
|
|
547
|
-
EcdsaSigningScheme2["EIP712"] = "eip712";
|
|
548
|
-
EcdsaSigningScheme2["ETHSIGN"] = "ethsign";
|
|
549
|
-
return EcdsaSigningScheme2;
|
|
550
|
-
})(EcdsaSigningScheme || {});
|
|
551
|
-
|
|
552
545
|
// src/generated/models/OnchainOrderData.ts
|
|
553
546
|
var OnchainOrderData;
|
|
554
547
|
((OnchainOrderData2) => {
|
|
@@ -846,6 +839,12 @@ function getQuoteAmountsAndCosts(params) {
|
|
|
846
839
|
amountsToSign
|
|
847
840
|
};
|
|
848
841
|
}
|
|
842
|
+
|
|
843
|
+
// src/signingSchemes.ts
|
|
844
|
+
var EcdsaSigningScheme = {
|
|
845
|
+
EIP712: "eip712" /* EIP712 */,
|
|
846
|
+
ETHSIGN: "ethsign" /* ETHSIGN */
|
|
847
|
+
};
|
|
849
848
|
// Annotate the CommonJS export names for ESM import in node:
|
|
850
849
|
0 && (module.exports = {
|
|
851
850
|
BuyTokenDestination,
|
package/dist/index.mjs
CHANGED
|
@@ -399,7 +399,7 @@ var OrderBookApi = class {
|
|
|
399
399
|
getSolverCompetition(auctionIdorTx, contextOverride = {}) {
|
|
400
400
|
return this.fetch(
|
|
401
401
|
{
|
|
402
|
-
path: `/api/
|
|
402
|
+
path: `/api/v2/solver_competition${typeof auctionIdorTx === "string" ? "/by_tx_hash" : ""}/${auctionIdorTx}`,
|
|
403
403
|
method: "GET"
|
|
404
404
|
},
|
|
405
405
|
contextOverride
|
|
@@ -491,13 +491,6 @@ var DebugFeePolicy;
|
|
|
491
491
|
})(kind = DebugFeePolicy2.kind || (DebugFeePolicy2.kind = {}));
|
|
492
492
|
})(DebugFeePolicy || (DebugFeePolicy = {}));
|
|
493
493
|
|
|
494
|
-
// src/generated/models/EcdsaSigningScheme.ts
|
|
495
|
-
var EcdsaSigningScheme = /* @__PURE__ */ ((EcdsaSigningScheme2) => {
|
|
496
|
-
EcdsaSigningScheme2["EIP712"] = "eip712";
|
|
497
|
-
EcdsaSigningScheme2["ETHSIGN"] = "ethsign";
|
|
498
|
-
return EcdsaSigningScheme2;
|
|
499
|
-
})(EcdsaSigningScheme || {});
|
|
500
|
-
|
|
501
494
|
// src/generated/models/OnchainOrderData.ts
|
|
502
495
|
var OnchainOrderData;
|
|
503
496
|
((OnchainOrderData2) => {
|
|
@@ -795,6 +788,12 @@ function getQuoteAmountsAndCosts(params) {
|
|
|
795
788
|
amountsToSign
|
|
796
789
|
};
|
|
797
790
|
}
|
|
791
|
+
|
|
792
|
+
// src/signingSchemes.ts
|
|
793
|
+
var EcdsaSigningScheme = {
|
|
794
|
+
EIP712: "eip712" /* EIP712 */,
|
|
795
|
+
ETHSIGN: "ethsign" /* ETHSIGN */
|
|
796
|
+
};
|
|
798
797
|
export {
|
|
799
798
|
BuyTokenDestination,
|
|
800
799
|
CompetitionOrderStatus,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-order-book",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "CowProtocol Order Book package",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"@types/jest": "^29.4.0",
|
|
23
23
|
"@types/node": "^20.17.31",
|
|
24
24
|
"@types/semver-sort": "^0.0.1",
|
|
25
|
-
"coveralls": "^3.1.1",
|
|
26
25
|
"jest": "^29.7.0",
|
|
27
26
|
"jest-fetch-mock": "^3.0.3",
|
|
28
27
|
"openapi-typescript-codegen": "0.29.0",
|
|
@@ -36,15 +35,16 @@
|
|
|
36
35
|
"cross-fetch": "^3.2.0",
|
|
37
36
|
"exponential-backoff": "^3.1.2",
|
|
38
37
|
"limiter": "^3.0.0",
|
|
39
|
-
"@cowprotocol/sdk-config": "2.3.
|
|
40
|
-
"@cowprotocol/sdk-common": "0.
|
|
38
|
+
"@cowprotocol/sdk-config": "2.3.1",
|
|
39
|
+
"@cowprotocol/sdk-common": "0.12.0"
|
|
41
40
|
},
|
|
42
41
|
"scripts": {
|
|
43
42
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
44
43
|
"prebuild": "pnpm swagger:codegen",
|
|
45
44
|
"lint": "eslint src/**/*.ts --quiet",
|
|
46
45
|
"test": "jest",
|
|
47
|
-
"test:coverage": "jest --coverage
|
|
46
|
+
"test:coverage": "jest --coverage",
|
|
47
|
+
"coverage:badges": "istanbul-badges-readme --exitCode=1",
|
|
48
48
|
"test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
|
|
49
49
|
"swagger:codegen": "openapi --input https://raw.githubusercontent.com/cowprotocol/services/5341875c9498b2026d1b6f67c840b086e4696dcd/crates/orderbook/openapi.yml --output src/generated --exportServices false --exportCore false",
|
|
50
50
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|