@cowprotocol/cow-sdk 2.1.0 → 2.2.1

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.
Files changed (50) hide show
  1. package/dist/{index-ed2b18ee.js → index-472d7872.js} +3 -3
  2. package/dist/index-472d7872.js.map +1 -0
  3. package/dist/index.js +4 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.modern.mjs +1 -1
  6. package/dist/index.module.js +2 -2
  7. package/dist/index.module.js.map +1 -1
  8. package/dist/order-book/generated/index.d.ts +3 -2
  9. package/dist/order-book/generated/models/{AppData.d.ts → AppDataHash.d.ts} +1 -1
  10. package/dist/order-book/generated/models/Auction.d.ts +1 -1
  11. package/dist/order-book/generated/models/BackendAppData.d.ts +1 -0
  12. package/dist/order-book/generated/models/BuyTokenDestination.d.ts +1 -1
  13. package/dist/order-book/generated/models/CallData.d.ts +1 -1
  14. package/dist/order-book/generated/models/CompetitionAuction.d.ts +1 -1
  15. package/dist/order-book/generated/models/EcdsaSignature.d.ts +1 -1
  16. package/dist/order-book/generated/models/EthflowData.d.ts +5 -5
  17. package/dist/order-book/generated/models/NativePriceResponse.d.ts +1 -1
  18. package/dist/order-book/generated/models/OnchainOrderData.d.ts +8 -8
  19. package/dist/order-book/generated/models/OrderCancellation.d.ts +2 -1
  20. package/dist/order-book/generated/models/OrderCancellations.d.ts +3 -3
  21. package/dist/order-book/generated/models/OrderClass.d.ts +1 -1
  22. package/dist/order-book/generated/models/OrderCreation.d.ts +67 -5
  23. package/dist/order-book/generated/models/OrderKind.d.ts +1 -1
  24. package/dist/order-book/generated/models/OrderMetaData.d.ts +25 -16
  25. package/dist/order-book/generated/models/OrderParameters.d.ts +12 -20
  26. package/dist/order-book/generated/models/OrderPostError.d.ts +4 -1
  27. package/dist/order-book/generated/models/OrderQuoteRequest.d.ts +9 -13
  28. package/dist/order-book/generated/models/OrderQuoteResponse.d.ts +2 -2
  29. package/dist/order-book/generated/models/OrderQuoteSide.d.ts +2 -2
  30. package/dist/order-book/generated/models/OrderQuoteValidity.d.ts +3 -3
  31. package/dist/order-book/generated/models/OrderStatus.d.ts +1 -1
  32. package/dist/order-book/generated/models/PriceQuality.d.ts +2 -1
  33. package/dist/order-book/generated/models/SellTokenSource.d.ts +1 -1
  34. package/dist/order-book/generated/models/SolverCompetitionResponse.d.ts +3 -3
  35. package/dist/order-book/generated/models/SolverSettlement.d.ts +13 -10
  36. package/dist/order-book/generated/models/TokenAmount.d.ts +1 -1
  37. package/dist/order-book/generated/models/TotalSurplus.d.ts +10 -0
  38. package/dist/order-book/generated/models/Trade.d.ts +6 -6
  39. package/dist/order-book/generated/models/UID.d.ts +2 -2
  40. package/dist/package.json +1 -1
  41. package/dist/subgraph/graphql.d.ts +1 -0
  42. package/dist/{utils-65bc03ac.js → utils-02f4dcd1.js} +1 -1
  43. package/dist/{utils-65bc03ac.js.map → utils-02f4dcd1.js.map} +1 -1
  44. package/dist/{utils-7b0a629b.js → utils-3ac5d3d0.js} +2 -2
  45. package/dist/{utils-7b0a629b.js.map → utils-3ac5d3d0.js.map} +1 -1
  46. package/dist/{utils-b35881cd.js → utils-5111115b.js} +1 -1
  47. package/dist/{utils-b35881cd.js.map → utils-5111115b.js.map} +1 -1
  48. package/package.json +1 -1
  49. package/dist/index-ed2b18ee.js.map +0 -1
  50. package/dist/order-book/generated/models/VersionResponse.d.ts +0 -18
@@ -7,8 +7,8 @@ import type { OrderStatus } from './OrderStatus';
7
7
  import type { TokenAmount } from './TokenAmount';
8
8
  import type { UID } from './UID';
9
9
  /**
10
- * Extra order data that is returned to users when querying orders
11
- * but not provided by users when creating orders.
10
+ * Extra order data that is returned to users when querying orders but not provided by users
11
+ * when creating orders.
12
12
  *
13
13
  */
14
14
  export type OrderMetaData = {
@@ -20,20 +20,24 @@ export type OrderMetaData = {
20
20
  owner: Address;
21
21
  uid: UID;
22
22
  /**
23
- * Unused field that is currently always set to null and will be removed in the future.
23
+ * Unused field that is currently always set to `null` and will be removed in the future.
24
+ *
24
25
  * @deprecated
25
26
  */
26
27
  availableBalance?: TokenAmount | null;
27
28
  /**
28
- * The total amount of sellToken that has been executed for this order including fees.
29
+ * The total amount of `sellToken` that has been executed for this order including fees.
30
+ *
29
31
  */
30
32
  executedSellAmount: BigUint;
31
33
  /**
32
- * The total amount of sellToken that has been executed for this order without fees.
34
+ * The total amount of `sellToken` that has been executed for this order without fees.
35
+ *
33
36
  */
34
37
  executedSellAmountBeforeFees: BigUint;
35
38
  /**
36
- * The total amount of buyToken that has been executed for this order.
39
+ * The total amount of `buyToken` that has been executed for this order.
40
+ *
37
41
  */
38
42
  executedBuyAmount: BigUint;
39
43
  /**
@@ -45,11 +49,11 @@ export type OrderMetaData = {
45
49
  */
46
50
  invalidated: boolean;
47
51
  /**
48
- * Order status
52
+ * Order status.
49
53
  */
50
54
  status: OrderStatus;
51
55
  /**
52
- * Amount that the signed fee would be without subsidies
56
+ * Amount that the signed fee would be without subsidies.
53
57
  */
54
58
  fullFeeAmount?: TokenAmount;
55
59
  /**
@@ -57,27 +61,26 @@ export type OrderMetaData = {
57
61
  * placed with the intent of actively getting traded. Instead they facilitate the
58
62
  * trade of normal orders by allowing them to be matched against liquidity orders which
59
63
  * uses less gas and can have better prices than external liquidity.
64
+ *
60
65
  * As such liquidity orders will only be used in order to improve settlement of normal
61
66
  * orders. They should not be expected to be traded otherwise and should not expect to get
62
67
  * surplus.
63
68
  *
64
69
  */
65
70
  isLiquidityOrder?: boolean;
66
- /**
67
- * For ethflow orders - order that are placed onchain with native eth -, this field
68
- * contains a struct with two variables user_valid_to and is_refunded
69
- *
70
- */
71
71
  ethflowData?: EthflowData;
72
72
  /**
73
73
  * This represents the actual trader of an on-chain order.
74
- * In that case, the owner would be the EthFlow contract in the case of EthFlow orders and not the actual trader.
74
+ *
75
+ * ### ethflow orders
76
+ *
77
+ * In this case, the `owner` would be the `EthFlow` contract and *not* the actual trader.
75
78
  *
76
79
  */
77
80
  onchainUser?: Address;
78
81
  /**
79
- * There is some data only available for orders that are placed onchain. This data
80
- * can be found in this object
82
+ * There is some data only available for orders that are placed on-chain. This data
83
+ * can be found in this object.
81
84
  *
82
85
  */
83
86
  onchainOrderData?: OnchainOrderData;
@@ -85,4 +88,10 @@ export type OrderMetaData = {
85
88
  * Surplus fee that the limit order was executed with.
86
89
  */
87
90
  executedSurplusFee?: BigUint | null;
91
+ /**
92
+ * Full `appData`, which the contract-level `appData` is a hash of. See `OrderCreation`
93
+ * for more information.
94
+ *
95
+ */
96
+ fullAppData?: string | null;
88
97
  };
@@ -1,60 +1,52 @@
1
1
  import type { Address } from './Address';
2
- import type { AppData } from './AppData';
2
+ import type { AppDataHash } from './AppDataHash';
3
3
  import type { BuyTokenDestination } from './BuyTokenDestination';
4
4
  import type { OrderKind } from './OrderKind';
5
5
  import type { SellTokenSource } from './SellTokenSource';
6
- import type { SigningScheme } from './SigningScheme';
7
6
  import type { TokenAmount } from './TokenAmount';
8
7
  /**
9
8
  * Order parameters.
10
9
  */
11
10
  export type OrderParameters = {
12
11
  /**
13
- * ERC20 token to be sold
12
+ * ERC-20 token to be sold.
14
13
  */
15
14
  sellToken: Address;
16
15
  /**
17
- * ERC20 token to be bought
16
+ * ERC-20 token to be bought.
18
17
  */
19
18
  buyToken: Address;
20
19
  /**
21
- * An optional address to receive the proceeds of the trade instead of the
22
- * owner (i.e. the order signer).
20
+ * An optional Ethereum address to receive the proceeds of the trade instead
21
+ * of the owner (i.e. the order signer).
23
22
  *
24
23
  */
25
24
  receiver?: Address | null;
26
25
  /**
27
- * Amount of sellToken to be sold in atoms
26
+ * Amount of `sellToken` to be sold in atoms.
28
27
  */
29
28
  sellAmount: TokenAmount;
30
29
  /**
31
- * Amount of buyToken to be bought in atoms
30
+ * Amount of `buyToken` to be bought in atoms.
32
31
  */
33
32
  buyAmount: TokenAmount;
34
33
  /**
35
- * Unix timestamp until the order is valid. uint32.
34
+ * Unix timestamp (`uint32`) until which the order is valid.
36
35
  */
37
36
  validTo: number;
37
+ appData: AppDataHash;
38
38
  /**
39
- * Arbitrary application specific data that can be added to an order. This can
40
- * also be used to ensure uniqueness between two orders with otherwise the
41
- * exact same parameters.
42
- *
43
- */
44
- appData: AppData;
45
- /**
46
- * Fees: feeRatio * sellAmount + minimal_fee in atoms
39
+ * feeRatio * sellAmount + minimal_fee in atoms.
47
40
  */
48
41
  feeAmount: TokenAmount;
49
42
  /**
50
- * The kind is either a buy or sell order
43
+ * The kind is either a buy or sell order.
51
44
  */
52
45
  kind: OrderKind;
53
46
  /**
54
- * Is this a fill-or-kill order or a partially fillable order?
47
+ * Is the order fill-or-kill or partially fillable?
55
48
  */
56
49
  partiallyFillable: boolean;
57
50
  sellTokenBalance?: SellTokenSource;
58
51
  buyTokenBalance?: BuyTokenDestination;
59
- signingScheme?: SigningScheme;
60
52
  };
@@ -15,6 +15,7 @@ export declare namespace OrderPostError {
15
15
  TRANSFER_SIMULATION_FAILED = "TransferSimulationFailed",
16
16
  UNSUPPORTED_TOKEN = "UnsupportedToken",
17
17
  WRONG_OWNER = "WrongOwner",
18
+ INVALID_EIP1271SIGNATURE = "InvalidEip1271Signature",
18
19
  MISSING_FROM = "MissingFrom",
19
20
  SAME_BUY_AND_SELL_TOKEN = "SameBuyAndSellToken",
20
21
  ZERO_AMOUNT = "ZeroAmount",
@@ -22,6 +23,8 @@ export declare namespace OrderPostError {
22
23
  UNSUPPORTED_SELL_TOKEN_SOURCE = "UnsupportedSellTokenSource",
23
24
  UNSUPPORTED_ORDER_TYPE = "UnsupportedOrderType",
24
25
  UNSUPPORTED_SIGNATURE = "UnsupportedSignature",
25
- TOO_MANY_LIMIT_ORDERS = "TooManyLimitOrders"
26
+ TOO_MANY_LIMIT_ORDERS = "TooManyLimitOrders",
27
+ INVALID_APP_DATA = "InvalidAppData",
28
+ APP_DATA_HASH_MISMATCH = "AppDataHashMismatch"
26
29
  }
27
30
  }
@@ -1,5 +1,5 @@
1
1
  import type { Address } from './Address';
2
- import type { AppData } from './AppData';
2
+ import type { AppDataHash } from './AppDataHash';
3
3
  import type { BuyTokenDestination } from './BuyTokenDestination';
4
4
  import type { OrderQuoteSide } from './OrderQuoteSide';
5
5
  import type { OrderQuoteValidity } from './OrderQuoteValidity';
@@ -11,28 +11,22 @@ import type { SigningScheme } from './SigningScheme';
11
11
  */
12
12
  export type OrderQuoteRequest = (OrderQuoteSide & OrderQuoteValidity & {
13
13
  /**
14
- * ERC20 token to be sold
14
+ * ERC-20 token to be sold
15
15
  */
16
16
  sellToken: Address;
17
17
  /**
18
- * ERC20 token to be bought
18
+ * ERC-20 token to be bought
19
19
  */
20
20
  buyToken: Address;
21
21
  /**
22
22
  * An optional address to receive the proceeds of the trade instead of the
23
- * owner (i.e. the order signer).
23
+ * `owner` (i.e. the order signer).
24
24
  *
25
25
  */
26
26
  receiver?: Address | null;
27
+ appData?: AppDataHash;
27
28
  /**
28
- * Arbitrary application specific data that can be added to an order. This can
29
- * also be used to ensure uniqueness between two orders with otherwise the
30
- * exact same parameters.
31
- *
32
- */
33
- appData?: AppData;
34
- /**
35
- * Is this a fill-or-kill order or a partially fillable order?
29
+ * Is the order fill-or-kill or partially fillable?
36
30
  */
37
31
  partiallyFillable?: boolean;
38
32
  sellTokenBalance?: SellTokenSource;
@@ -41,7 +35,9 @@ export type OrderQuoteRequest = (OrderQuoteSide & OrderQuoteValidity & {
41
35
  priceQuality?: PriceQuality;
42
36
  signingScheme?: SigningScheme;
43
37
  /**
44
- * Flag to signal whether the order is intended for onchain order placement. Only valid for non ECDSA-signed orders
38
+ * Flag to signal whether the order is intended for on-chain order placement. Only valid
39
+ * for non ECDSA-signed orders."
40
+ *
45
41
  */
46
42
  onchainOrder?: any;
47
43
  });
@@ -1,7 +1,7 @@
1
1
  import type { Address } from './Address';
2
2
  import type { OrderParameters } from './OrderParameters';
3
3
  /**
4
- * An order quoted by the back end that can be directly signed and
4
+ * An order quoted by the backend that can be directly signed and
5
5
  * submitted to the order creation backend.
6
6
  *
7
7
  */
@@ -15,7 +15,7 @@ export type OrderQuoteResponse = {
15
15
  */
16
16
  expiration: string;
17
17
  /**
18
- * Order ID linked to a quote to enable providing more metadata when analyzing
18
+ * Quote ID linked to a quote to enable providing more metadata when analysing
19
19
  * order slippage.
20
20
  *
21
21
  */
@@ -13,13 +13,13 @@ export type OrderQuoteSide = ({
13
13
  } | {
14
14
  kind: OrderQuoteSide.kind;
15
15
  /**
16
- * The sell amount for the order.
16
+ * The `sellAmount` for the order.
17
17
  */
18
18
  sellAmountAfterFee: TokenAmount;
19
19
  } | {
20
20
  kind: OrderQuoteSide.kind;
21
21
  /**
22
- * The buy amount for the order.
22
+ * The `buyAmount` for the order.
23
23
  */
24
24
  buyAmountAfterFee: TokenAmount;
25
25
  });
@@ -1,14 +1,14 @@
1
1
  /**
2
- * The validity for the order
2
+ * The validity for the order.
3
3
  */
4
4
  export type OrderQuoteValidity = ({
5
5
  /**
6
- * Unix timestamp until the order is valid. uint32.
6
+ * Unix timestamp (`uint32`) until which the order is valid.
7
7
  */
8
8
  validTo?: number;
9
9
  } | {
10
10
  /**
11
- * Number of seconds that the order should be valid for. uint32.
11
+ * Number (`uint32`) of seconds that the order should be valid for.
12
12
  */
13
13
  validFor?: number;
14
14
  });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The current order status
2
+ * The current order status.
3
3
  */
4
4
  export declare enum OrderStatus {
5
5
  PRESIGNATURE_PENDING = "presignaturePending",
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * How good should the price estimate be?
3
- * Note that orders are supposed to be created from "optimal" price estimates.
3
+ *
4
+ * **NOTE**: Orders are supposed to be created from `optimal` price estimates.
4
5
  *
5
6
  */
6
7
  export declare enum PriceQuality {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Where should the sell token be drawn from?
2
+ * Where should the `sellToken` be drawn from?
3
3
  */
4
4
  export declare enum SellTokenSource {
5
5
  ERC20 = "erc20",
@@ -3,13 +3,13 @@ import type { SolverSettlement } from './SolverSettlement';
3
3
  import type { TransactionHash } from './TransactionHash';
4
4
  /**
5
5
  * The settlements submitted by every solver for a specific auction.
6
- * The auction id corresponds to the id external solvers are provided
6
+ * The `auctionId` corresponds to the id external solvers are provided
7
7
  * with.
8
8
  *
9
9
  */
10
10
  export type SolverCompetitionResponse = {
11
11
  /**
12
- * The id of the auction the competition info is for.
12
+ * The ID of the auction the competition info is for.
13
13
  */
14
14
  auctionId?: number;
15
15
  /**
@@ -17,7 +17,7 @@ export type SolverCompetitionResponse = {
17
17
  */
18
18
  transactionHash?: TransactionHash | null;
19
19
  /**
20
- * gas price used for ranking solutions
20
+ * Gas price used for ranking solutions.
21
21
  */
22
22
  gasPrice?: number;
23
23
  liquidityCollectedBlock?: number;
@@ -3,18 +3,18 @@ import type { CallData } from './CallData';
3
3
  import type { UID } from './UID';
4
4
  export type SolverSettlement = {
5
5
  /**
6
- * name of the solver
6
+ * Name of the solver.
7
7
  */
8
8
  solver?: string;
9
9
  /**
10
- * The address used by the solver to execute the settlement onchain.
10
+ * The address used by the solver to execute the settlement on-chain.
11
11
  * This field is missing for old settlements, the zero address has been used instead.
12
12
  *
13
13
  */
14
14
  solverAddress?: string;
15
15
  objective?: {
16
16
  /**
17
- * the total objective value used for ranking solutions
17
+ * The total objective value used for ranking solutions.
18
18
  */
19
19
  total?: number;
20
20
  surplus?: number;
@@ -23,8 +23,8 @@ export type SolverSettlement = {
23
23
  gas?: number;
24
24
  };
25
25
  /**
26
- * The score of the current auction as defined in CIP-20.
27
- * It is null for old auctions.
26
+ * The score of the current auction as defined in [CIP-20](https://snapshot.org/#/cow.eth/proposal/0x2d3f9bd1ea72dca84b03e97dda3efc1f4a42a772c54bd2037e8b62e7d09a491f).
27
+ * It is `null` for old auctions.
28
28
  *
29
29
  */
30
30
  score?: BigUint | null;
@@ -34,20 +34,23 @@ export type SolverSettlement = {
34
34
  */
35
35
  clearingPrices?: Record<string, BigUint>;
36
36
  /**
37
- * the touched orders
37
+ * Touched orders.
38
38
  */
39
39
  orders?: Array<{
40
40
  id?: UID;
41
41
  executedAmount?: BigUint;
42
42
  }>;
43
43
  /**
44
- * Transaction call data that is executed onchain if the settlement is executed.
44
+ * Transaction `calldata` that is executed on-chain if the settlement is executed.
45
45
  */
46
46
  callData?: CallData;
47
47
  /**
48
- * Full call data as generated from the original solver output.
49
- * It can be different from the executed transaction if part of the settlements are internalized (use internal liquidity in lieu of trading against onchain liquidity).
50
- * This field is omitted in case it coincides with callData.
48
+ * Full `calldata` as generated from the original solver output.
49
+ *
50
+ * It can be different from the executed transaction if part of the settlements are internalised
51
+ * (use internal liquidity in lieu of trading against on-chain liquidity).
52
+ *
53
+ * This field is omitted in case it coincides with `callData`.
51
54
  *
52
55
  */
53
56
  uninternalizedCallData?: CallData;
@@ -1,4 +1,4 @@
1
1
  /**
2
- * Amount of a token. uint256 encoded in decimal.
2
+ * Amount of a token. `uint256` encoded in decimal.
3
3
  */
4
4
  export type TokenAmount = string;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The total surplus.
3
+ *
4
+ */
5
+ export type TotalSurplus = {
6
+ /**
7
+ * The total surplus.
8
+ */
9
+ totalSurplus?: string;
10
+ };
@@ -4,7 +4,7 @@ import type { TokenAmount } from './TokenAmount';
4
4
  import type { TransactionHash } from './TransactionHash';
5
5
  import type { UID } from './UID';
6
6
  /**
7
- * Trade data such as executed amounts, fees, order id and block number.
7
+ * Trade data such as executed amounts, fees, `orderUid` and `block` number.
8
8
  *
9
9
  */
10
10
  export type Trade = {
@@ -17,7 +17,7 @@ export type Trade = {
17
17
  */
18
18
  logIndex: number;
19
19
  /**
20
- * Unique ID of the order matched by this trade.
20
+ * UID of the order matched by this trade.
21
21
  */
22
22
  orderUid: UID;
23
23
  /**
@@ -33,19 +33,19 @@ export type Trade = {
33
33
  */
34
34
  buyToken: Address;
35
35
  /**
36
- * Total amount of sellToken that has been executed for this trade (including fees).
36
+ * Total amount of `sellToken` that has been executed for this trade (including fees).
37
37
  */
38
38
  sellAmount: TokenAmount;
39
39
  /**
40
- * The total amount of sellToken that has been executed for this order without fees.
40
+ * The total amount of `sellToken` that has been executed for this order without fees.
41
41
  */
42
42
  sellAmountBeforeFees: BigUint;
43
43
  /**
44
- * Total amount of buyToken received in this trade.
44
+ * Total amount of `buyToken` received in this trade.
45
45
  */
46
46
  buyAmount: TokenAmount;
47
47
  /**
48
- * Hash of the corresponding settlement transaction containing the trade (if available).
48
+ * Transaction hash of the corresponding settlement transaction containing the trade (if available).
49
49
  */
50
50
  txHash: TransactionHash | null;
51
51
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Unique identifier for the order: 56 bytes encoded as hex with `0x` prefix.
3
- * Bytes 0 to 32 are the order digest, bytes 30 to 52 the owner address
4
- * and bytes 52..56 valid to,
3
+ * Bytes 0..32 are the order digest, bytes 30..52 the owner address and bytes
4
+ * 52..56 the expiry (`validTo`) as a `uint32` unix epoch timestamp.
5
5
  *
6
6
  */
7
7
  export type UID = string;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/cow-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "files": [
6
6
  "/dist"
@@ -21,6 +21,7 @@ export type Scalars = {
21
21
  BigDecimal: any;
22
22
  BigInt: any;
23
23
  Bytes: any;
24
+ Int8: any;
24
25
  };
25
26
  export type BlockChangedFilter = {
26
27
  number_gte: Scalars['Int'];
@@ -1,2 +1,2 @@
1
1
  import{IntChainIdTypedDataV4Signer as e,TypedDataVersionedSigner as t,signOrderCancellations as r,signOrderCancellation as n,signOrder as o,SigningScheme as i,domain as s}from"@cowprotocol/contracts";import{EcdsaSigningScheme as c,CowError as a,COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS as u}from"./index.module.js";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";const d=function(e,t,r){return m({orderUids:e,chainId:t},f,r)},h=function(e,t,r){return m({orderId:e,chainId:t},g,r)},l=function(e,t,r){return m({order:e,chainId:t},v,r)},m=function(r,n,o,i="v4"){try{let u;function s(e){if(u)return e;const t=l?.data;return{signature:t?.toString()||"",signingScheme:d}}const d="eth_sign"===i?c.ETHSIGN:c.EIP712;let h,l=null;try{switch(i){case"default":case"v3":h=new t(o);break;case"int_v4":h=new e(o);break;default:h=o}}catch(g){throw console.error("Wallet not supported:",g),new a("Wallet not supported")}const f=function(e,t){try{var o=Promise.resolve(n({...r,signer:h,signingScheme:d})).then(function(e){l=e})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){if(void 0===(t=e).code&&void 0===t.message)throw console.error(e),e;var t;const s=[w,y].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==I&&!s){if(_.test(e.message)){const e=m(r,n,o,"int_v4");return u=1,e}if(e.code===p){const e=m(r,n,o,"eth_sign");return u=1,e}if(P.test(e.message)){const e=m(r,n,o,"v3");return u=1,e}if(S.test(e.message)){const e=m(r,n,o,"eth_sign");return u=1,e}throw console.error(e),e}switch(i){case"v4":const t=m(r,n,o,"default");return u=1,t;case"default":const i=m(r,n,o,"v3");return u=1,i;case"v3":const s=m(r,n,o,"eth_sign");return u=1,s;default:throw e}});return Promise.resolve(f&&f.then?f.then(s):s(f))}catch(v){return Promise.reject(v)}},f=function(e){try{const{chainId:t,signer:n,signingScheme:o,orderUids:i}=e,s=j(t);return Promise.resolve(r(s,i,n,E[o]))}catch(e){return Promise.reject(e)}},g=function(e){try{const{chainId:t,signer:r,signingScheme:o,orderId:i}=e,s=j(t);return Promise.resolve(n(s,i,r,E[o]))}catch(e){return Promise.reject(e)}},v=function(e){try{const{chainId:t,signer:r,order:n,signingScheme:i}=e,s=j(t);return Promise.resolve(o(s,n,r,E[i]))}catch(e){return Promise.reject(e)}},p=-32603,I=-32601,w=/Method not found/i,P=/eth_signTypedData_v4 does not exist/i,S=/eth_signTypedData_v3 does not exist/i,y=/RPC request failed/i,_=/provided chainid .* must match the active chainid/i,E={[c.EIP712]:i.EIP712,[c.ETHSIGN]:i.ETHSIGN};function j(e){const t=u[e];if(!t)throw new a("Unsupported network. Settlement contract is not deployed");return s(e,t)}export{j as getDomain,l as signOrder,h as signOrderCancellation,d as signOrderCancellations};
2
- //# sourceMappingURL=utils-65bc03ac.js.map
2
+ //# sourceMappingURL=utils-02f4dcd1.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils-65bc03ac.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\n signOrder as signOrderGp,\n signOrderCancellation as signOrderCancellationGp,\n signOrderCancellations as signOrderCancellationsGp,\n TypedDataVersionedSigner,\n} from '@cowprotocol/contracts'\nimport type { Signer } from '@ethersproject/abstract-signer'\nimport type { SigningResult, SignOrderParams, SingOrderCancellationParams, UnsignedOrder } from './types'\n\nimport { COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS } from '../common/consts'\nimport { CowError, SupportedChainId } from '../common'\nimport { EcdsaSigningScheme } from '../order-book'\nimport { SingOrderCancellationsParams } from './types'\n\n// For error codes, see:\n// - https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal\n// - https://www.jsonrpc.org/specification#error_object\nconst METAMASK_SIGNATURE_ERROR_CODE = -32603\nconst METHOD_NOT_FOUND_ERROR_CODE = -32601\n// Added the following because of 1Inch walet who doesn't send the error code\n// So we will check the actual error text\nconst METHOD_NOT_FOUND_ERROR_MSG_REGEX = /Method not found/i\nconst V4_ERROR_MSG_REGEX = /eth_signTypedData_v4 does not exist/i\nconst V3_ERROR_MSG_REGEX = /eth_signTypedData_v3 does not exist/i\nconst RPC_REQUEST_FAILED_REGEX = /RPC request failed/i\nconst METAMASK_STRING_CHAINID_REGEX = /provided chainid .* must match the active chainid/i\n\nconst mapSigningSchema: Record<EcdsaSigningScheme, EcdsaSigningSchemeContract> = {\n [EcdsaSigningScheme.EIP712]: SigningScheme.EIP712,\n [EcdsaSigningScheme.ETHSIGN]: SigningScheme.ETHSIGN,\n}\n\ninterface ProviderRpcError extends Error {\n message: string\n code: number\n data?: unknown\n}\n\ntype PayloadParams =\n | Pick<SignOrderParams, 'order' & 'chainId'>\n | Pick<SingOrderCancellationParams, 'chainId' & 'orderId'>\n | Pick<SingOrderCancellationsParams, 'chainId' & 'orderUids'>\n\nfunction isProviderRpcError(error: unknown): error is ProviderRpcError {\n return (error as ProviderRpcError).code !== undefined || (error as ProviderRpcError).message !== undefined\n}\n\nasync function _signOrder(params: SignOrderParams): Promise<Signature> {\n const { chainId, signer, order, signingScheme } = params\n\n const domain = getDomain(chainId)\n\n return signOrderGp(domain, order as OrderFromContract, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellation(params: SingOrderCancellationParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderId } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationGp(domain, orderId, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellations(params: SingOrderCancellationsParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUids } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationsGp(domain, orderUids, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signPayload(\n payload: PayloadParams,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n signFn: (params: any) => Promise<Signature>,\n signer: Signer,\n signingMethod: 'default' | 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'\n): Promise<SigningResult> {\n const signingScheme: EcdsaSigningScheme =\n signingMethod === 'eth_sign' ? EcdsaSigningScheme.ETHSIGN : EcdsaSigningScheme.EIP712\n let signature: Signature | null = null\n\n let _signer\n try {\n switch (signingMethod) {\n case 'default':\n case 'v3':\n _signer = new TypedDataVersionedSigner(signer)\n break\n case 'int_v4':\n _signer = new IntChainIdTypedDataV4Signer(signer)\n break\n default:\n _signer = signer\n }\n } catch (e) {\n console.error('Wallet not supported:', e)\n throw new CowError('Wallet not supported')\n }\n\n try {\n signature = (await signFn({ ...payload, signer: _signer, signingScheme })) as EcdsaSignature // Only ECDSA signing supported for now\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!isProviderRpcError(e)) {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n\n const regexErrorCheck = [METHOD_NOT_FOUND_ERROR_MSG_REGEX, RPC_REQUEST_FAILED_REGEX].some((regex) =>\n // for example 1Inch error doesn't have e.message so we will check the output of toString()\n [e.message, e.toString()].some((msg) => regex.test(msg))\n )\n\n if (e.code === METHOD_NOT_FOUND_ERROR_CODE || regexErrorCheck) {\n // Maybe the wallet returns the proper error code? We can only hope 🤞\n // OR it failed with a generic message, there's no error code set, and we also hope it'll work\n // with other methods...\n switch (signingMethod) {\n case 'v4':\n return _signPayload(payload, signFn, signer, 'default')\n case 'default':\n return _signPayload(payload, signFn, signer, 'v3')\n case 'v3':\n return _signPayload(payload, signFn, signer, 'eth_sign')\n default:\n throw e\n }\n } else if (METAMASK_STRING_CHAINID_REGEX.test(e.message)) {\n // Metamask now enforces chainId to be an integer\n return _signPayload(payload, signFn, signer, 'int_v4')\n } else if (e.code === METAMASK_SIGNATURE_ERROR_CODE) {\n // We tried to sign order the nice way.\n // That works fine for regular MM addresses. Does not work for Hardware wallets, though.\n // See https://github.com/MetaMask/metamask-extension/issues/10240#issuecomment-810552020\n // So, when that specific error occurs, we know this is a problem with MM + HW.\n // Then, we fallback to ETHSIGN.\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else if (V4_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v4`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'v3')\n } else if (V3_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v3`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n }\n\n const data: unknown = signature?.data\n\n return { signature: data?.toString() || '', signingScheme }\n}\n\n/**\n * Returns the signature for the specified order with the signing scheme encoded\n * into the signature.\n * @export\n * @param {UnsignedOrder} order The order to sign.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrder(\n order: UnsignedOrder,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ order, chainId }, _signOrder, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellation with the signing scheme encoded\n * into the signature.\n *\n * @export\n * @param {string} orderId The unique identifier of the order being cancelled.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellation(\n orderId: string,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderId, chainId }, _signOrderCancellation, signer)\n}\n\nexport async function signOrderCancellations(\n orderUids: string[],\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUids, chainId }, _signOrderCancellations, signer)\n}\n\nexport function getDomain(chainId: SupportedChainId): TypedDataDomain {\n // Get settlement contract address\n const settlementContract = COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]\n\n if (!settlementContract) {\n throw new CowError('Unsupported network. Settlement contract is not deployed')\n }\n\n return domainGp(chainId, settlementContract)\n}\n"],"names":["signOrderCancellations","orderUids","chainId","signer","_signPayload","_signOrderCancellations","signOrderCancellation","orderId","_signOrderCancellation","signOrder","order","_signOrder","payload","signFn","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_temp","Promise","resolve","then","_signFn","_catch","undefined","code","message","regexErrorCheck","METHOD_NOT_FOUND_ERROR_MSG_REGEX","RPC_REQUEST_FAILED_REGEX","some","regex","msg","test","METHOD_NOT_FOUND_ERROR_CODE","METAMASK_STRING_CHAINID_REGEX","_signPayload5","METAMASK_SIGNATURE_ERROR_CODE","_signPayload6","V4_ERROR_MSG_REGEX","_signPayload7","V3_ERROR_MSG_REGEX","_signPayload8","_signPayload2","_signPayload3","_signPayload4","reject","params","domain","getDomain","signOrderCancellationsGp","mapSigningSchema","signOrderCancellationGp","signOrderGp","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"4ZA0MsB,MAAAA,EAAsBA,SAC1CC,EACAC,EACAC,GAEA,OAAOC,EAAa,CAAEH,YAAWC,WAAWG,EAAyBF,EACvE,EAdsBG,EAAqB,SACzCC,EACAL,EACAC,GAEA,OAAOC,EAAa,CAAEG,UAASL,WAAWM,EAAwBL,EACpE,EAxBsBM,EAAS,SAC7BC,EACAR,EACAC,GAEA,OAAOC,EAAa,CAAEM,QAAOR,WAAWS,EAAYR,EACtD,EArGeC,EAAYA,SACzBQ,EAEAC,EACAV,EACAW,EAAiE,MAAI,IAAAC,IAAAA,EAAAC,SAAAA,EAAAC,GAAA,GAAAF,EAAA,OAAAE,EA4ErE,MAAMC,EAAgBC,GAAWD,KAEjC,MAAO,CAAEC,UAAWD,GAAME,YAAc,GAAIC,gBAAe,CA5E3D,MAAMA,EACc,aAAlBP,EAA+BQ,EAAmBC,QAAUD,EAAmBE,OACjF,IAEIC,EAFAN,EAA8B,KAGlC,IACE,OAAQL,GACN,IAAK,UACL,IAAK,KACHW,EAAU,IAAIC,EAAyBvB,GACvC,MACF,IAAK,SACHsB,EAAU,IAAIE,EAA4BxB,GAC1C,MACF,QACEsB,EAAUtB,EAEf,CAAC,MAAOyB,GAEP,MADAC,QAAQC,MAAM,wBAAyBF,GAC7B,IAAAG,EAAS,uBACpB,CAAA,MAAAC,0BAEGC,QA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KmE,EACH,MAAM,IAAItC,EAAS,4DAGrB,OAAOwC,EAASrE,EAASmE,EAC3B"}
1
+ {"version":3,"file":"utils-02f4dcd1.js","sources":["../src/order-signing/utils.ts"],"sourcesContent":["import type {\n Order as OrderFromContract,\n Signature,\n TypedDataDomain,\n EcdsaSigningScheme as EcdsaSigningSchemeContract,\n} from '@cowprotocol/contracts'\nimport {\n domain as domainGp,\n EcdsaSignature,\n IntChainIdTypedDataV4Signer,\n SigningScheme,\n signOrder as signOrderGp,\n signOrderCancellation as signOrderCancellationGp,\n signOrderCancellations as signOrderCancellationsGp,\n TypedDataVersionedSigner,\n} from '@cowprotocol/contracts'\nimport type { Signer } from '@ethersproject/abstract-signer'\nimport type { SigningResult, SignOrderParams, SingOrderCancellationParams, UnsignedOrder } from './types'\n\nimport { COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS } from '../common/consts'\nimport { CowError, SupportedChainId } from '../common'\nimport { EcdsaSigningScheme } from '../order-book'\nimport { SingOrderCancellationsParams } from './types'\n\n// For error codes, see:\n// - https://eth.wiki/json-rpc/json-rpc-error-codes-improvement-proposal\n// - https://www.jsonrpc.org/specification#error_object\nconst METAMASK_SIGNATURE_ERROR_CODE = -32603\nconst METHOD_NOT_FOUND_ERROR_CODE = -32601\n// Added the following because of 1Inch walet who doesn't send the error code\n// So we will check the actual error text\nconst METHOD_NOT_FOUND_ERROR_MSG_REGEX = /Method not found/i\nconst V4_ERROR_MSG_REGEX = /eth_signTypedData_v4 does not exist/i\nconst V3_ERROR_MSG_REGEX = /eth_signTypedData_v3 does not exist/i\nconst RPC_REQUEST_FAILED_REGEX = /RPC request failed/i\nconst METAMASK_STRING_CHAINID_REGEX = /provided chainid .* must match the active chainid/i\n\nconst mapSigningSchema: Record<EcdsaSigningScheme, EcdsaSigningSchemeContract> = {\n [EcdsaSigningScheme.EIP712]: SigningScheme.EIP712,\n [EcdsaSigningScheme.ETHSIGN]: SigningScheme.ETHSIGN,\n}\n\ninterface ProviderRpcError extends Error {\n message: string\n code: number\n data?: unknown\n}\n\ntype PayloadParams =\n | Pick<SignOrderParams, 'order' & 'chainId'>\n | Pick<SingOrderCancellationParams, 'chainId' & 'orderId'>\n | Pick<SingOrderCancellationsParams, 'chainId' & 'orderUids'>\n\nfunction isProviderRpcError(error: unknown): error is ProviderRpcError {\n return (error as ProviderRpcError).code !== undefined || (error as ProviderRpcError).message !== undefined\n}\n\nasync function _signOrder(params: SignOrderParams): Promise<Signature> {\n const { chainId, signer, order, signingScheme } = params\n\n const domain = getDomain(chainId)\n\n return signOrderGp(domain, order as OrderFromContract, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellation(params: SingOrderCancellationParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderId } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationGp(domain, orderId, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signOrderCancellations(params: SingOrderCancellationsParams): Promise<Signature> {\n const { chainId, signer, signingScheme, orderUids } = params\n\n const domain = getDomain(chainId)\n\n return signOrderCancellationsGp(domain, orderUids, signer, mapSigningSchema[signingScheme])\n}\n\nasync function _signPayload(\n payload: PayloadParams,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n signFn: (params: any) => Promise<Signature>,\n signer: Signer,\n signingMethod: 'default' | 'v4' | 'int_v4' | 'v3' | 'eth_sign' = 'v4'\n): Promise<SigningResult> {\n const signingScheme: EcdsaSigningScheme =\n signingMethod === 'eth_sign' ? EcdsaSigningScheme.ETHSIGN : EcdsaSigningScheme.EIP712\n let signature: Signature | null = null\n\n let _signer\n try {\n switch (signingMethod) {\n case 'default':\n case 'v3':\n _signer = new TypedDataVersionedSigner(signer)\n break\n case 'int_v4':\n _signer = new IntChainIdTypedDataV4Signer(signer)\n break\n default:\n _signer = signer\n }\n } catch (e) {\n console.error('Wallet not supported:', e)\n throw new CowError('Wallet not supported')\n }\n\n try {\n signature = (await signFn({ ...payload, signer: _signer, signingScheme })) as EcdsaSignature // Only ECDSA signing supported for now\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!isProviderRpcError(e)) {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n\n const regexErrorCheck = [METHOD_NOT_FOUND_ERROR_MSG_REGEX, RPC_REQUEST_FAILED_REGEX].some((regex) =>\n // for example 1Inch error doesn't have e.message so we will check the output of toString()\n [e.message, e.toString()].some((msg) => regex.test(msg))\n )\n\n if (e.code === METHOD_NOT_FOUND_ERROR_CODE || regexErrorCheck) {\n // Maybe the wallet returns the proper error code? We can only hope 🤞\n // OR it failed with a generic message, there's no error code set, and we also hope it'll work\n // with other methods...\n switch (signingMethod) {\n case 'v4':\n return _signPayload(payload, signFn, signer, 'default')\n case 'default':\n return _signPayload(payload, signFn, signer, 'v3')\n case 'v3':\n return _signPayload(payload, signFn, signer, 'eth_sign')\n default:\n throw e\n }\n } else if (METAMASK_STRING_CHAINID_REGEX.test(e.message)) {\n // Metamask now enforces chainId to be an integer\n return _signPayload(payload, signFn, signer, 'int_v4')\n } else if (e.code === METAMASK_SIGNATURE_ERROR_CODE) {\n // We tried to sign order the nice way.\n // That works fine for regular MM addresses. Does not work for Hardware wallets, though.\n // See https://github.com/MetaMask/metamask-extension/issues/10240#issuecomment-810552020\n // So, when that specific error occurs, we know this is a problem with MM + HW.\n // Then, we fallback to ETHSIGN.\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else if (V4_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v4`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'v3')\n } else if (V3_ERROR_MSG_REGEX.test(e.message)) {\n // Failed with `v3`, and the wallet does not set the proper error code\n return _signPayload(payload, signFn, signer, 'eth_sign')\n } else {\n // Some other error signing. Let it bubble up.\n console.error(e)\n throw e\n }\n }\n\n const data: unknown = signature?.data\n\n return { signature: data?.toString() || '', signingScheme }\n}\n\n/**\n * Returns the signature for the specified order with the signing scheme encoded\n * into the signature.\n * @export\n * @param {UnsignedOrder} order The order to sign.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrder(\n order: UnsignedOrder,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ order, chainId }, _signOrder, signer)\n}\n\n/**\n * Returns the signature for the Order Cancellation with the signing scheme encoded\n * into the signature.\n *\n * @export\n * @param {string} orderId The unique identifier of the order being cancelled.\n * @param {SupportedChainId} chainId The chain Id\n * @param {Signer} signer The owner for the order used to sign.\n * @return {*} Encoded signature including signing scheme for the order.\n */\nexport async function signOrderCancellation(\n orderId: string,\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderId, chainId }, _signOrderCancellation, signer)\n}\n\nexport async function signOrderCancellations(\n orderUids: string[],\n chainId: SupportedChainId,\n signer: Signer\n): Promise<SigningResult> {\n return _signPayload({ orderUids, chainId }, _signOrderCancellations, signer)\n}\n\nexport function getDomain(chainId: SupportedChainId): TypedDataDomain {\n // Get settlement contract address\n const settlementContract = COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS[chainId]\n\n if (!settlementContract) {\n throw new CowError('Unsupported network. Settlement contract is not deployed')\n }\n\n return domainGp(chainId, settlementContract)\n}\n"],"names":["signOrderCancellations","orderUids","chainId","signer","_signPayload","_signOrderCancellations","signOrderCancellation","orderId","_signOrderCancellation","signOrder","order","_signOrder","payload","signFn","signingMethod","_exit","_temp2","_result","data","signature","toString","signingScheme","EcdsaSigningScheme","ETHSIGN","EIP712","_signer","TypedDataVersionedSigner","IntChainIdTypedDataV4Signer","e","console","error","CowError","_temp","Promise","resolve","then","_signFn","_catch","undefined","code","message","regexErrorCheck","METHOD_NOT_FOUND_ERROR_MSG_REGEX","RPC_REQUEST_FAILED_REGEX","some","regex","msg","test","METHOD_NOT_FOUND_ERROR_CODE","METAMASK_STRING_CHAINID_REGEX","_signPayload5","METAMASK_SIGNATURE_ERROR_CODE","_signPayload6","V4_ERROR_MSG_REGEX","_signPayload7","V3_ERROR_MSG_REGEX","_signPayload8","_signPayload2","_signPayload3","_signPayload4","reject","params","domain","getDomain","signOrderCancellationsGp","mapSigningSchema","signOrderCancellationGp","signOrderGp","SigningScheme","settlementContract","COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS","domainGp"],"mappings":"4ZA0MsB,MAAAA,EAAsBA,SAC1CC,EACAC,EACAC,GAEA,OAAOC,EAAa,CAAEH,YAAWC,WAAWG,EAAyBF,EACvE,EAdsBG,EAAqB,SACzCC,EACAL,EACAC,GAEA,OAAOC,EAAa,CAAEG,UAASL,WAAWM,EAAwBL,EACpE,EAxBsBM,EAAS,SAC7BC,EACAR,EACAC,GAEA,OAAOC,EAAa,CAAEM,QAAOR,WAAWS,EAAYR,EACtD,EArGeC,EAAYA,SACzBQ,EAEAC,EACAV,EACAW,EAAiE,MAAI,IAAAC,IAAAA,EAAAC,SAAAA,EAAAC,GAAA,GAAAF,EAAA,OAAAE,EA4ErE,MAAMC,EAAgBC,GAAWD,KAEjC,MAAO,CAAEC,UAAWD,GAAME,YAAc,GAAIC,gBAAe,CA5E3D,MAAMA,EACc,aAAlBP,EAA+BQ,EAAmBC,QAAUD,EAAmBE,OACjF,IAEIC,EAFAN,EAA8B,KAGlC,IACE,OAAQL,GACN,IAAK,UACL,IAAK,KACHW,EAAU,IAAIC,EAAyBvB,GACvC,MACF,IAAK,SACHsB,EAAU,IAAIE,EAA4BxB,GAC1C,MACF,QACEsB,EAAUtB,EAEf,CAAC,MAAOyB,GAEP,MADAC,QAAQC,MAAM,wBAAyBF,GAC7B,IAAAG,EAAS,uBACpB,CAAA,MAAAC,0BAEGC,QAAAC,QACiBrB,EAAO,IAAKD,EAAST,OAAQsB,EAASJ,mBAAgBc,cAAAC,GAAzEjB,EAASiB,CAAmF,4DAH7FC,CAEG,EAGH,SAAQT,GACP,QA5D0CU,KADlBR,EA6DAF,GA5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edDataV4Signer as s,TypedDataVersionedSigner as o,signOrder as a,signOrderCancellation as c,signOrderCancellations as d,SigningScheme as u}from"@cowprotocol/contracts";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";const h=-32603,l=-32601,g=/Method not found/i,f=/eth_signTypedData_v4 does not exist/i,m=/eth_signTypedData_v3 does not exist/i,p=/RPC request failed/i,v=/provided chainid .* must match the active chainid/i,w={[r.EIP712]:u.EIP712,[r.ETHSIGN]:u.ETHSIGN};async function I(e){const{chainId:t,signer:n,order:r,signingScheme:i}=e,s=b(t);return a(s,r,n,w[i])}async function y(e){const{chainId:t,signer:n,signingScheme:r,orderId:i}=e,s=b(t);return c(s,i,n,w[r])}async function S(e){const{chainId:t,signer:n,signingScheme:r,orderUids:i}=e,s=b(t);return d(s,i,n,w[r])}async function _(n,i,a,c="v4"){var d;const u="eth_sign"===c?r.ETHSIGN:r.EIP712;let w,I=null;try{switch(c){case"default":case"v3":w=new o(a);break;case"int_v4":w=new s(a);break;default:w=a}}catch(t){throw console.error("Wallet not supported:",t),new e("Wallet not supported")}try{I=await i(t({},n,{signer:w,signingScheme:u}))}catch(e){if(void 0===(y=e).code&&void 0===y.message)throw console.error(e),e;const t=[g,p].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==l&&!t){if(v.test(e.message))return _(n,i,a,"int_v4");if(e.code===h)return _(n,i,a,"eth_sign");if(f.test(e.message))return _(n,i,a,"v3");if(m.test(e.message))return _(n,i,a,"eth_sign");throw console.error(e),e}switch(c){case"v4":return _(n,i,a,"default");case"default":return _(n,i,a,"v3");case"v3":return _(n,i,a,"eth_sign");default:throw e}}var y;const S=null==(d=I)?void 0:d.data;return{signature:(null==S?void 0:S.toString())||"",signingScheme:u}}async function E(e,t,n){return _({order:e,chainId:t},I,n)}async function x(e,t,n){return _({orderId:e,chainId:t},y,n)}async function T(e,t,n){return _({orderUids:e,chainId:t},S,n)}function b(t){const r=n[t];if(!r)throw new e("Unsupported network. Settlement contract is not deployed");return i(t,r)}export{b as getDomain,E as signOrder,x as signOrderCancellation,T as signOrderCancellations};
2
- //# sourceMappingURL=utils-7b0a629b.js.map
1
+ import{C as e,_ as t,a as n,E as r}from"./index-472d7872.js";import{domain as i,IntChainIdTypedDataV4Signer as s,TypedDataVersionedSigner as o,signOrder as a,signOrderCancellation as c,signOrderCancellations as d,SigningScheme as u}from"@cowprotocol/contracts";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";const h=-32603,l=-32601,g=/Method not found/i,f=/eth_signTypedData_v4 does not exist/i,m=/eth_signTypedData_v3 does not exist/i,p=/RPC request failed/i,v=/provided chainid .* must match the active chainid/i,w={[r.EIP712]:u.EIP712,[r.ETHSIGN]:u.ETHSIGN};async function I(e){const{chainId:t,signer:n,order:r,signingScheme:i}=e,s=k(t);return a(s,r,n,w[i])}async function y(e){const{chainId:t,signer:n,signingScheme:r,orderId:i}=e,s=k(t);return c(s,i,n,w[r])}async function S(e){const{chainId:t,signer:n,signingScheme:r,orderUids:i}=e,s=k(t);return d(s,i,n,w[r])}async function _(n,i,a,c="v4"){var d;const u="eth_sign"===c?r.ETHSIGN:r.EIP712;let w,I=null;try{switch(c){case"default":case"v3":w=new o(a);break;case"int_v4":w=new s(a);break;default:w=a}}catch(t){throw console.error("Wallet not supported:",t),new e("Wallet not supported")}try{I=await i(t({},n,{signer:w,signingScheme:u}))}catch(e){if(void 0===(y=e).code&&void 0===y.message)throw console.error(e),e;const t=[g,p].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==l&&!t){if(v.test(e.message))return _(n,i,a,"int_v4");if(e.code===h)return _(n,i,a,"eth_sign");if(f.test(e.message))return _(n,i,a,"v3");if(m.test(e.message))return _(n,i,a,"eth_sign");throw console.error(e),e}switch(c){case"v4":return _(n,i,a,"default");case"default":return _(n,i,a,"v3");case"v3":return _(n,i,a,"eth_sign");default:throw e}}var y;const S=null==(d=I)?void 0:d.data;return{signature:(null==S?void 0:S.toString())||"",signingScheme:u}}async function E(e,t,n){return _({order:e,chainId:t},I,n)}async function x(e,t,n){return _({orderId:e,chainId:t},y,n)}async function T(e,t,n){return _({orderUids:e,chainId:t},S,n)}function k(t){const r=n[t];if(!r)throw new e("Unsupported network. Settlement contract is not deployed");return i(t,r)}export{k as getDomain,E as signOrder,x as signOrderCancellation,T as signOrderCancellations};
2
+ //# sourceMappingURL=utils-3ac5d3d0.js.map