@cowprotocol/cow-sdk 1.0.1-RC.3 → 1.0.1-RC.6
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/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/dist/api/cow/transformOrder.d.ts +2 -0
- package/dist/api/cow/types.d.ts +5 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +2 -2
- package/dist/index.modern.mjs.map +1 -1
- package/dist/index.module.js +2 -2
- package/dist/index.module.js.map +1 -1
- package/package.json +2 -2
- package/dist/appData.schema-0c8db23b.js +0 -2
- package/dist/appData.schema-0c8db23b.js.map +0 -1
- package/dist/appData.schema-412cbfbf.js +0 -2
- package/dist/appData.schema-412cbfbf.js.map +0 -1
- package/dist/appData.schema-42d10730.js +0 -2
- package/dist/appData.schema-42d10730.js.map +0 -1
- package/dist/appData.schema-4c010c50.js +0 -2
- package/dist/appData.schema-4c010c50.js.map +0 -1
- package/dist/appData.schema-adfc1c6f.js +0 -2
- package/dist/appData.schema-adfc1c6f.js.map +0 -1
- package/dist/appData.schema-b8f018d7.js +0 -2
- package/dist/appData.schema-b8f018d7.js.map +0 -1
- package/dist/index.modern.js +0 -29
- package/dist/index.modern.js.map +0 -1
- package/dist/src/appData.schema-d44994e0.js +0 -2
- package/dist/src/appData.schema-d44994e0.js.map +0 -1
- package/dist/src/appData.schema-fb2df827.js +0 -2
- package/dist/src/appData.schema-fb2df827.js.map +0 -1
- package/dist/src/cow-sdk.esm.js +0 -2
- package/dist/src/cow-sdk.esm.js.map +0 -1
- package/dist/src/cow-sdk.js +0 -2
- package/dist/src/cow-sdk.js.map +0 -1
- package/dist/src/cow-sdk.modern.js +0 -2
- package/dist/src/cow-sdk.modern.js.map +0 -1
- package/dist/src/src/CowSdk.d.ts +0 -16
- package/dist/src/src/api/cow/errors/OperatorError.d.ts +0 -63
- package/dist/src/src/api/cow/errors/QuoteError.d.ts +0 -32
- package/dist/src/src/api/cow/index.d.ts +0 -38
- package/dist/src/src/api/cow/types.d.ts +0 -73
- package/dist/src/src/api/index.d.ts +0 -1
- package/dist/src/src/constants/chains.d.ts +0 -6
- package/dist/src/src/constants/index.d.ts +0 -3
- package/dist/src/src/constants/tokens.d.ts +0 -5
- package/dist/src/src/index.d.ts +0 -4
- package/dist/src/src/types/index.d.ts +0 -7
- package/dist/src/src/utils/appData.d.ts +0 -7
- package/dist/src/src/utils/common.d.ts +0 -5
- package/dist/src/src/utils/context.d.ts +0 -24
- package/dist/src/src/utils/sign.d.ts +0 -54
- package/dist/src/src/utils/tokens.d.ts +0 -2
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Gnosis Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/api/cow/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { StrictUnion } from '../../types/utilities';
|
|
|
10
10
|
export declare type OrderID = string;
|
|
11
11
|
export declare type ApiOrderStatus = 'fulfilled' | 'expired' | 'cancelled' | 'presignaturePending' | 'open';
|
|
12
12
|
export declare type OrderClass = 'market' | 'limit' | 'liquidity';
|
|
13
|
-
export interface
|
|
13
|
+
export interface OrderDto {
|
|
14
14
|
creationDate: string;
|
|
15
15
|
owner: string;
|
|
16
16
|
uid: OrderID;
|
|
@@ -19,7 +19,7 @@ export interface OrderMetaData {
|
|
|
19
19
|
executedSellAmount: string;
|
|
20
20
|
executedSellAmountBeforeFees: string;
|
|
21
21
|
executedFeeAmount: string;
|
|
22
|
-
executedSurplusFee: string;
|
|
22
|
+
executedSurplusFee: string | null;
|
|
23
23
|
invalidated: false;
|
|
24
24
|
sellToken: string;
|
|
25
25
|
buyToken: string;
|
|
@@ -38,6 +38,9 @@ export interface OrderMetaData {
|
|
|
38
38
|
ethflowData?: EthFlowData;
|
|
39
39
|
onchainUser?: string;
|
|
40
40
|
}
|
|
41
|
+
export interface OrderMetaData extends OrderDto {
|
|
42
|
+
totalFee: string;
|
|
43
|
+
}
|
|
41
44
|
declare type EthFlowData = {
|
|
42
45
|
userValidTo: number;
|
|
43
46
|
isRefunded: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=require("loglevel"),r=require("@cowprotocol/contracts"),t=require("cross-fetch"),n=require("graphql-request"),o=require("@cowprotocol/app-data"),s=require("paraswap");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function a(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var c,d=/*#__PURE__*/i(e),u=/*#__PURE__*/i(t);class l extends Error{constructor(e,r){super(e),this.error_code=void 0,this.error_code=r}}function h(e){if(!e)return"";const r=new URLSearchParams;for(const t of Object.keys(e)){const n=e[t];n&&r.append(t,n.toString())}const t=r.toString();return t?`?${t}`:""}exports.SupportedChainId=void 0,(c=exports.SupportedChainId||(exports.SupportedChainId={}))[c.MAINNET=1]="MAINNET",c[c.GOERLI=5]="GOERLI",c[c.GNOSIS_CHAIN=100]="GNOSIS_CHAIN";const p=[exports.SupportedChainId.MAINNET,exports.SupportedChainId.GOERLI,exports.SupportedChainId.GNOSIS_CHAIN],{GPv2Settlement:f}=JSON.parse('{\n "GPv2AllowListAuthentication_Implementation": {\n "1": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67",\n "transactionHash": "0x58340aa44119c74e48635fab0ac344170c6d6e8b42e5714baa4ba4e1651f63ad"\n },\n "4": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67"\n },\n "5": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67",\n "transactionHash": "0x24f4f80b46a17345011065f9ea2af823f582db56be81098b3b66cc2db9659ea7"\n },\n "100": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67",\n "transactionHash": "0xe52d425fe34d6d5215ccfc9ddfa485d490b3018f0ee5bbed708f2d172044d60d"\n }\n },\n "GPv2AllowListAuthentication_Proxy": {\n "1": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0xb84bf720364f94c749f1ec1cdf0d4c44c70411b716459aaccfd24fc677013375"\n },\n "4": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x57b2278fd3a13ab1b132031024475ba1a4e28d7d4d37f556134c84512b742c1f"\n },\n "5": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x39dcf30baf887a5db54551a84de8bfdb6cf418bb284b09680d13aed17d5fa0c1"\n },\n "100": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x1a2d87a05a94bc6680a4faee31bbafbd74e9ddb63dd3941c717b5c609c08b957"\n }\n },\n "GPv2AllowListAuthentication": {\n "1": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0xb84bf720364f94c749f1ec1cdf0d4c44c70411b716459aaccfd24fc677013375"\n },\n "4": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x57b2278fd3a13ab1b132031024475ba1a4e28d7d4d37f556134c84512b742c1f"\n },\n "5": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x39dcf30baf887a5db54551a84de8bfdb6cf418bb284b09680d13aed17d5fa0c1"\n },\n "100": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x1a2d87a05a94bc6680a4faee31bbafbd74e9ddb63dd3941c717b5c609c08b957"\n }\n },\n "GPv2Settlement": {\n "1": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0xf49f90aa5a268c40001d1227b76bb4dd8247f18361fcad9fffd4a7a44f1320d3"\n },\n "4": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0x609fa2e8f32c73c1f5dc21ff60a26238dacb50d4674d336c90d6950bdda17a21"\n },\n "5": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0x982f089060ff66e19d0683ef1cc6a637297331a9ba95b65d8eb84b9f8dc64b04"\n },\n "100": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0x9ddc538f89cd8433f4a19bc4de0de27e7c68a1d04a14b327185e4bba9af87133"\n }\n },\n "GPv2VaultRelayer": {\n "1": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0xf49f90aa5a268c40001d1227b76bb4dd8247f18361fcad9fffd4a7a44f1320d3"\n },\n "4": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0x609fa2e8f32c73c1f5dc21ff60a26238dacb50d4674d336c90d6950bdda17a21"\n },\n "5": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0x982f089060ff66e19d0683ef1cc6a637297331a9ba95b65d8eb84b9f8dc64b04"\n },\n "100": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0x9ddc538f89cd8433f4a19bc4de0de27e7c68a1d04a14b327185e4bba9af87133"\n }\n }\n}'),m=p.reduce((e,r)=>({...e,[r]:f[r].address}),{}),v=function(e,t,n,o="v4"){try{let i;function s(e){return i?e:{signature:u?.data.toString(),signingScheme:a}}const a="eth_sign"===o?r.SigningScheme.ETHSIGN:r.SigningScheme.EIP712;let c,u=null;try{switch(o){case"v3":c=new r.TypedDataV3Signer(n);break;case"int_v4":c=new r.IntChainIdTypedDataV4Signer(n);break;default:c=n}}catch(p){throw d.default.error("cow-sdk:","Wallet not supported:",p),new l("Wallet not supported")}const h=function(r,n){try{var o=Promise.resolve(t({...e,signer:c,signingScheme:a})).then(function(e){u=e})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(r){if(void 0===(s=r).code&&void 0===s.message)throw d.default.error("cow-sdk:",r),r;var s;if(r.code===T||A.test(r.message))switch(o){case"v4":const o=v(e,t,n,"v3");return i=1,o;case"v3":const s=v(e,t,n,"eth_sign");return i=1,s;default:throw r}else{if(b.test(r.message)){const r=v(e,t,n,"int_v4");return i=1,r}if(r.code===E){const r=v(e,t,n,"eth_sign");return i=1,r}if(w.test(r.message)){const r=v(e,t,n,"v3");return i=1,r}if(y.test(r.message)){const r=v(e,t,n,"eth_sign");return i=1,r}}});return Promise.resolve(h&&h.then?h.then(s):s(h))}catch(f){return Promise.reject(f)}},P=function(e){try{const{chainId:t,signer:n,signingScheme:o,orderId:s}=e,i=x(t);return Promise.resolve(r.signOrderCancellation(i,s,n,O(o)))}catch(e){return Promise.reject(e)}},g=function(e){try{const{chainId:t,signer:n,order:o,signingScheme:s}=e,i=x(t);return Promise.resolve(r.signOrder(i,o,n,O(s)))}catch(e){return Promise.reject(e)}},E=-32603,T=-32601,w=/eth_signTypedData_v4 does not exist/i,y=/eth_signTypedData_v3 does not exist/i,A=/RPC request failed/i,b=/provided chainid .* must match the active chainid/i,I=new Map([[r.SigningScheme.EIP712,{libraryValue:0,apiValue:"eip712"}],[r.SigningScheme.ETHSIGN,{libraryValue:1,apiValue:"ethsign"}],[r.SigningScheme.EIP1271,{libraryValue:2,apiValue:"eip1271"}],[r.SigningScheme.PRESIGN,{libraryValue:3,apiValue:"presign"}]]);function S(e){const r=I.get(e);if(void 0===r)throw new l("Unknown schema "+e);return r}function k(e){return S(e).apiValue}function O(e){return S(e).libraryValue}function x(e){const t=m[e];if(!t)throw new l("Unsupported network. Settlement contract is not deployed");return r.domain(e,t)}var D,N,_,C,R;!function(e){e.DuplicateOrder="DuplicateOrder",e.InvalidSignature="InvalidSignature",e.MissingOrderData="MissingOrderData",e.InsufficientValidTo="InsufficientValidTo",e.InsufficientAllowance="InsufficientAllowance",e.InsufficientBalance="InsufficientBalance",e.InsufficientFee="InsufficientFee",e.WrongOwner="WrongOwner",e.NotFound="NotFound",e.OrderNotFound="OrderNotFound",e.AlreadyCancelled="AlreadyCancelled",e.OrderFullyExecuted="OrderFullyExecuted",e.OrderExpired="OrderExpired",e.NoLiquidity="NoLiquidity",e.UnsupportedToken="UnsupportedToken",e.AmountIsZero="AmountIsZero",e.SellAmountDoesNotCoverFee="SellAmountDoesNotCoverFee",e.TransferEthToContract="TransferEthToContract",e.UNHANDLED_GET_ERROR="UNHANDLED_GET_ERROR",e.UNHANDLED_CREATE_ERROR="UNHANDLED_CREATE_ERROR",e.UNHANDLED_DELETE_ERROR="UNHANDLED_DELETE_ERROR"}(D||(D={})),function(e){e.DuplicateOrder="There was another identical order already submitted. Please try again.",e.InsufficientFee="The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",e.InvalidSignature="The order signature is invalid. Check whether your Wallet app supports off-chain signing.",e.MissingOrderData="The order has missing information",e.InsufficientValidTo="The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.",e.InsufficientAllowance="The account doesn't have enough funds",e.InsufficientBalance="The account needs to approve the selling token in order to trade",e.WrongOwner="The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CowSwap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",e.NotFound="Not found",e.OrderNotFound="The order you are trying to cancel does not exist",e.AlreadyCancelled="Order is already cancelled",e.OrderFullyExecuted="Order is already filled",e.OrderExpired="Order is expired",e.NoLiquidity="Token pair selected has insufficient liquidity",e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.AmountIsZero="Amount is zero",e.SellAmountDoesNotCoverFee="Sell amount does not sufficiently cover the current fee",e.TransferEthToContract="Sending the native currency to smart contract wallets is not currently supported",e.UNHANDLED_GET_ERROR="Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.",e.UNHANDLED_CREATE_ERROR="The order was not accepted by the network",e.UNHANDLED_DELETE_ERROR="The order cancellation was not accepted by the network"}(N||(N={}));class U extends l{static getErrorMessage(e,r){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){return e.errorType?U.apiErrorDetails[e.errorType]||e.errorType:(d.default.error("cow-sdk:","Unknown reason for bad order submission",e),e.description)})}catch(e){return t()}return n&&n.then?n.then(void 0,t):n}(0,function(){return d.default.error("cow-sdk:","Error handling a 400 error. Likely a problem deserialising the JSON response"),function(e){switch(e){case"get":return N.UNHANDLED_GET_ERROR;case"create":return N.UNHANDLED_CREATE_ERROR;case"delete":return N.UNHANDLED_DELETE_ERROR;default:return d.default.error("cow-sdk:","[OperatorError::_mapActionToErrorDetails] Uncaught error mapping error action type to server error. Please try again later."),"Something failed. Please try again later."}}(r)}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e,r){try{const t=this;switch(e.status){case 400:case 404:return Promise.resolve(t.getErrorMessage(e,r));case 403:return Promise.resolve(`The order cannot be ${"create"===r?"accepted":"cancelled"}. Your account is deny-listed.`);case 429:return Promise.resolve(`The order cannot be ${"create"===r?"accepted. Too many order placements":"cancelled. Too many order cancellations"}. Please, retry in a minute`);default:return d.default.error("cow-sdk:",`[OperatorError::getErrorFromStatusCode] Error ${"create"===r?"creating":"cancelling"} the order, status code:`,e.status||"unknown"),Promise.resolve(`Error ${"create"===r?"creating":"cancelling"} the order`)}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="OperatorError",this.description=void 0,this.description=e.description,this.message=N[e.errorType]}}U.apiErrorDetails=N,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(_||(_={})),function(e){e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.InsufficientLiquidity="Token pair selected has insufficient liquidity",e.FeeExceedsFrom='Current fee exceeds entered "from" amount',e.ZeroPrice="Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.",e.UNHANDLED_ERROR="Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later."}(C||(C={}));class L extends l{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){return e.errorType?L.quoteErrorDetails[e.errorType]||e.errorType:(d.default.error("cow-sdk:","Unknown reason for bad quote fetch",e),e.description)})}catch(e){return t()}return n&&n.then?n.then(void 0,t):n}(0,function(){return d.default.error("cow-sdk:","Error handling 400/404 error. Likely a problem deserialising the JSON response"),L.quoteErrorDetails.UNHANDLED_ERROR}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:case 404:return Promise.resolve(r.getErrorMessage(e));default:return d.default.error("cow-sdk:","[QuoteError::getErrorFromStatusCode] Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="QuoteErrorObject",this.description=void 0,this.data=void 0,this.description=e.description,this.message=L.quoteErrorDetails[e.errorType],this.data=e?.data}}L.quoteErrorDetails=C,exports.ERC20BridgeSource=void 0,(R=exports.ERC20BridgeSource||(exports.ERC20BridgeSource={})).Native="Native",R.Uniswap="Uniswap",R.UniswapV2="Uniswap_V2",R.Eth2Dai="Eth2Dai",R.Kyber="Kyber",R.Curve="Curve",R.LiquidityProvider="LiquidityProvider",R.MultiBridge="MultiBridge",R.Balancer="Balancer",R.BalancerV2="Balancer_V2",R.Cream="CREAM",R.Bancor="Bancor",R.MakerPsm="MakerPsm",R.MStable="mStable",R.Mooniswap="Mooniswap",R.MultiHop="MultiHop",R.Shell="Shell",R.Swerve="Swerve",R.SnowSwap="SnowSwap",R.SushiSwap="SushiSwap",R.Dodo="DODO",R.DodoV2="DODO_V2",R.CryptoCom="CryptoCom",R.Linkswap="Linkswap",R.KyberDmm="KyberDMM",R.Smoothy="Smoothy",R.Component="Component",R.Saddle="Saddle",R.XSigma="xSigma",R.UniswapV3="Uniswap_V3",R.CurveV2="Curve_V2",R.Lido="Lido",R.ShibaSwap="ShibaSwap",R.Clipper="Clipper",R.PancakeSwap="PancakeSwap",R.PancakeSwapV2="PancakeSwap_V2",R.BakerySwap="BakerySwap",R.Nerve="Nerve",R.Belt="Belt",R.Ellipsis="Ellipsis",R.ApeSwap="ApeSwap",R.CafeSwap="CafeSwap",R.CheeseSwap="CheeseSwap",R.JulSwap="JulSwap",R.ACryptos="ACryptoS",R.QuickSwap="QuickSwap",R.ComethSwap="ComethSwap",R.Dfyn="Dfyn",R.WaultSwap="WaultSwap",R.Polydex="Polydex",R.FirebirdOneSwap="FirebirdOneSwap",R.JetSwap="JetSwap",R.IronSwap="IronSwap";class j{constructor(e,r){this.symbol=void 0,this.address=void 0,this.symbol=e,this.address=r}}const H={[exports.SupportedChainId.MAINNET]:new j("WETH","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),[exports.SupportedChainId.GOERLI]:new j("WETH","0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6"),[exports.SupportedChainId.GNOSIS_CHAIN]:new j("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},M={[exports.SupportedChainId.MAINNET]:"ETH",[exports.SupportedChainId.GOERLI]:"ETH",[exports.SupportedChainId.GNOSIS_CHAIN]:"XDAI"};function V(e,r){let t=e;return e===M[r]&&(t=H[r].address),t}const F={"Content-Type":"application/json"};class q{constructor({context:e,name:r,getApiUrl:t,defaultHeaders:n=F,apiVersion:o="v1"}){this.context=void 0,this.API_NAME=void 0,this.API_VERSION=void 0,this.API_URL_GETTER=void 0,this.DEFAULT_HEADERS=void 0,this.context=e,this.API_NAME=r,this.API_VERSION=o,this.API_URL_GETTER=t,this.DEFAULT_HEADERS=n}getApiBaseUrl(){try{const e=this,r=arguments;return Promise.resolve(e.context.chainId).then(function(t){const n=e.API_URL_GETTER(...[].slice.call(r))[t];if(n)return n+"/"+e.API_VERSION;throw new l(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+t)})}catch(e){return Promise.reject(e)}}post(e,r,t={},n){const o=[e,"POST",this.fetch.bind(this),this.API_URL_GETTER,t,r];return n?this.fetchSingleEnv(...o):this.fetchMultipleEnvs(...o)}get(e,r={}){return this.fetchMultipleEnvs(e,"GET",this.fetch.bind(this),this.API_URL_GETTER,r)}delete(e,r,t={}){return this.fetchMultipleEnvs(e,"DELETE",this.fetch.bind(this),this.API_URL_GETTER,t,r)}fetchSingleEnv(e,r,t,n,o={},s){try{const i=this;function a(o){function a(a){const c=n(o);return t(e,r,`${c[a]}/${i.API_VERSION}`,s,u)}return c?a(c):Promise.resolve(i.context.chainId).then(a)}const{chainId:c,env:d,requestOptions:u}=o;return Promise.resolve(d?a(d):Promise.resolve(i.context.env).then(a))}catch(l){return Promise.reject(l)}}fetchMultipleEnvs(e,r,t,n,o={},s){try{const i=this;function a(o){return i.fetchMultipleEnvsRecursive({url:e,method:r,fetchFn:t,getApiUrl:n,options:u,envs:l,chainId:o,data:s})}const{env:c,chainId:d,...u}=o,l=c?[c]:["prod","staging"];return Promise.resolve(d?a(d):Promise.resolve(i.context.chainId).then(a))}catch(h){return Promise.reject(h)}}fetch(e,r,t,n,o){try{return Promise.resolve(u.default(t+e,{headers:this.DEFAULT_HEADERS,...o,method:r,body:void 0!==n?JSON.stringify(n):n}))}catch(e){return Promise.reject(e)}}fetchMultipleEnvsRecursive(e){try{const r=this,{url:t,method:n,fetchFn:o,getApiUrl:s,options:i={},envs:a,chainId:c,data:d}=e,{requestOptions:u}=i,[l,...h]=a,p=s(l)[c];return Promise.resolve(function(s,i){try{var a=Promise.resolve(o(t,n,`${p}/${r.API_VERSION}`,d,u)).then(function(t){return!t.ok&&h?.length?r.fetchMultipleEnvsRecursive({...e,envs:h}):t})}catch(e){return i(e)}return a&&a.then?a.then(void 0,i):a}(0,function(t){if(h?.length)return r.fetchMultipleEnvsRecursive({...e,envs:h});throw t}))}catch(e){return Promise.reject(e)}}}function B(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}const $=function(e,r){try{return e.ok?Promise.resolve(e.json()):"application/json"===e.headers.get("Content-Type")?Promise.resolve(e.json()).then(function(e){const t=function(e){switch(e?.errorType){case D.NotFound:case D.NoLiquidity:return{errorType:_.InsufficientLiquidity,description:C.InsufficientLiquidity};case D.SellAmountDoesNotCoverFee:return{errorType:_.FeeExceedsFrom,description:C.FeeExceedsFrom,data:e?.data};case D.UnsupportedToken:return{errorType:_.UnsupportedToken,description:e.description};case D.SellAmountDoesNotCoverFee:return{errorType:_.FeeExceedsFrom,description:e.description};default:return{errorType:_.UNHANDLED_ERROR,description:C.UNHANDLED_ERROR}}}(e),n=new L(t);if(r){const{sellToken:e,buyToken:t}=r;d.default.error("cow-sdk:",`Error querying fee from API - sellToken: ${e}, buyToken: ${t}`)}throw n}):Promise.resolve(e.text()).then(function(e){throw new L({description:e,errorType:_.UNHANDLED_ERROR})})}catch(e){return Promise.reject(e)}};function G(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[exports.SupportedChainId.GOERLI]:"https://barn.api.cow.fi/goerli/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai/api"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/mainnet/api",[exports.SupportedChainId.GOERLI]:"https://api.cow.fi/goerli/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}}function Q(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/affiliate/api"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/affiliate/api"}}}const X={errorType:_.UNHANDLED_ERROR,description:C.UNHANDLED_ERROR},Z={errorType:D.UNHANDLED_GET_ERROR,description:N.UNHANDLED_GET_ERROR};class J extends q{constructor(e){super({context:e,name:"CoW Protocol",apiVersion:"v1",getApiUrl:G})}getProfileData(e,r={}){try{const t=this;function n(r){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get profile data for`,r,e),r!==exports.SupportedChainId.MAINNET?(d.default.info("cow-sdk:","Profile data is only available for mainnet"),null):Promise.resolve(t.getProfile(`/profile/${e}`,{chainId:r,env:s})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw d.default.error("cow-sdk:",e),new l(e?.description)})})}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getTrades(e,r={}){try{const t=this;function n(e){return d.default.debug("cow-sdk:","[util:operator] Get trades for",e,{owner:i,orderId:a}),B(function(){return Promise.resolve(t.get(`/trades${c}`,{chainId:e,env:s})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("cow-sdk:","Error getting trades:",e),e instanceof U)throw e;throw new l("Error getting trades: "+e)})}const{chainId:o,env:s=t.context.env}=r,{owner:i,orderId:a}=e;if(i&&a)throw new l("Cannot specify both owner and orderId");const c=h({owner:i,orderUid:a});return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(u){return Promise.reject(u)}}getOrders(e,r={}){try{const t=this;function n(e){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get orders for `,e,i,a,c),B(function(){return Promise.resolve(t.get(`/account/${i}/orders/${u}`,{chainId:e,env:s})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return e.map(W)}):Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("cow-sdk:","Error getting orders information:",e),e instanceof U)throw e;throw new U(Z)})}const{chainId:o,env:s=t.context.env}=r,{owner:i,limit:a=1e3,offset:c=0}=e,u=h({limit:a,offset:c});return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(l){return Promise.reject(l)}}getTxOrders(e,r={}){try{const t=this;function n(r){return d.default.debug(`[api:${t.API_NAME}] Get tx orders for `,r,e),B(function(){return Promise.resolve(t.get(`/transactions/${e}/orders`,{chainId:r,env:s})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return e.map(W)}):Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("Error getting transaction orders information:",e),e instanceof U)throw e;throw new U(Z)})}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getOrder(e,r={}){try{const t=this;function n(r){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get order for `,r,e),B(function(){return Promise.resolve(t.get(`/orders/${e}`,{chainId:r,env:s})).then(function(e){return e.ok?Promise.resolve(e.json()).then(W):Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("cow-sdk:","Error getting order information:",e),e instanceof U)throw e;throw new U(Z)})}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getPriceQuoteLegacy(e,r={}){try{const t=this;function n(r){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get price from API`,e,"for",r),Promise.resolve(t.get(`/markets/${V(i,r)}-${V(a,r)}/${u}/${c}`,{chainId:r,env:s}).catch(e=>{throw d.default.error("cow-sdk:","Error getting price quote:",e),new L(X)})).then($)}const{chainId:o,env:s}=r,{baseToken:i,quoteToken:a,amount:c,kind:u}=e;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(l){return Promise.reject(l)}}getQuoteLegacyParams(e,r={}){try{const t=this;function n(r){const n=t.mapNewToLegacyParams(e,r);return Promise.resolve(t.post("/quote",n,{chainId:r,env:s})).then($)}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getQuote(e,r={}){try{const t=this;function n(r){return Promise.resolve(t.post("/quote",e,{chainId:r,env:s})).then($)}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}sendSignedOrderCancellation(e,r={}){try{const t=this;function n(e){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Delete signed order for network`,e,i),Promise.resolve(t.delete(`/orders/${i.orderUid}`,{signature:i.signature,signingScheme:k(i.signingScheme),from:a},{chainId:e,env:s})).then(function(r){function n(r){d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Cancelled order`,i.orderUid,e)}const o=function(){if(!r.ok)return Promise.resolve(U.getErrorFromStatusCode(r,"delete")).then(function(e){throw new l(e)})}();return o&&o.then?o.then(n):n()})}const{chainId:o,env:s}=r,{cancellation:i,owner:a}=e;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(c){return Promise.reject(c)}}sendOrder(e,r={}){try{const t=this;function n(r){const{owner:n}=e;return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Post signed order for network`,r,o),Promise.resolve(t.post("/orders",{...o,signingScheme:k(o.signingScheme),from:n},{chainId:r,env:i},!0)).then(function(e){function r(r){return Promise.resolve(e.json()).then(function(e){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Success posting the signed order`,e),e})}const n=function(){if(!e.ok)return Promise.resolve(U.getErrorFromStatusCode(e,"create")).then(function(e){throw new l(e)})}();return n&&n.then?n.then(r):r()})}const o={...e.order,appData:t.context.appDataHash},{chainId:s,env:i}=r;return Promise.resolve(s?n(s):Promise.resolve(t.context.chainId).then(n))}catch(a){return Promise.reject(a)}}getOrderLink(e){try{return Promise.resolve(this.getApiBaseUrl()).then(function(r){return r+`/orders/${e}`})}catch(e){return Promise.reject(e)}}getApiBaseUrl(){return super.getApiBaseUrl(this.context.env)}getProfile(e,r={}){return this.fetchMultipleEnvs(e,"GET",this.fetchProfile.bind(this),Q,r)}mapNewToLegacyParams(e,t){const{amount:n,kind:o,userAddress:s,receiver:i,validTo:a,sellToken:c,buyToken:d}=e,u=s||"0x0000000000000000000000000000000000000000",l={sellToken:V(c,t),buyToken:V(d,t),from:u,receiver:i||u,appData:this.context.appDataHash,validTo:a,partiallyFillable:!1};return o===r.OrderKind.SELL?{kind:r.OrderKind.SELL,sellAmountBeforeFee:n,...l}:{kind:r.OrderKind.BUY,buyAmountAfterFee:n,...l}}fetchProfile(e,r,t,n){try{return Promise.resolve(fetch(t+e,{headers:this.DEFAULT_HEADERS,method:r,body:void 0!==n?JSON.stringify(n):n}))}catch(e){return Promise.reject(e)}}}function W(e){const{ethflowData:t}=e;if(!t)return e;const{userValidTo:n}=t,o=e.onchainUser||e.owner,s=r.BUY_ETH_ADDRESS;return{...e,validTo:n,owner:o,sellToken:s}}const K=n.gql`
|
|
1
|
+
var e=require("loglevel"),r=require("@cowprotocol/contracts"),t=require("cross-fetch"),n=require("graphql-request"),o=require("@cowprotocol/app-data"),s=require("paraswap");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function a(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var c,d=/*#__PURE__*/i(e),u=/*#__PURE__*/i(t);class l extends Error{constructor(e,r){super(e),this.error_code=void 0,this.error_code=r}}function h(e){if(!e)return"";const r=new URLSearchParams;for(const t of Object.keys(e)){const n=e[t];n&&r.append(t,n.toString())}const t=r.toString();return t?`?${t}`:""}exports.SupportedChainId=void 0,(c=exports.SupportedChainId||(exports.SupportedChainId={}))[c.MAINNET=1]="MAINNET",c[c.GOERLI=5]="GOERLI",c[c.GNOSIS_CHAIN=100]="GNOSIS_CHAIN";const p=[exports.SupportedChainId.MAINNET,exports.SupportedChainId.GOERLI,exports.SupportedChainId.GNOSIS_CHAIN],{GPv2Settlement:f}=JSON.parse('{\n "GPv2AllowListAuthentication_Implementation": {\n "1": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67",\n "transactionHash": "0x58340aa44119c74e48635fab0ac344170c6d6e8b42e5714baa4ba4e1651f63ad"\n },\n "4": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67"\n },\n "5": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67",\n "transactionHash": "0x24f4f80b46a17345011065f9ea2af823f582db56be81098b3b66cc2db9659ea7"\n },\n "100": {\n "address": "0x9E7Ae8Bdba9AA346739792d219a808884996Db67",\n "transactionHash": "0xe52d425fe34d6d5215ccfc9ddfa485d490b3018f0ee5bbed708f2d172044d60d"\n }\n },\n "GPv2AllowListAuthentication_Proxy": {\n "1": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0xb84bf720364f94c749f1ec1cdf0d4c44c70411b716459aaccfd24fc677013375"\n },\n "4": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x57b2278fd3a13ab1b132031024475ba1a4e28d7d4d37f556134c84512b742c1f"\n },\n "5": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x39dcf30baf887a5db54551a84de8bfdb6cf418bb284b09680d13aed17d5fa0c1"\n },\n "100": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x1a2d87a05a94bc6680a4faee31bbafbd74e9ddb63dd3941c717b5c609c08b957"\n }\n },\n "GPv2AllowListAuthentication": {\n "1": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0xb84bf720364f94c749f1ec1cdf0d4c44c70411b716459aaccfd24fc677013375"\n },\n "4": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x57b2278fd3a13ab1b132031024475ba1a4e28d7d4d37f556134c84512b742c1f"\n },\n "5": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x39dcf30baf887a5db54551a84de8bfdb6cf418bb284b09680d13aed17d5fa0c1"\n },\n "100": {\n "address": "0x2c4c28DDBdAc9C5E7055b4C863b72eA0149D8aFE",\n "transactionHash": "0x1a2d87a05a94bc6680a4faee31bbafbd74e9ddb63dd3941c717b5c609c08b957"\n }\n },\n "GPv2Settlement": {\n "1": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0xf49f90aa5a268c40001d1227b76bb4dd8247f18361fcad9fffd4a7a44f1320d3"\n },\n "4": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0x609fa2e8f32c73c1f5dc21ff60a26238dacb50d4674d336c90d6950bdda17a21"\n },\n "5": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0x982f089060ff66e19d0683ef1cc6a637297331a9ba95b65d8eb84b9f8dc64b04"\n },\n "100": {\n "address": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41",\n "transactionHash": "0x9ddc538f89cd8433f4a19bc4de0de27e7c68a1d04a14b327185e4bba9af87133"\n }\n },\n "GPv2VaultRelayer": {\n "1": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0xf49f90aa5a268c40001d1227b76bb4dd8247f18361fcad9fffd4a7a44f1320d3"\n },\n "4": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0x609fa2e8f32c73c1f5dc21ff60a26238dacb50d4674d336c90d6950bdda17a21"\n },\n "5": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0x982f089060ff66e19d0683ef1cc6a637297331a9ba95b65d8eb84b9f8dc64b04"\n },\n "100": {\n "address": "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110",\n "transactionHash": "0x9ddc538f89cd8433f4a19bc4de0de27e7c68a1d04a14b327185e4bba9af87133"\n }\n }\n}'),m=p.reduce((e,r)=>({...e,[r]:f[r].address}),{}),v=function(e,t,n,o="v4"){try{let i;function s(e){var r;return i?e:{signature:null==(r=u)?void 0:r.data.toString(),signingScheme:a}}const a="eth_sign"===o?r.SigningScheme.ETHSIGN:r.SigningScheme.EIP712;let c,u=null;try{switch(o){case"v3":c=new r.TypedDataV3Signer(n);break;case"int_v4":c=new r.IntChainIdTypedDataV4Signer(n);break;default:c=n}}catch(p){throw d.default.error("cow-sdk:","Wallet not supported:",p),new l("Wallet not supported")}const h=function(r,n){try{var o=Promise.resolve(t({...e,signer:c,signingScheme:a})).then(function(e){u=e})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(r){if(void 0===(s=r).code&&void 0===s.message)throw d.default.error("cow-sdk:",r),r;var s;if(r.code===T||A.test(r.message))switch(o){case"v4":const o=v(e,t,n,"v3");return i=1,o;case"v3":const s=v(e,t,n,"eth_sign");return i=1,s;default:throw r}else{if(b.test(r.message)){const r=v(e,t,n,"int_v4");return i=1,r}if(r.code===E){const r=v(e,t,n,"eth_sign");return i=1,r}if(w.test(r.message)){const r=v(e,t,n,"v3");return i=1,r}if(y.test(r.message)){const r=v(e,t,n,"eth_sign");return i=1,r}}});return Promise.resolve(h&&h.then?h.then(s):s(h))}catch(f){return Promise.reject(f)}},P=function(e){try{const{chainId:t,signer:n,signingScheme:o,orderId:s}=e,i=x(t);return Promise.resolve(r.signOrderCancellation(i,s,n,O(o)))}catch(e){return Promise.reject(e)}},g=function(e){try{const{chainId:t,signer:n,order:o,signingScheme:s}=e,i=x(t);return Promise.resolve(r.signOrder(i,o,n,O(s)))}catch(e){return Promise.reject(e)}},E=-32603,T=-32601,w=/eth_signTypedData_v4 does not exist/i,y=/eth_signTypedData_v3 does not exist/i,A=/RPC request failed/i,b=/provided chainid .* must match the active chainid/i,I=new Map([[r.SigningScheme.EIP712,{libraryValue:0,apiValue:"eip712"}],[r.SigningScheme.ETHSIGN,{libraryValue:1,apiValue:"ethsign"}],[r.SigningScheme.EIP1271,{libraryValue:2,apiValue:"eip1271"}],[r.SigningScheme.PRESIGN,{libraryValue:3,apiValue:"presign"}]]);function S(e){const r=I.get(e);if(void 0===r)throw new l("Unknown schema "+e);return r}function k(e){return S(e).apiValue}function O(e){return S(e).libraryValue}function x(e){const t=m[e];if(!t)throw new l("Unsupported network. Settlement contract is not deployed");return r.domain(e,t)}var D,N,_,C,R;!function(e){e.DuplicateOrder="DuplicateOrder",e.InvalidSignature="InvalidSignature",e.MissingOrderData="MissingOrderData",e.InsufficientValidTo="InsufficientValidTo",e.InsufficientAllowance="InsufficientAllowance",e.InsufficientBalance="InsufficientBalance",e.InsufficientFee="InsufficientFee",e.WrongOwner="WrongOwner",e.NotFound="NotFound",e.OrderNotFound="OrderNotFound",e.AlreadyCancelled="AlreadyCancelled",e.OrderFullyExecuted="OrderFullyExecuted",e.OrderExpired="OrderExpired",e.NoLiquidity="NoLiquidity",e.UnsupportedToken="UnsupportedToken",e.AmountIsZero="AmountIsZero",e.SellAmountDoesNotCoverFee="SellAmountDoesNotCoverFee",e.TransferEthToContract="TransferEthToContract",e.UNHANDLED_GET_ERROR="UNHANDLED_GET_ERROR",e.UNHANDLED_CREATE_ERROR="UNHANDLED_CREATE_ERROR",e.UNHANDLED_DELETE_ERROR="UNHANDLED_DELETE_ERROR"}(D||(D={})),function(e){e.DuplicateOrder="There was another identical order already submitted. Please try again.",e.InsufficientFee="The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",e.InvalidSignature="The order signature is invalid. Check whether your Wallet app supports off-chain signing.",e.MissingOrderData="The order has missing information",e.InsufficientValidTo="The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.",e.InsufficientAllowance="The account doesn't have enough funds",e.InsufficientBalance="The account needs to approve the selling token in order to trade",e.WrongOwner="The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CowSwap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",e.NotFound="Not found",e.OrderNotFound="The order you are trying to cancel does not exist",e.AlreadyCancelled="Order is already cancelled",e.OrderFullyExecuted="Order is already filled",e.OrderExpired="Order is expired",e.NoLiquidity="Token pair selected has insufficient liquidity",e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.AmountIsZero="Amount is zero",e.SellAmountDoesNotCoverFee="Sell amount does not sufficiently cover the current fee",e.TransferEthToContract="Sending the native currency to smart contract wallets is not currently supported",e.UNHANDLED_GET_ERROR="Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.",e.UNHANDLED_CREATE_ERROR="The order was not accepted by the network",e.UNHANDLED_DELETE_ERROR="The order cancellation was not accepted by the network"}(N||(N={}));class U extends l{static getErrorMessage(e,r){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){return e.errorType?U.apiErrorDetails[e.errorType]||e.errorType:(d.default.error("cow-sdk:","Unknown reason for bad order submission",e),e.description)})}catch(e){return t()}return n&&n.then?n.then(void 0,t):n}(0,function(){return d.default.error("cow-sdk:","Error handling a 400 error. Likely a problem deserialising the JSON response"),function(e){switch(e){case"get":return N.UNHANDLED_GET_ERROR;case"create":return N.UNHANDLED_CREATE_ERROR;case"delete":return N.UNHANDLED_DELETE_ERROR;default:return d.default.error("cow-sdk:","[OperatorError::_mapActionToErrorDetails] Uncaught error mapping error action type to server error. Please try again later."),"Something failed. Please try again later."}}(r)}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e,r){try{const t=this;switch(e.status){case 400:case 404:return Promise.resolve(t.getErrorMessage(e,r));case 403:return Promise.resolve(`The order cannot be ${"create"===r?"accepted":"cancelled"}. Your account is deny-listed.`);case 429:return Promise.resolve(`The order cannot be ${"create"===r?"accepted. Too many order placements":"cancelled. Too many order cancellations"}. Please, retry in a minute`);default:return d.default.error("cow-sdk:",`[OperatorError::getErrorFromStatusCode] Error ${"create"===r?"creating":"cancelling"} the order, status code:`,e.status||"unknown"),Promise.resolve(`Error ${"create"===r?"creating":"cancelling"} the order`)}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="OperatorError",this.description=void 0,this.description=e.description,this.message=N[e.errorType]}}U.apiErrorDetails=N,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(_||(_={})),function(e){e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.InsufficientLiquidity="Token pair selected has insufficient liquidity",e.FeeExceedsFrom='Current fee exceeds entered "from" amount',e.ZeroPrice="Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.",e.UNHANDLED_ERROR="Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later."}(C||(C={}));class L extends l{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){return e.errorType?L.quoteErrorDetails[e.errorType]||e.errorType:(d.default.error("cow-sdk:","Unknown reason for bad quote fetch",e),e.description)})}catch(e){return t()}return n&&n.then?n.then(void 0,t):n}(0,function(){return d.default.error("cow-sdk:","Error handling 400/404 error. Likely a problem deserialising the JSON response"),L.quoteErrorDetails.UNHANDLED_ERROR}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:case 404:return Promise.resolve(r.getErrorMessage(e));default:return d.default.error("cow-sdk:","[QuoteError::getErrorFromStatusCode] Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="QuoteErrorObject",this.description=void 0,this.data=void 0,this.description=e.description,this.message=L.quoteErrorDetails[e.errorType],this.data=null==e?void 0:e.data}}L.quoteErrorDetails=C,exports.ERC20BridgeSource=void 0,(R=exports.ERC20BridgeSource||(exports.ERC20BridgeSource={})).Native="Native",R.Uniswap="Uniswap",R.UniswapV2="Uniswap_V2",R.Eth2Dai="Eth2Dai",R.Kyber="Kyber",R.Curve="Curve",R.LiquidityProvider="LiquidityProvider",R.MultiBridge="MultiBridge",R.Balancer="Balancer",R.BalancerV2="Balancer_V2",R.Cream="CREAM",R.Bancor="Bancor",R.MakerPsm="MakerPsm",R.MStable="mStable",R.Mooniswap="Mooniswap",R.MultiHop="MultiHop",R.Shell="Shell",R.Swerve="Swerve",R.SnowSwap="SnowSwap",R.SushiSwap="SushiSwap",R.Dodo="DODO",R.DodoV2="DODO_V2",R.CryptoCom="CryptoCom",R.Linkswap="Linkswap",R.KyberDmm="KyberDMM",R.Smoothy="Smoothy",R.Component="Component",R.Saddle="Saddle",R.XSigma="xSigma",R.UniswapV3="Uniswap_V3",R.CurveV2="Curve_V2",R.Lido="Lido",R.ShibaSwap="ShibaSwap",R.Clipper="Clipper",R.PancakeSwap="PancakeSwap",R.PancakeSwapV2="PancakeSwap_V2",R.BakerySwap="BakerySwap",R.Nerve="Nerve",R.Belt="Belt",R.Ellipsis="Ellipsis",R.ApeSwap="ApeSwap",R.CafeSwap="CafeSwap",R.CheeseSwap="CheeseSwap",R.JulSwap="JulSwap",R.ACryptos="ACryptoS",R.QuickSwap="QuickSwap",R.ComethSwap="ComethSwap",R.Dfyn="Dfyn",R.WaultSwap="WaultSwap",R.Polydex="Polydex",R.FirebirdOneSwap="FirebirdOneSwap",R.JetSwap="JetSwap",R.IronSwap="IronSwap";class j{constructor(e,r){this.symbol=void 0,this.address=void 0,this.symbol=e,this.address=r}}const H={[exports.SupportedChainId.MAINNET]:new j("WETH","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),[exports.SupportedChainId.GOERLI]:new j("WETH","0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6"),[exports.SupportedChainId.GNOSIS_CHAIN]:new j("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},M={[exports.SupportedChainId.MAINNET]:"ETH",[exports.SupportedChainId.GOERLI]:"ETH",[exports.SupportedChainId.GNOSIS_CHAIN]:"XDAI"};function V(e,r){let t=e;return e===M[r]&&(t=H[r].address),t}const F={"Content-Type":"application/json"};class q{constructor({context:e,name:r,getApiUrl:t,defaultHeaders:n=F,apiVersion:o="v1"}){this.context=void 0,this.API_NAME=void 0,this.API_VERSION=void 0,this.API_URL_GETTER=void 0,this.DEFAULT_HEADERS=void 0,this.context=e,this.API_NAME=r,this.API_VERSION=o,this.API_URL_GETTER=t,this.DEFAULT_HEADERS=n}getApiBaseUrl(){try{const e=this,r=arguments;return Promise.resolve(e.context.chainId).then(function(t){const n=e.API_URL_GETTER(...[].slice.call(r))[t];if(n)return n+"/"+e.API_VERSION;throw new l(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+t)})}catch(e){return Promise.reject(e)}}post(e,r,t={},n){const o=[e,"POST",this.fetch.bind(this),this.API_URL_GETTER,t,r];return n?this.fetchSingleEnv(...o):this.fetchMultipleEnvs(...o)}get(e,r={}){return this.fetchMultipleEnvs(e,"GET",this.fetch.bind(this),this.API_URL_GETTER,r)}delete(e,r,t={}){return this.fetchMultipleEnvs(e,"DELETE",this.fetch.bind(this),this.API_URL_GETTER,t,r)}fetchSingleEnv(e,r,t,n,o={},s){try{const i=this;function a(o){function a(a){const c=n(o);return t(e,r,`${c[a]}/${i.API_VERSION}`,s,u)}return c?a(c):Promise.resolve(i.context.chainId).then(a)}const{chainId:c,env:d,requestOptions:u}=o;return Promise.resolve(d?a(d):Promise.resolve(i.context.env).then(a))}catch(l){return Promise.reject(l)}}fetchMultipleEnvs(e,r,t,n,o={},s){try{const i=this;function a(o){return i.fetchMultipleEnvsRecursive({url:e,method:r,fetchFn:t,getApiUrl:n,options:u,envs:l,chainId:o,data:s})}const{env:c,chainId:d,...u}=o,l=c?[c]:["prod","staging"];return Promise.resolve(d?a(d):Promise.resolve(i.context.chainId).then(a))}catch(h){return Promise.reject(h)}}fetch(e,r,t,n,o){try{return Promise.resolve(u.default(t+e,{headers:this.DEFAULT_HEADERS,...o,method:r,body:void 0!==n?JSON.stringify(n):n}))}catch(e){return Promise.reject(e)}}fetchMultipleEnvsRecursive(e){try{const r=this,{url:t,method:n,fetchFn:o,getApiUrl:s,options:i={},envs:a,chainId:c,data:d}=e,{requestOptions:u}=i,[l,...h]=a,p=s(l)[c];return Promise.resolve(function(s,i){try{var a=Promise.resolve(o(t,n,`${p}/${r.API_VERSION}`,d,u)).then(function(t){return!t.ok&&null!=h&&h.length?r.fetchMultipleEnvsRecursive({...e,envs:h}):t})}catch(e){return i(e)}return a&&a.then?a.then(void 0,i):a}(0,function(t){if(null!=h&&h.length)return r.fetchMultipleEnvsRecursive({...e,envs:h});throw t}))}catch(e){return Promise.reject(e)}}}function B(e){return function(e){const{ethflowData:t}=e;if(!t)return e;const{userValidTo:n}=t,o=e.onchainUser||e.owner,s=r.BUY_ETH_ADDRESS;return{...e,validTo:n,owner:o,sellToken:s}}(function(e){const{executedFeeAmount:r,executedSurplusFee:t}=e,n=null!=t?t:r;return{...e,totalFee:n}}(e))}function $(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}const G=function(e,r){try{return e.ok?Promise.resolve(e.json()):"application/json"===e.headers.get("Content-Type")?Promise.resolve(e.json()).then(function(e){const t=function(e){switch(null==e?void 0:e.errorType){case D.NotFound:case D.NoLiquidity:return{errorType:_.InsufficientLiquidity,description:C.InsufficientLiquidity};case D.SellAmountDoesNotCoverFee:return{errorType:_.FeeExceedsFrom,description:C.FeeExceedsFrom,data:null==e?void 0:e.data};case D.UnsupportedToken:return{errorType:_.UnsupportedToken,description:e.description};case D.SellAmountDoesNotCoverFee:return{errorType:_.FeeExceedsFrom,description:e.description};default:return{errorType:_.UNHANDLED_ERROR,description:C.UNHANDLED_ERROR}}}(e),n=new L(t);if(r){const{sellToken:e,buyToken:t}=r;d.default.error("cow-sdk:",`Error querying fee from API - sellToken: ${e}, buyToken: ${t}`)}throw n}):Promise.resolve(e.text()).then(function(e){throw new L({description:e,errorType:_.UNHANDLED_ERROR})})}catch(e){return Promise.reject(e)}};function Q(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[exports.SupportedChainId.GOERLI]:"https://barn.api.cow.fi/goerli/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai/api"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/mainnet/api",[exports.SupportedChainId.GOERLI]:"https://api.cow.fi/goerli/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}}function X(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/affiliate/api"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/affiliate/api"}}}const Z={errorType:_.UNHANDLED_ERROR,description:C.UNHANDLED_ERROR},J={errorType:D.UNHANDLED_GET_ERROR,description:N.UNHANDLED_GET_ERROR};class W extends q{constructor(e){super({context:e,name:"CoW Protocol",apiVersion:"v1",getApiUrl:Q})}getProfileData(e,r={}){try{const t=this;function n(r){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get profile data for`,r,e),r!==exports.SupportedChainId.MAINNET?(d.default.info("cow-sdk:","Profile data is only available for mainnet"),null):Promise.resolve(t.getProfile(`/profile/${e}`,{chainId:r,env:s})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw d.default.error("cow-sdk:",e),new l(null==e?void 0:e.description)})})}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getTrades(e,r={}){try{const t=this;function n(e){return d.default.debug("cow-sdk:","[util:operator] Get trades for",e,{owner:i,orderId:a}),$(function(){return Promise.resolve(t.get(`/trades${c}`,{chainId:e,env:s})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("cow-sdk:","Error getting trades:",e),e instanceof U)throw e;throw new l("Error getting trades: "+e)})}const{chainId:o,env:s=t.context.env}=r,{owner:i,orderId:a}=e;if(i&&a)throw new l("Cannot specify both owner and orderId");const c=h({owner:i,orderUid:a});return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(u){return Promise.reject(u)}}getOrders(e,r={}){try{const t=this;function n(e){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get orders for `,e,i,a,c),$(function(){return Promise.resolve(t.get(`/account/${i}/orders/${u}`,{chainId:e,env:s})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return e.map(B)}):Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("cow-sdk:","Error getting orders information:",e),e instanceof U)throw e;throw new U(J)})}const{chainId:o,env:s=t.context.env}=r,{owner:i,limit:a=1e3,offset:c=0}=e,u=h({limit:a,offset:c});return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(l){return Promise.reject(l)}}getTxOrders(e,r={}){try{const t=this;function n(r){return d.default.debug(`[api:${t.API_NAME}] Get tx orders for `,r,e),$(function(){return Promise.resolve(t.get(`/transactions/${e}/orders`,{chainId:r,env:s})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return e.map(B)}):Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("Error getting transaction orders information:",e),e instanceof U)throw e;throw new U(J)})}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getOrder(e,r={}){try{const t=this;function n(r){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get order for `,r,e),$(function(){return Promise.resolve(t.get(`/orders/${e}`,{chainId:r,env:s})).then(function(e){return e.ok?Promise.resolve(e.json()).then(B):Promise.resolve(e.json()).then(function(e){throw new U(e)})})},function(e){if(d.default.error("cow-sdk:","Error getting order information:",e),e instanceof U)throw e;throw new U(J)})}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getPriceQuoteLegacy(e,r={}){try{const t=this;function n(r){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get price from API`,e,"for",r),Promise.resolve(t.get(`/markets/${V(i,r)}-${V(a,r)}/${u}/${c}`,{chainId:r,env:s}).catch(e=>{throw d.default.error("cow-sdk:","Error getting price quote:",e),new L(Z)})).then(G)}const{chainId:o,env:s}=r,{baseToken:i,quoteToken:a,amount:c,kind:u}=e;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(l){return Promise.reject(l)}}getQuoteLegacyParams(e,r={}){try{const t=this;function n(r){const n=t.mapNewToLegacyParams(e,r);return Promise.resolve(t.post("/quote",n,{chainId:r,env:s})).then(G)}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}getQuote(e,r={}){try{const t=this;function n(r){return Promise.resolve(t.post("/quote",e,{chainId:r,env:s})).then(G)}const{chainId:o,env:s}=r;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(i){return Promise.reject(i)}}sendSignedOrderCancellation(e,r={}){try{const t=this;function n(e){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Delete signed order for network`,e,i),Promise.resolve(t.delete(`/orders/${i.orderUid}`,{signature:i.signature,signingScheme:k(i.signingScheme),from:a},{chainId:e,env:s})).then(function(r){function n(r){d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Cancelled order`,i.orderUid,e)}const o=function(){if(!r.ok)return Promise.resolve(U.getErrorFromStatusCode(r,"delete")).then(function(e){throw new l(e)})}();return o&&o.then?o.then(n):n()})}const{chainId:o,env:s}=r,{cancellation:i,owner:a}=e;return Promise.resolve(o?n(o):Promise.resolve(t.context.chainId).then(n))}catch(c){return Promise.reject(c)}}sendOrder(e,r={}){try{const t=this;function n(r){const{owner:n}=e;return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Post signed order for network`,r,o),Promise.resolve(t.post("/orders",{...o,signingScheme:k(o.signingScheme),from:n},{chainId:r,env:i},!0)).then(function(e){function r(r){return Promise.resolve(e.json()).then(function(e){return d.default.debug("cow-sdk:",`[api:${t.API_NAME}] Success posting the signed order`,e),e})}const n=function(){if(!e.ok)return Promise.resolve(U.getErrorFromStatusCode(e,"create")).then(function(e){throw new l(e)})}();return n&&n.then?n.then(r):r()})}const o={...e.order,appData:t.context.appDataHash},{chainId:s,env:i}=r;return Promise.resolve(s?n(s):Promise.resolve(t.context.chainId).then(n))}catch(a){return Promise.reject(a)}}getOrderLink(e){try{return Promise.resolve(this.getApiBaseUrl()).then(function(r){return r+`/orders/${e}`})}catch(e){return Promise.reject(e)}}getApiBaseUrl(){return super.getApiBaseUrl(this.context.env)}getProfile(e,r={}){return this.fetchMultipleEnvs(e,"GET",this.fetchProfile.bind(this),X,r)}mapNewToLegacyParams(e,t){const{amount:n,kind:o,userAddress:s,receiver:i,validTo:a,sellToken:c,buyToken:d}=e,u=s||"0x0000000000000000000000000000000000000000",l={sellToken:V(c,t),buyToken:V(d,t),from:u,receiver:i||u,appData:this.context.appDataHash,validTo:a,partiallyFillable:!1};return o===r.OrderKind.SELL?{kind:r.OrderKind.SELL,sellAmountBeforeFee:n,...l}:{kind:r.OrderKind.BUY,buyAmountAfterFee:n,...l}}fetchProfile(e,r,t,n){try{return Promise.resolve(fetch(t+e,{headers:this.DEFAULT_HEADERS,method:r,body:void 0!==n?JSON.stringify(n):n}))}catch(e){return Promise.reject(e)}}}const K=n.gql`
|
|
2
2
|
query Totals {
|
|
3
3
|
totals {
|
|
4
4
|
tokens
|
|
@@ -25,5 +25,5 @@ var e=require("loglevel"),r=require("@cowprotocol/contracts"),t=require("cross-f
|
|
|
25
25
|
volumeUsd
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
`;class ee{constructor(e){this.context=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e}getBaseUrl(e={}){try{const r=this;function t(e){const r=function(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-staging",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc-staging"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[exports.SupportedChainId.GOERLI]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-goerli",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"}}}(o)[e];if(!r)throw new l(`No network support for SubGraph in ChainId ${n} and Environment "${o}"`);return r}const{chainId:n,env:o="prod"}=e;return Promise.resolve(n?t(n):Promise.resolve(r.context.chainId).then(t))}catch(s){return Promise.reject(s)}}getTotals(e={}){try{const r=this;return Promise.resolve(r.context.chainId).then(function(t){return d.default.debug(`[subgraph:${r.API_NAME}] Get totals for:`,t),Promise.resolve(r.runQuery(K,void 0,e)).then(function(e){return e.totals[0]})})}catch(e){return Promise.reject(e)}}getLastDaysVolume(e,r={}){try{const t=this;return Promise.resolve(t.context.chainId).then(function(n){return d.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} days volume for:`,n),t.runQuery(z,{days:e},r)})}catch(e){return Promise.reject(e)}}getLastHoursVolume(e,r={}){try{const t=this;return Promise.resolve(t.context.chainId).then(function(n){return d.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} hours volume for:`,n),t.runQuery(Y,{hours:e},r)})}catch(e){return Promise.reject(e)}}runQuery(e,r,t={}){try{const o=this,{chainId:s,env:i}=t;return Promise.resolve(o.getBaseUrl({chainId:s,env:i})).then(function(t){return function(o,s){try{var i=Promise.resolve(n.request(t,e,r))}catch(e){return s(e)}return i&&i.then?i.then(void 0,s):i}(0,function(t){return d.default.error(`[subgraph:${o.API_NAME}]`,t),Promise.resolve(o.getBaseUrl()).then(function(n){throw new l(`Error running query: ${e}. Variables: ${JSON.stringify(r)}. API: ${n}. Inner Error: ${t}`)})})})}catch(e){return Promise.reject(e)}}}const re=function(e){try{const r=1,t=112,n=18,o=32,s=function(e){const r=e.match(/.{1,2}/g);if(r)return new Uint8Array(r.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!s)return Promise.resolve();const i=Uint8Array.from([r,t,n,o,...s]);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:e}){return e.decode(i).toV0().toString()})}catch(e){return Promise.reject(e)}};function te(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}class ne{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e){const{appDataParams:r,metadataParams:t}=e||{},{referrerParams:n,quoteParams:s}=t||{},i={};n&&(i.referrer=o.createReferrerMetadata(n)),s&&(i.quote=o.createQuoteMetadata(s));const a=r?.appCode||"CowSwap";return o.createAppDataDoc({...r,appCode:a,metadata:i})}getAppDataSchema(e){try{return Promise.resolve(te(function(){return Promise.resolve(o.getAppDataSchema(e))},function(e){throw new l(e.message)}))}catch(e){return Promise.reject(e)}}validateAppDataDoc(e){try{return Promise.resolve(o.validateAppDataDoc(e))}catch(e){return Promise.reject(e)}}decodeAppData(e){try{return Promise.resolve(te(function(){return Promise.resolve(re(e)).then(function(e){if(!e)throw new l("Error getting serialized CID");return function(e,r="https://gnosis.mypinata.cloud/ipfs"){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:t}){return Promise.resolve(t(`${r}/${e}`)).then(function(e){return Promise.resolve(e.json())})})}catch(e){return Promise.reject(e)}}(e)})},function(e){const r=e;throw d.default.error("Error decoding AppData:",r),new l("Error decoding AppData: "+r.message)}))}catch(e){return Promise.reject(e)}}cidToAppDataHex(e){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:r}){const{digest:t}=r.parse(e).multihash;return`0x${Buffer.from(t).toString("hex")}`})}catch(e){return Promise.reject(e)}}appDataHexToCid(e){try{return Promise.resolve(re(e)).then(function(e){if(!e)throw new l("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}calculateAppDataHash(e){try{const r=this;return Promise.resolve(r.validateAppDataDoc(e)).then(function(t){if(!t?.success)throw new l("Invalid appData provided",t?.errors);return te(function(){return Promise.resolve(function(e){try{const r=JSON.stringify(e);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("ipfs-only-hash"))})).then(function({of:e}){return e(r,{cidVersion:0})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(r.cidToAppDataHex(e)).then(function(r){if(!r)throw new l(`Could not extract appDataHash from calculated cidV0 ${e}`);return{cidV0:e,appDataHash:r}})})},function(e){throw new l("Failed to calculate appDataHash",e.message)})})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const r=this;return Promise.resolve(function(e,{writeUri:r="https://api.pinata.cloud",pinataApiKey:t="",pinataApiSecret:n=""}){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:o}){if(!t||!n)throw new l("You need to pass IPFS api credentials.");const s=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData"}});return Promise.resolve(o(`${r}/pinning/pinJSONToIPFS`,{method:"POST",body:s,headers:{"Content-Type":"application/json",pinata_api_key:t,pinata_secret_api_key:n}})).then(function(e){return Promise.resolve(e.json()).then(function(r){if(200!==e.status)throw new Error(r.error.details||r.error);return r})})})}catch(e){return Promise.reject(e)}}(e,r.context.ipfs)).then(function({IpfsHash:e}){return r.cidToAppDataHex(e)})}catch(e){return Promise.reject(e)}}}var oe=0;function se(e){return"__private_"+oe+++"_"+e}function ie(e,r){if(!Object.prototype.hasOwnProperty.call(e,r))throw new TypeError("attempted to use private field on non-instance");return e}const ae={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",env:"prod",ipfs:{readUri:"https://gnosis.mypinata.cloud/ipfs",writeUri:"https://api.pinata.cloud",pinataApiKey:"",pinataApiSecret:""}};var ce=/*#__PURE__*/se("chainId"),de=/*#__PURE__*/se("context");class ue{updateContext(e,r){this.setParams(r,e)}constructor(e,r){Object.defineProperty(this,ce,{writable:!0,value:exports.SupportedChainId.MAINNET}),Object.defineProperty(this,de,{writable:!0,value:ae}),this.setParams(e,r)}setParams(e,r){ie(this,ce)[ce]=this.updateChainId(e),ie(this,de)[de]={...ae,...r,ipfs:{...ae.ipfs,...r.ipfs}}}updateChainId(e){if(!exports.SupportedChainId[e])throw new l(`Invalid chainId: ${e}`);return d.default.debug("cow-sdk:",`Updating chainId to: ${e}`),ie(this,ce)[ce]=e,e}get chainId(){const e=this,r=ie(this,de)[de].signer?.provider;return r?(d.default.debug("cow-sdk:","Getting chainId from provider"),function(){try{return Promise.resolve(r.getNetwork()).then(function(r){const t=r.chainId;return t!==ie(e,ce)[ce]&&(d.default.debug("cow-sdk:",`ChainId mismatch: Provider's chainId: ${t} vs Context's chainId: ${ie(e,ce)[ce]}. Updating Context's chainId`),e.updateChainId(t)),t})}catch(e){return Promise.reject(e)}}()):Promise.resolve(ie(this,ce)[ce])}get appDataHash(){var e;return null!==(e=ie(this,de)[de].appDataHash)&&void 0!==e?e:ae.appDataHash}get env(){return ie(this,de)[de].env||ae.env}get signer(){return ie(this,de)[de].signer}get ipfs(){var e;return null!==(e=ie(this,de)[de].ipfs)&&void 0!==e?e:ae.ipfs}}function le({quoteToken:e,baseToken:t,kind:n}){return n===r.OrderKind.SELL?{sellToken:t,buyToken:e}:{buyToken:t,sellToken:e}}class he extends l{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){if(e.validationErrors?.length)return e.validationErrors?.[0].reason||e.reason;if(e?.reason)return d.default.error("0x-sdk:","Unknown validation reason for bad price request",e),e.reason;throw new Error('Error response body properties "reason" and "validationErrors" missing.')})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){const r=e instanceof Error;return d.default.error("0x-sdk:","Error handling a 4xx error. Likely a problem deserialising the JSON response.",r&&e?.message),r?e?.message:"Price fetch failed. This may be due to a server or network connectivity issue. Please try again later."}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:return Promise.resolve(r.getErrorMessage(e));case 404:return Promise.resolve("Not found");case 429:return Promise.resolve("Too many requests - Rate limit exceeded");case 500:return Promise.resolve("Internal server error");case 501:return Promise.resolve("Not Implemented");case 503:return Promise.resolve("Server Error - Too many open connections");default:return d.default.error("0x-sdk:","Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.reason,e.code.toString()),this.name="ZeroXError",this.description=void 0,this.message=void 0,this.description=e.validationErrors?.[0].reason||e.reason,this.message=e.reason}}const pe=function(e,r){try{return e.ok?Promise.resolve(e.json()):Promise.resolve(e.clone().json()).then(function(t){function n(){if(r){const{quoteToken:e,baseToken:t}=r;d.default.error("0x-sdk:",`Error querying fee from API - quoteToken: ${e}, baseToken: ${t}`)}throw o}let o;const s=function(){if(!t?.code||!t?.reason)return Promise.resolve(he.getErrorFromStatusCode(e.clone())).then(function(r){o=new he({code:e.status,reason:r})});o=new he(t)}();return s&&s.then?s.then(n):n()})}catch(e){return Promise.reject(e)}};function fe(){return{[exports.SupportedChainId.MAINNET]:"https://api.0x.org/swap"}}function me({excludedSources:e,affiliateAddress:r}){return h({excludedSources:Pe({excludedSources:e}),affiliateAddress:r})}function ve({affiliateAddressMap:e,chainId:r}){const t=e[r];if(!t)throw new l(`Invalid affiliate address! Parameters passed: ${JSON.stringify({affiliateAddressMap:e,chainId:r},null,2)}`);return t}function Pe({excludedSources:e}){return e.length>0?e.join(","):""}const ge=[];class Ee extends q{constructor(e,r){super({context:new ue(e,{}),name:"0x",apiVersion:"v1",getApiUrl:fe}),this.ZEROX_OPTIONS=void 0,this.ZEROX_OPTIONS_URL=void 0;const t=r?.affiliateAddressMap||m,n=r?.excludedSources||ge,o=ve({affiliateAddressMap:t,chainId:e});this.ZEROX_OPTIONS={affiliateAddressMap:t,excludedSources:n},this.ZEROX_OPTIONS_URL=me({excludedSources:n,affiliateAddress:o})}getQuote(e,t={}){try{const n=this;function o(t){const o=function(e){return e===exports.SupportedChainId.MAINNET?e:null}(t);if(null==o)return d.default.debug("0x-sdk:","Network not supported"),null;d.default.debug("0x-sdk:",`Get price from ${n.API_NAME}`,e,n.ZEROX_OPTIONS);const{sellToken:u,buyToken:p}=le({baseToken:V(i,t),quoteToken:V(a,t),kind:c}),f=ve({affiliateAddressMap:n.ZEROX_OPTIONS.affiliateAddressMap,chainId:t});return Promise.resolve(n.get(`/price${h({sellToken:u,buyToken:p,[c===r.OrderKind.BUY?"buyAmount":"sellAmount"]:s,affiliateAddress:f,excludedSources:Pe(n.ZEROX_OPTIONS)})}`,{chainId:t,env:l}).catch(e=>{throw d.default.error(`Error getting ${n.API_NAME} price quote:`,e),new Error(e)})).then(pe)}const{amount:s,baseToken:i,quoteToken:a,kind:c}=e,{chainId:u,env:l=n.context.env}=t;return Promise.resolve(u?o(u):Promise.resolve(n.context.chainId).then(o))}catch(p){return Promise.reject(p)}}updateOptions({affiliateAddressMap:e,excludedSources:r}){try{const t=this;return Promise.resolve(t.context.chainId).then(function(n){e&&(d.default.debug("0x-sdk:","Updating 0x options affiliate address to",e),t.ZEROX_OPTIONS.affiliateAddressMap=e),r&&(d.default.debug("0x-sdk:","Updating 0x options excludedSources to",r),t.ZEROX_OPTIONS.excludedSources=r);const o=ve({affiliateAddressMap:t.ZEROX_OPTIONS.affiliateAddressMap,chainId:n});t.ZEROX_OPTIONS_URL=me({...t.ZEROX_OPTIONS,affiliateAddress:o})})}catch(e){return Promise.reject(e)}}}const Te="https://apiv5.paraswap.io",we={maxImpact:100,excludeDEXS:"ParaSwapPool4"},ye=new Map([[1,new s.ParaSwap(1,Te)],[3,new s.ParaSwap(3,Te)],[56,new s.ParaSwap(56,Te)],[137,new s.ParaSwap(137,Te)],[250,new s.ParaSwap(250,Te)],[42161,new s.ParaSwap(42161,Te)],[43114,new s.ParaSwap(43114,Te)]]),Ae=p.filter(e=>ye.has(e));class be extends l{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){if(e.data?.error||e.message)return e.data?.error||e.message;throw new Error('Error response body properties "data.error" and "message" missing.')})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){const r=e instanceof Error;return d.default.error("ParaswapApi","Error handling a 4xx error. Likely a problem deserialising the JSON response.",r&&e?.message),r?e?.message:"Price fetch failed. This may be due to a server or network connectivity issue. Please try again later."}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:return Promise.resolve(r.getErrorMessage(e));case 404:return Promise.resolve("Not found");default:return d.default.error("ParaswapApi","Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.message,e.status?.toString()),this.name="ParaswapError",this.description=void 0,this.message=void 0,this.description=e.data?.error||e.message,this.message=e.message}}function Ie(e){return e===exports.SupportedChainId.MAINNET?e:null}function Se(e){if(function(e){return!!e?.destAmount}(e))return e;{const t="ESTIMATED_LOSS_GREATER_THAN_MAX_IMPACT"===(r=e)?.message&&r.data&&r.data.priceRoute?r.data.priceRoute:null;if(t)return t;throw new be(e)}var r}var ke,Oe,xe,De,Ne,_e,Ce,Re,Ue,Le,je,He,Me,Ve,Fe,qe,Be,$e,Ge,Qe=/*#__PURE__*/se("libMap"),Xe=/*#__PURE__*/se("apiUrl"),Ze=/*#__PURE__*/se("rateOptions"),Je=/*#__PURE__*/se("getLib");class We{constructor(e={}){Object.defineProperty(this,Je,{value:Ke}),this.name=void 0,Object.defineProperty(this,Qe,{writable:!0,value:ye}),Object.defineProperty(this,Xe,{writable:!0,value:void 0}),Object.defineProperty(this,Ze,{writable:!0,value:void 0}),this.name="Paraswap",ie(this,Xe)[Xe]=Te,ie(this,Ze)[Ze]={...we,...e}}getQuote(t,n={allowParaswapNetworks:!1}){try{const o=this,{chainId:i}=t,{baseToken:a,quoteToken:c,fromDecimals:d,toDecimals:u,amount:h,kind:p,userAddress:f}=function(e,r){const{baseToken:t,quoteToken:n,userAddress:o}=r,s=V(t,e),i=V(n,e);return{...r,baseToken:s,quoteToken:i,userAddress:null!=o?o:void 0}}(t.chainId,t),m=!n?.allowParaswapNetworks,v=!!Ie(i);if(m&&!v)throw new l("ParaswapApi isn't compatible with chainId "+i);const P=ie(o,Je)[Je](i);if(!P)throw new l("ParaswapApi isn't compatible with chainId "+i);const{sellToken:g,buyToken:E}=le({baseToken:a,quoteToken:c,kind:p}),T=p===r.OrderKind.BUY?s.SwapSide.BUY:s.SwapSide.SELL,w={...ie(o,Ze)[Ze],...n?.rateOptions};return n?.allowParaswapNetworks||Ie(i)?(e.debug("ParaswapApi","Getting price quote",t),Promise.resolve(P.getRate(g,E,h,f,T,w,d,u)).then(Se)):(e.error("ParaswapApi",`Chain id ${i} is not currently supported by the CoW contracts - please use: ${Ae.join(",")}. If you want to query all other ParaSwap specific chain ids, please pass { allowParaswapNetworks: true } as the query's "options" parameter.`),Promise.resolve(null))}catch(e){return Promise.reject(e)}}getQuoteCowNetworks(e,r){try{return Promise.resolve(this.getQuote(e,{...r,allowParaswapNetworks:!1}))}catch(e){return Promise.reject(e)}}getQuoteAllNetworks(e,r){try{return Promise.resolve(this.getQuote(e,{...r,allowParaswapNetworks:!0}))}catch(e){return Promise.reject(e)}}updateOptions(e){try{const r=this;return ie(r,Ze)[Ze]=null===e.rateOptions?{}:{...ie(r,Ze)[Ze],...e.rateOptions||{}},e.apiUrl&&(ie(r,Xe)[Xe]=e.apiUrl),Promise.resolve()}catch(e){return Promise.reject(e)}}get rateOptions(){return ie(this,Ze)[Ze]}get apiUrl(){return ie(this,Xe)[Xe]}}function Ke(e){var r;return null!==(r=ie(this,Qe)[Qe].get(e))&&void 0!==r?r:null}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(ke||(ke={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Oe||(Oe={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(xe||(xe={})),function(e){e.Asc="asc",e.Desc="desc"}(De||(De={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsSigned="isSigned",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(Ne||(Ne={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(_e||(_e={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Ce||(Ce={})),function(e){e.Id="id",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Re||(Re={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(Ue||(Ue={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Le||(Le={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(je||(je={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(He||(He={})),function(e){e.Address="address",e.DailyTotals="dailyTotals",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.HourlyTotals="hourlyTotals",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Me||(Me={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ve||(Ve={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(Fe||(Fe={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(qe||(qe={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.Id="id",e.Name="name",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol"}(Be||(Be={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}($e||($e={})),function(e){e.Allow="allow",e.Deny="deny"}(Ge||(Ge={}));var ze={__proto__:null,get Bundle_OrderBy(){return ke},get DailyTotal_OrderBy(){return Oe},get HourlyTotal_OrderBy(){return xe},get OrderDirection(){return De},get Order_OrderBy(){return Ne},get PairDaily_OrderBy(){return _e},get PairHourly_OrderBy(){return Ce},get Pair_OrderBy(){return Re},get Settlement_OrderBy(){return Ue},get TokenDailyTotal_OrderBy(){return Le},get TokenHourlyTotal_OrderBy(){return je},get TokenTradingEvent_OrderBy(){return He},get Token_OrderBy(){return Me},get Total_OrderBy(){return Ve},get Trade_OrderBy(){return Fe},get UniswapPool_OrderBy(){return qe},get UniswapToken_OrderBy(){return Be},get User_OrderBy(){return $e},get _SubgraphErrorPolicy_(){return Ge}};Object.defineProperty(exports,"OrderKind",{enumerable:!0,get:function(){return r.OrderKind}}),exports.ALL_SUPPORTED_CHAIN_IDS=p,exports.COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS=m,exports.CowError=l,exports.CowSdk=class{constructor(e=exports.SupportedChainId.MAINNET,r={},t={}){var n,o;const s=this;this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.zeroXApi=void 0,this.paraswapApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.updateContext=function(e,r){try{return Promise.resolve(s.context.chainId).then(function(t){s.context.updateContext(e,r||t)})}catch(e){return Promise.reject(e)}};const i=null!==(n=t?.zeroXOptions?.enabled)&&void 0!==n&&n,a=null!==(o=t?.paraswapOptions?.enabled)&&void 0!==o&&o;this.context=new ue(e,{...r}),this.cowApi=new J(this.context),this.cowSubgraphApi=new ee(this.context),this.metadataApi=new ne(this.context),this.zeroXApi=i?new Ee(e,t.zeroXOptions):void 0,this.paraswapApi=a?new We(t.paraswapOptions):void 0,d.default.setLevel(t.loglevel||"ERROR")}signOrder(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(n){return function(e,r,t){return v({order:e,chainId:r},g,t)}({...e,appData:r.context.appDataHash},n,t)})}catch(e){return Promise.reject(e)}}signOrderCancellation(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(r){return function(e,r,t){return v({orderId:e,chainId:r},P,t)}(e,r,t)})}catch(e){return Promise.reject(e)}}_checkSigner(e=this.context.signer){if(!e)throw new l("No signer available");return e}},exports.GraphQL=ze,exports.Token=j;
|
|
28
|
+
`;class ee{constructor(e){this.context=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e}getBaseUrl(e={}){try{const r=this;function t(e){const r=function(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-staging",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc-staging"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[exports.SupportedChainId.GOERLI]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-goerli",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"}}}(o)[e];if(!r)throw new l(`No network support for SubGraph in ChainId ${n} and Environment "${o}"`);return r}const{chainId:n,env:o="prod"}=e;return Promise.resolve(n?t(n):Promise.resolve(r.context.chainId).then(t))}catch(s){return Promise.reject(s)}}getTotals(e={}){try{const r=this;return Promise.resolve(r.context.chainId).then(function(t){return d.default.debug(`[subgraph:${r.API_NAME}] Get totals for:`,t),Promise.resolve(r.runQuery(K,void 0,e)).then(function(e){return e.totals[0]})})}catch(e){return Promise.reject(e)}}getLastDaysVolume(e,r={}){try{const t=this;return Promise.resolve(t.context.chainId).then(function(n){return d.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} days volume for:`,n),t.runQuery(z,{days:e},r)})}catch(e){return Promise.reject(e)}}getLastHoursVolume(e,r={}){try{const t=this;return Promise.resolve(t.context.chainId).then(function(n){return d.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} hours volume for:`,n),t.runQuery(Y,{hours:e},r)})}catch(e){return Promise.reject(e)}}runQuery(e,r,t={}){try{const o=this,{chainId:s,env:i}=t;return Promise.resolve(o.getBaseUrl({chainId:s,env:i})).then(function(t){return function(o,s){try{var i=Promise.resolve(n.request(t,e,r))}catch(e){return s(e)}return i&&i.then?i.then(void 0,s):i}(0,function(t){return d.default.error(`[subgraph:${o.API_NAME}]`,t),Promise.resolve(o.getBaseUrl()).then(function(n){throw new l(`Error running query: ${e}. Variables: ${JSON.stringify(r)}. API: ${n}. Inner Error: ${t}`)})})})}catch(e){return Promise.reject(e)}}}const re=function(e){try{const r=1,t=112,n=18,o=32,s=function(e){const r=e.match(/.{1,2}/g);if(r)return new Uint8Array(r.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!s)return Promise.resolve();const i=Uint8Array.from([r,t,n,o,...s]);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:e}){return e.decode(i).toV0().toString()})}catch(e){return Promise.reject(e)}};function te(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}class ne{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e){const{appDataParams:r,metadataParams:t}=e||{},{referrerParams:n,quoteParams:s}=t||{},i={};n&&(i.referrer=o.createReferrerMetadata(n)),s&&(i.quote=o.createQuoteMetadata(s));const a=(null==r?void 0:r.appCode)||"CowSwap";return o.createAppDataDoc({...r,appCode:a,metadata:i})}getAppDataSchema(e){try{return Promise.resolve(te(function(){return Promise.resolve(o.getAppDataSchema(e))},function(e){throw new l(e.message)}))}catch(e){return Promise.reject(e)}}validateAppDataDoc(e){try{return Promise.resolve(o.validateAppDataDoc(e))}catch(e){return Promise.reject(e)}}decodeAppData(e){try{return Promise.resolve(te(function(){return Promise.resolve(re(e)).then(function(e){if(!e)throw new l("Error getting serialized CID");return function(e,r="https://gnosis.mypinata.cloud/ipfs"){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:t}){return Promise.resolve(t(`${r}/${e}`)).then(function(e){return Promise.resolve(e.json())})})}catch(e){return Promise.reject(e)}}(e)})},function(e){const r=e;throw d.default.error("Error decoding AppData:",r),new l("Error decoding AppData: "+r.message)}))}catch(e){return Promise.reject(e)}}cidToAppDataHex(e){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:r}){const{digest:t}=r.parse(e).multihash;return`0x${Buffer.from(t).toString("hex")}`})}catch(e){return Promise.reject(e)}}appDataHexToCid(e){try{return Promise.resolve(re(e)).then(function(e){if(!e)throw new l("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}calculateAppDataHash(e){try{const r=this;return Promise.resolve(r.validateAppDataDoc(e)).then(function(t){if(null==t||!t.success)throw new l("Invalid appData provided",null==t?void 0:t.errors);return te(function(){return Promise.resolve(function(e){try{const r=JSON.stringify(e);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("ipfs-only-hash"))})).then(function({of:e}){return e(r,{cidVersion:0})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(r.cidToAppDataHex(e)).then(function(r){if(!r)throw new l(`Could not extract appDataHash from calculated cidV0 ${e}`);return{cidV0:e,appDataHash:r}})})},function(e){throw new l("Failed to calculate appDataHash",e.message)})})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const r=this;return Promise.resolve(function(e,{writeUri:r="https://api.pinata.cloud",pinataApiKey:t="",pinataApiSecret:n=""}){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:o}){if(!t||!n)throw new l("You need to pass IPFS api credentials.");const s=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData"}});return Promise.resolve(o(`${r}/pinning/pinJSONToIPFS`,{method:"POST",body:s,headers:{"Content-Type":"application/json",pinata_api_key:t,pinata_secret_api_key:n}})).then(function(e){return Promise.resolve(e.json()).then(function(r){if(200!==e.status)throw new Error(r.error.details||r.error);return r})})})}catch(e){return Promise.reject(e)}}(e,r.context.ipfs)).then(function({IpfsHash:e}){return r.cidToAppDataHex(e)})}catch(e){return Promise.reject(e)}}}var oe=0;function se(e){return"__private_"+oe+++"_"+e}function ie(e,r){if(!Object.prototype.hasOwnProperty.call(e,r))throw new TypeError("attempted to use private field on non-instance");return e}const ae={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",env:"prod",ipfs:{readUri:"https://gnosis.mypinata.cloud/ipfs",writeUri:"https://api.pinata.cloud",pinataApiKey:"",pinataApiSecret:""}};var ce=/*#__PURE__*/se("chainId"),de=/*#__PURE__*/se("context");class ue{updateContext(e,r){this.setParams(r,e)}constructor(e,r){Object.defineProperty(this,ce,{writable:!0,value:exports.SupportedChainId.MAINNET}),Object.defineProperty(this,de,{writable:!0,value:ae}),this.setParams(e,r)}setParams(e,r){ie(this,ce)[ce]=this.updateChainId(e),ie(this,de)[de]={...ae,...r,ipfs:{...ae.ipfs,...r.ipfs}}}updateChainId(e){if(!exports.SupportedChainId[e])throw new l(`Invalid chainId: ${e}`);return d.default.debug("cow-sdk:",`Updating chainId to: ${e}`),ie(this,ce)[ce]=e,e}get chainId(){const e=this;var r;const t=null==(r=ie(this,de)[de].signer)?void 0:r.provider;return t?(d.default.debug("cow-sdk:","Getting chainId from provider"),function(){try{return Promise.resolve(t.getNetwork()).then(function(r){const t=r.chainId;return t!==ie(e,ce)[ce]&&(d.default.debug("cow-sdk:",`ChainId mismatch: Provider's chainId: ${t} vs Context's chainId: ${ie(e,ce)[ce]}. Updating Context's chainId`),e.updateChainId(t)),t})}catch(e){return Promise.reject(e)}}()):Promise.resolve(ie(this,ce)[ce])}get appDataHash(){var e;return null!==(e=ie(this,de)[de].appDataHash)&&void 0!==e?e:ae.appDataHash}get env(){return ie(this,de)[de].env||ae.env}get signer(){return ie(this,de)[de].signer}get ipfs(){var e;return null!==(e=ie(this,de)[de].ipfs)&&void 0!==e?e:ae.ipfs}}function le({quoteToken:e,baseToken:t,kind:n}){return n===r.OrderKind.SELL?{sellToken:t,buyToken:e}:{buyToken:t,sellToken:e}}class he extends l{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){var r,t;if(null!=(r=e.validationErrors)&&r.length)return(null==(t=e.validationErrors)?void 0:t[0].reason)||e.reason;if(null!=e&&e.reason)return d.default.error("0x-sdk:","Unknown validation reason for bad price request",e),e.reason;throw new Error('Error response body properties "reason" and "validationErrors" missing.')})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){const r=e instanceof Error;return d.default.error("0x-sdk:","Error handling a 4xx error. Likely a problem deserialising the JSON response.",r&&(null==e?void 0:e.message)),r?null==e?void 0:e.message:"Price fetch failed. This may be due to a server or network connectivity issue. Please try again later."}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:return Promise.resolve(r.getErrorMessage(e));case 404:return Promise.resolve("Not found");case 429:return Promise.resolve("Too many requests - Rate limit exceeded");case 500:return Promise.resolve("Internal server error");case 501:return Promise.resolve("Not Implemented");case 503:return Promise.resolve("Server Error - Too many open connections");default:return d.default.error("0x-sdk:","Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){var r;super(e.reason,e.code.toString()),this.name="ZeroXError",this.description=void 0,this.message=void 0,this.description=(null==(r=e.validationErrors)?void 0:r[0].reason)||e.reason,this.message=e.reason}}const pe=function(e,r){try{return e.ok?Promise.resolve(e.json()):Promise.resolve(e.clone().json()).then(function(t){function n(){if(r){const{quoteToken:e,baseToken:t}=r;d.default.error("0x-sdk:",`Error querying fee from API - quoteToken: ${e}, baseToken: ${t}`)}throw o}let o;const s=function(){if(null==t||!t.code||null==t||!t.reason)return Promise.resolve(he.getErrorFromStatusCode(e.clone())).then(function(r){o=new he({code:e.status,reason:r})});o=new he(t)}();return s&&s.then?s.then(n):n()})}catch(e){return Promise.reject(e)}};function fe(){return{[exports.SupportedChainId.MAINNET]:"https://api.0x.org/swap"}}function me({excludedSources:e,affiliateAddress:r}){return h({excludedSources:Pe({excludedSources:e}),affiliateAddress:r})}function ve({affiliateAddressMap:e,chainId:r}){const t=e[r];if(!t)throw new l(`Invalid affiliate address! Parameters passed: ${JSON.stringify({affiliateAddressMap:e,chainId:r},null,2)}`);return t}function Pe({excludedSources:e}){return e.length>0?e.join(","):""}const ge=[];class Ee extends q{constructor(e,r){super({context:new ue(e,{}),name:"0x",apiVersion:"v1",getApiUrl:fe}),this.ZEROX_OPTIONS=void 0,this.ZEROX_OPTIONS_URL=void 0;const t=(null==r?void 0:r.affiliateAddressMap)||m,n=(null==r?void 0:r.excludedSources)||ge,o=ve({affiliateAddressMap:t,chainId:e});this.ZEROX_OPTIONS={affiliateAddressMap:t,excludedSources:n},this.ZEROX_OPTIONS_URL=me({excludedSources:n,affiliateAddress:o})}getQuote(e,t={}){try{const n=this;function o(t){const o=function(e){return e===exports.SupportedChainId.MAINNET?e:null}(t);if(null==o)return d.default.debug("0x-sdk:","Network not supported"),null;d.default.debug("0x-sdk:",`Get price from ${n.API_NAME}`,e,n.ZEROX_OPTIONS);const{sellToken:u,buyToken:p}=le({baseToken:V(i,t),quoteToken:V(a,t),kind:c}),f=ve({affiliateAddressMap:n.ZEROX_OPTIONS.affiliateAddressMap,chainId:t});return Promise.resolve(n.get(`/price${h({sellToken:u,buyToken:p,[c===r.OrderKind.BUY?"buyAmount":"sellAmount"]:s,affiliateAddress:f,excludedSources:Pe(n.ZEROX_OPTIONS)})}`,{chainId:t,env:l}).catch(e=>{throw d.default.error(`Error getting ${n.API_NAME} price quote:`,e),new Error(e)})).then(pe)}const{amount:s,baseToken:i,quoteToken:a,kind:c}=e,{chainId:u,env:l=n.context.env}=t;return Promise.resolve(u?o(u):Promise.resolve(n.context.chainId).then(o))}catch(p){return Promise.reject(p)}}updateOptions({affiliateAddressMap:e,excludedSources:r}){try{const t=this;return Promise.resolve(t.context.chainId).then(function(n){e&&(d.default.debug("0x-sdk:","Updating 0x options affiliate address to",e),t.ZEROX_OPTIONS.affiliateAddressMap=e),r&&(d.default.debug("0x-sdk:","Updating 0x options excludedSources to",r),t.ZEROX_OPTIONS.excludedSources=r);const o=ve({affiliateAddressMap:t.ZEROX_OPTIONS.affiliateAddressMap,chainId:n});t.ZEROX_OPTIONS_URL=me({...t.ZEROX_OPTIONS,affiliateAddress:o})})}catch(e){return Promise.reject(e)}}}const Te="https://apiv5.paraswap.io",we={maxImpact:100,excludeDEXS:"ParaSwapPool4"},ye=new Map([[1,new s.ParaSwap(1,Te)],[3,new s.ParaSwap(3,Te)],[56,new s.ParaSwap(56,Te)],[137,new s.ParaSwap(137,Te)],[250,new s.ParaSwap(250,Te)],[42161,new s.ParaSwap(42161,Te)],[43114,new s.ParaSwap(43114,Te)]]),Ae=p.filter(e=>ye.has(e));class be extends l{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var n=Promise.resolve(e.json()).then(function(e){var r,t;if(null!=(r=e.data)&&r.error||e.message)return(null==(t=e.data)?void 0:t.error)||e.message;throw new Error('Error response body properties "data.error" and "message" missing.')})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){const r=e instanceof Error;return d.default.error("ParaswapApi","Error handling a 4xx error. Likely a problem deserialising the JSON response.",r&&(null==e?void 0:e.message)),r?null==e?void 0:e.message:"Price fetch failed. This may be due to a server or network connectivity issue. Please try again later."}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:return Promise.resolve(r.getErrorMessage(e));case 404:return Promise.resolve("Not found");default:return d.default.error("ParaswapApi","Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){var r,t;super(e.message,null==(r=e.status)?void 0:r.toString()),this.name="ParaswapError",this.description=void 0,this.message=void 0,this.description=(null==(t=e.data)?void 0:t.error)||e.message,this.message=e.message}}function Ie(e){return e===exports.SupportedChainId.MAINNET?e:null}function Se(e){if(function(e){return!(null==e||!e.destAmount)}(e))return e;{const t="ESTIMATED_LOSS_GREATER_THAN_MAX_IMPACT"===(null==(r=e)?void 0:r.message)&&r.data&&r.data.priceRoute?r.data.priceRoute:null;if(t)return t;throw new be(e)}var r}var ke,Oe,xe,De,Ne,_e,Ce,Re,Ue,Le,je,He,Me,Ve,Fe,qe,Be,$e,Ge,Qe=/*#__PURE__*/se("libMap"),Xe=/*#__PURE__*/se("apiUrl"),Ze=/*#__PURE__*/se("rateOptions"),Je=/*#__PURE__*/se("getLib");class We{constructor(e={}){Object.defineProperty(this,Je,{value:Ke}),this.name=void 0,Object.defineProperty(this,Qe,{writable:!0,value:ye}),Object.defineProperty(this,Xe,{writable:!0,value:void 0}),Object.defineProperty(this,Ze,{writable:!0,value:void 0}),this.name="Paraswap",ie(this,Xe)[Xe]=Te,ie(this,Ze)[Ze]={...we,...e}}getQuote(t,n={allowParaswapNetworks:!1}){try{const o=this,{chainId:i}=t,{baseToken:a,quoteToken:c,fromDecimals:d,toDecimals:u,amount:h,kind:p,userAddress:f}=function(e,r){const{baseToken:t,quoteToken:n,userAddress:o}=r,s=V(t,e),i=V(n,e);return{...r,baseToken:s,quoteToken:i,userAddress:null!=o?o:void 0}}(t.chainId,t),m=!(null!=n&&n.allowParaswapNetworks),v=!!Ie(i);if(m&&!v)throw new l("ParaswapApi isn't compatible with chainId "+i);const P=ie(o,Je)[Je](i);if(!P)throw new l("ParaswapApi isn't compatible with chainId "+i);const{sellToken:g,buyToken:E}=le({baseToken:a,quoteToken:c,kind:p}),T=p===r.OrderKind.BUY?s.SwapSide.BUY:s.SwapSide.SELL,w={...ie(o,Ze)[Ze],...null==n?void 0:n.rateOptions};return null!=n&&n.allowParaswapNetworks||Ie(i)?(e.debug("ParaswapApi","Getting price quote",t),Promise.resolve(P.getRate(g,E,h,f,T,w,d,u)).then(Se)):(e.error("ParaswapApi",`Chain id ${i} is not currently supported by the CoW contracts - please use: ${Ae.join(",")}. If you want to query all other ParaSwap specific chain ids, please pass { allowParaswapNetworks: true } as the query's "options" parameter.`),Promise.resolve(null))}catch(e){return Promise.reject(e)}}getQuoteCowNetworks(e,r){try{return Promise.resolve(this.getQuote(e,{...r,allowParaswapNetworks:!1}))}catch(e){return Promise.reject(e)}}getQuoteAllNetworks(e,r){try{return Promise.resolve(this.getQuote(e,{...r,allowParaswapNetworks:!0}))}catch(e){return Promise.reject(e)}}updateOptions(e){try{const r=this;return ie(r,Ze)[Ze]=null===e.rateOptions?{}:{...ie(r,Ze)[Ze],...e.rateOptions||{}},e.apiUrl&&(ie(r,Xe)[Xe]=e.apiUrl),Promise.resolve()}catch(e){return Promise.reject(e)}}get rateOptions(){return ie(this,Ze)[Ze]}get apiUrl(){return ie(this,Xe)[Xe]}}function Ke(e){var r;return null!==(r=ie(this,Qe)[Qe].get(e))&&void 0!==r?r:null}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(ke||(ke={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Oe||(Oe={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(xe||(xe={})),function(e){e.Asc="asc",e.Desc="desc"}(De||(De={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsSigned="isSigned",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(Ne||(Ne={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(_e||(_e={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Ce||(Ce={})),function(e){e.Id="id",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Re||(Re={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(Ue||(Ue={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Le||(Le={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(je||(je={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(He||(He={})),function(e){e.Address="address",e.DailyTotals="dailyTotals",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.HourlyTotals="hourlyTotals",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Me||(Me={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ve||(Ve={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(Fe||(Fe={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(qe||(qe={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.Id="id",e.Name="name",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol"}(Be||(Be={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}($e||($e={})),function(e){e.Allow="allow",e.Deny="deny"}(Ge||(Ge={}));var ze={__proto__:null,get Bundle_OrderBy(){return ke},get DailyTotal_OrderBy(){return Oe},get HourlyTotal_OrderBy(){return xe},get OrderDirection(){return De},get Order_OrderBy(){return Ne},get PairDaily_OrderBy(){return _e},get PairHourly_OrderBy(){return Ce},get Pair_OrderBy(){return Re},get Settlement_OrderBy(){return Ue},get TokenDailyTotal_OrderBy(){return Le},get TokenHourlyTotal_OrderBy(){return je},get TokenTradingEvent_OrderBy(){return He},get Token_OrderBy(){return Me},get Total_OrderBy(){return Ve},get Trade_OrderBy(){return Fe},get UniswapPool_OrderBy(){return qe},get UniswapToken_OrderBy(){return Be},get User_OrderBy(){return $e},get _SubgraphErrorPolicy_(){return Ge}};Object.defineProperty(exports,"OrderKind",{enumerable:!0,get:function(){return r.OrderKind}}),exports.ALL_SUPPORTED_CHAIN_IDS=p,exports.COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS=m,exports.CowError=l,exports.CowSdk=class{constructor(e=exports.SupportedChainId.MAINNET,r={},t={}){var n,o,s,i;const a=this;this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.zeroXApi=void 0,this.paraswapApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.updateContext=function(e,r){try{return Promise.resolve(a.context.chainId).then(function(t){a.context.updateContext(e,r||t)})}catch(e){return Promise.reject(e)}};const c=null!==(n=null==t||null==(o=t.zeroXOptions)?void 0:o.enabled)&&void 0!==n&&n,u=null!==(s=null==t||null==(i=t.paraswapOptions)?void 0:i.enabled)&&void 0!==s&&s;this.context=new ue(e,{...r}),this.cowApi=new W(this.context),this.cowSubgraphApi=new ee(this.context),this.metadataApi=new ne(this.context),this.zeroXApi=c?new Ee(e,t.zeroXOptions):void 0,this.paraswapApi=u?new We(t.paraswapOptions):void 0,d.default.setLevel(t.loglevel||"ERROR")}signOrder(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(n){return function(e,r,t){return v({order:e,chainId:r},g,t)}({...e,appData:r.context.appDataHash},n,t)})}catch(e){return Promise.reject(e)}}signOrderCancellation(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(r){return function(e,r,t){return v({orderId:e,chainId:r},P,t)}(e,r,t)})}catch(e){return Promise.reject(e)}}_checkSigner(e=this.context.signer){if(!e)throw new l("No signer available");return e}},exports.GraphQL=ze,exports.Token=j;
|
|
29
29
|
//# sourceMappingURL=index.js.map
|