ccxt 4.2.59 → 4.2.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/README.md +103 -102
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +11853 -3790
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +4 -1
  6. package/dist/cjs/src/abstract/hyperliquid.js +9 -0
  7. package/dist/cjs/src/ascendex.js +10 -12
  8. package/dist/cjs/src/base/Exchange.js +22 -1
  9. package/dist/cjs/src/base/functions/encode.js +5 -0
  10. package/dist/cjs/src/base/functions.js +1 -0
  11. package/dist/cjs/src/bingx.js +38 -0
  12. package/dist/cjs/src/bitfinex2.js +20 -3
  13. package/dist/cjs/src/bitget.js +9 -2
  14. package/dist/cjs/src/bitmart.js +41 -23
  15. package/dist/cjs/src/blofin.js +59 -1
  16. package/dist/cjs/src/coinbase.js +108 -103
  17. package/dist/cjs/src/coinex.js +61 -1
  18. package/dist/cjs/src/hitbtc.js +1 -1
  19. package/dist/cjs/src/htx.js +4 -1
  20. package/dist/cjs/src/hyperliquid.js +2035 -0
  21. package/dist/cjs/src/kraken.js +50 -41
  22. package/dist/cjs/src/krakenfutures.js +28 -0
  23. package/dist/cjs/src/kucoinfutures.js +3 -2
  24. package/dist/cjs/src/okx.js +1 -1
  25. package/dist/cjs/src/phemex.js +2 -2
  26. package/dist/cjs/src/pro/binance.js +16 -3
  27. package/dist/cjs/src/pro/bingx.js +1 -0
  28. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
  29. package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
  30. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
  31. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
  32. package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
  33. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
  34. package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
  35. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
  36. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
  37. package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
  38. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
  39. package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
  40. package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
  41. package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
  42. package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
  43. package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
  44. package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
  45. package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
  46. package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
  47. package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
  48. package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
  49. package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
  50. package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
  51. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
  52. package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
  53. package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
  54. package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
  55. package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
  56. package/dist/cjs/src/tokocrypto.js +22 -2
  57. package/dist/cjs/src/wazirx.js +314 -4
  58. package/dist/cjs/src/woo.js +157 -77
  59. package/js/ccxt.d.ts +5 -2
  60. package/js/ccxt.js +4 -2
  61. package/js/src/abstract/blofin.d.ts +1 -0
  62. package/js/src/abstract/coinbase.d.ts +3 -3
  63. package/js/src/abstract/hyperliquid.d.ts +9 -0
  64. package/js/src/abstract/hyperliquid.js +11 -0
  65. package/js/src/abstract/wazirx.d.ts +5 -0
  66. package/js/src/ascendex.d.ts +2 -2
  67. package/js/src/ascendex.js +10 -12
  68. package/js/src/base/Exchange.d.ts +4 -0
  69. package/js/src/base/Exchange.js +13 -1
  70. package/js/src/base/functions/encode.d.ts +2 -1
  71. package/js/src/base/functions/encode.js +5 -1
  72. package/js/src/bingx.d.ts +3 -1
  73. package/js/src/bingx.js +38 -0
  74. package/js/src/bitfinex2.js +20 -3
  75. package/js/src/bitget.js +9 -2
  76. package/js/src/bitmart.d.ts +9 -2
  77. package/js/src/bitmart.js +41 -23
  78. package/js/src/blofin.d.ts +2 -1
  79. package/js/src/blofin.js +59 -1
  80. package/js/src/coinbase.js +108 -103
  81. package/js/src/coinex.d.ts +3 -1
  82. package/js/src/coinex.js +61 -1
  83. package/js/src/hitbtc.js +1 -1
  84. package/js/src/htx.js +4 -1
  85. package/js/src/hyperliquid.d.ts +83 -0
  86. package/js/src/hyperliquid.js +2036 -0
  87. package/js/src/kraken.js +50 -41
  88. package/js/src/krakenfutures.d.ts +2 -1
  89. package/js/src/krakenfutures.js +28 -0
  90. package/js/src/kucoinfutures.js +3 -2
  91. package/js/src/okx.js +1 -1
  92. package/js/src/phemex.js +2 -2
  93. package/js/src/pro/binance.js +16 -3
  94. package/js/src/pro/bingx.js +1 -0
  95. package/js/src/pro/deribit.d.ts +1 -1
  96. package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
  97. package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
  98. package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
  99. package/js/src/static_dependencies/ethers/address/address.js +162 -0
  100. package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
  101. package/js/src/static_dependencies/ethers/address/checks.js +119 -0
  102. package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
  103. package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
  104. package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
  105. package/js/src/static_dependencies/ethers/address/index.js +24 -0
  106. package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
  107. package/js/src/static_dependencies/ethers/bytes32.js +45 -0
  108. package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
  109. package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
  110. package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
  111. package/js/src/static_dependencies/ethers/coders/address.js +34 -0
  112. package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
  113. package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
  114. package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
  115. package/js/src/static_dependencies/ethers/coders/array.js +162 -0
  116. package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
  117. package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
  118. package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
  119. package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
  120. package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
  121. package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
  122. package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
  123. package/js/src/static_dependencies/ethers/coders/null.js +29 -0
  124. package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
  125. package/js/src/static_dependencies/ethers/coders/number.js +48 -0
  126. package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
  127. package/js/src/static_dependencies/ethers/coders/string.js +26 -0
  128. package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
  129. package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
  130. package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
  131. package/js/src/static_dependencies/ethers/fragments.js +1252 -0
  132. package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
  133. package/js/src/static_dependencies/ethers/hash/index.js +15 -0
  134. package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
  135. package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
  136. package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
  137. package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
  138. package/js/src/static_dependencies/ethers/index.d.ts +19 -0
  139. package/js/src/static_dependencies/ethers/index.js +22 -0
  140. package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
  141. package/js/src/static_dependencies/ethers/interface.js +990 -0
  142. package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
  143. package/js/src/static_dependencies/ethers/typed.js +608 -0
  144. package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
  145. package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
  146. package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
  147. package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
  148. package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
  149. package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
  150. package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
  151. package/js/src/static_dependencies/ethers/utils/data.js +175 -0
  152. package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
  153. package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
  154. package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
  155. package/js/src/static_dependencies/ethers/utils/events.js +52 -0
  156. package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
  157. package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
  158. package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
  159. package/js/src/static_dependencies/ethers/utils/index.js +38 -0
  160. package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
  161. package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
  162. package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
  163. package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
  164. package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
  165. package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
  166. package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
  167. package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
  168. package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
  169. package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
  170. package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
  171. package/js/src/static_dependencies/ethers/utils/units.js +88 -0
  172. package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
  173. package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
  174. package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
  175. package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
  176. package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
  177. package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
  178. package/js/src/tokocrypto.js +22 -2
  179. package/js/src/wazirx.d.ts +12 -1
  180. package/js/src/wazirx.js +314 -4
  181. package/js/src/woo.d.ts +8 -0
  182. package/js/src/woo.js +157 -77
  183. package/package.json +1 -1
  184. package/skip-tests.json +60 -16
@@ -0,0 +1,614 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('./utils/base58.js');
6
+ var errors = require('./utils/errors.js');
7
+ require('./utils/events.js');
8
+ require('./utils/fixednumber.js');
9
+ var maths = require('./utils/maths.js');
10
+ var properties = require('./utils/properties.js');
11
+ require('./utils/utf8.js');
12
+ require('../../base/functions/platform.js');
13
+ require('../../base/functions/encode.js');
14
+ require('../../base/functions/crypto.js');
15
+ require('../noble-hashes/sha3.js');
16
+ require('../noble-hashes/sha256.js');
17
+
18
+ /**
19
+ * A fragment is a single item from an ABI, which may represent any of:
20
+ *
21
+ * - [Functions](FunctionFragment)
22
+ * - [Events](EventFragment)
23
+ * - [Constructors](ConstructorFragment)
24
+ * - Custom [Errors](ErrorFragment)
25
+ * - [Fallback or Receive](FallbackFragment) functions
26
+ *
27
+ * @_subsection api/abi/abi-coder:Fragments [about-fragments]
28
+ */
29
+ var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
30
+ if (kind === "m") throw new TypeError("Private method is not writable");
31
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
32
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
33
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
34
+ };
35
+ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
36
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
37
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
38
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
39
+ };
40
+ var _TokenString_instances, _TokenString_offset, _TokenString_tokens, _TokenString_subTokenString, _ParamType_instances, _ParamType_walkAsync;
41
+ // [ "a", "b" ] => { "a": 1, "b": 1 }
42
+ function setify(items) {
43
+ const result = new Set();
44
+ items.forEach((k) => result.add(k));
45
+ return Object.freeze(result);
46
+ }
47
+ const _kwVisibDeploy = "external public payable";
48
+ setify(_kwVisibDeploy.split(" "));
49
+ // Visibility Keywords
50
+ const _kwVisib = "constant external internal payable private public pure view";
51
+ setify(_kwVisib.split(" "));
52
+ const _kwTypes = "constructor error event fallback function receive struct";
53
+ setify(_kwTypes.split(" "));
54
+ const _kwModifiers = "calldata memory storage payable indexed";
55
+ const KwModifiers = setify(_kwModifiers.split(" "));
56
+ const _kwOther = "tuple returns";
57
+ // All Keywords
58
+ const _keywords = [_kwTypes, _kwModifiers, _kwOther, _kwVisib].join(" ");
59
+ const Keywords = setify(_keywords.split(" "));
60
+ // Single character tokens
61
+ const SimpleTokens = {
62
+ "(": "OPEN_PAREN", ")": "CLOSE_PAREN",
63
+ "[": "OPEN_BRACKET", "]": "CLOSE_BRACKET",
64
+ ",": "COMMA", "@": "AT"
65
+ };
66
+ // Parser regexes to consume the next token
67
+ const regexWhitespacePrefix = new RegExp("^(\\s*)");
68
+ const regexNumberPrefix = new RegExp("^([0-9]+)");
69
+ const regexIdPrefix = new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)");
70
+ // Parser regexs to check validity
71
+ const regexId = new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$");
72
+ const regexType = new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$");
73
+ class TokenString {
74
+ constructor(tokens) {
75
+ _TokenString_instances.add(this);
76
+ _TokenString_offset.set(this, void 0);
77
+ _TokenString_tokens.set(this, void 0);
78
+ __classPrivateFieldSet(this, _TokenString_offset, 0, "f");
79
+ __classPrivateFieldSet(this, _TokenString_tokens, tokens.slice(), "f");
80
+ }
81
+ get offset() { return __classPrivateFieldGet(this, _TokenString_offset, "f"); }
82
+ get length() { return __classPrivateFieldGet(this, _TokenString_tokens, "f").length - __classPrivateFieldGet(this, _TokenString_offset, "f"); }
83
+ clone() { return new TokenString(__classPrivateFieldGet(this, _TokenString_tokens, "f")); }
84
+ reset() { __classPrivateFieldSet(this, _TokenString_offset, 0, "f"); }
85
+ // Pops and returns the value of the next token, if it is a keyword in allowed; throws if out of tokens
86
+ popKeyword(allowed) {
87
+ const top = this.peek();
88
+ if (top.type !== "KEYWORD" || !allowed.has(top.text)) {
89
+ throw new Error(`expected keyword ${top.text}`);
90
+ }
91
+ return this.pop().text;
92
+ }
93
+ // Pops and returns the value of the next token if it is `type`; throws if out of tokens
94
+ popType(type) {
95
+ if (this.peek().type !== type) {
96
+ throw new Error(`expected ${type}; got ${JSON.stringify(this.peek())}`);
97
+ }
98
+ return this.pop().text;
99
+ }
100
+ // Pops and returns a "(" TOKENS ")"
101
+ popParen() {
102
+ const top = this.peek();
103
+ if (top.type !== "OPEN_PAREN") {
104
+ throw new Error("bad start");
105
+ }
106
+ const result = __classPrivateFieldGet(this, _TokenString_instances, "m", _TokenString_subTokenString).call(this, __classPrivateFieldGet(this, _TokenString_offset, "f") + 1, top.match + 1);
107
+ __classPrivateFieldSet(this, _TokenString_offset, top.match + 1, "f");
108
+ return result;
109
+ }
110
+ // Pops and returns the items within "(" ITEM1 "," ITEM2 "," ... ")"
111
+ popParams() {
112
+ const top = this.peek();
113
+ if (top.type !== "OPEN_PAREN") {
114
+ throw new Error("bad start");
115
+ }
116
+ const result = [];
117
+ while (__classPrivateFieldGet(this, _TokenString_offset, "f") < top.match - 1) {
118
+ const link = this.peek().linkNext;
119
+ result.push(__classPrivateFieldGet(this, _TokenString_instances, "m", _TokenString_subTokenString).call(this, __classPrivateFieldGet(this, _TokenString_offset, "f") + 1, link));
120
+ __classPrivateFieldSet(this, _TokenString_offset, link, "f");
121
+ }
122
+ __classPrivateFieldSet(this, _TokenString_offset, top.match + 1, "f");
123
+ return result;
124
+ }
125
+ // Returns the top Token, throwing if out of tokens
126
+ peek() {
127
+ if (__classPrivateFieldGet(this, _TokenString_offset, "f") >= __classPrivateFieldGet(this, _TokenString_tokens, "f").length) {
128
+ throw new Error("out-of-bounds");
129
+ }
130
+ return __classPrivateFieldGet(this, _TokenString_tokens, "f")[__classPrivateFieldGet(this, _TokenString_offset, "f")];
131
+ }
132
+ // Returns the next value, if it is a keyword in `allowed`
133
+ peekKeyword(allowed) {
134
+ const top = this.peekType("KEYWORD");
135
+ return (top != null && allowed.has(top)) ? top : null;
136
+ }
137
+ // Returns the value of the next token if it is `type`
138
+ peekType(type) {
139
+ if (this.length === 0) {
140
+ return null;
141
+ }
142
+ const top = this.peek();
143
+ return (top.type === type) ? top.text : null;
144
+ }
145
+ // Returns the next token; throws if out of tokens
146
+ pop() {
147
+ var _a;
148
+ const result = this.peek();
149
+ __classPrivateFieldSet(this, _TokenString_offset, (_a = __classPrivateFieldGet(this, _TokenString_offset, "f"), _a++, _a), "f");
150
+ return result;
151
+ }
152
+ toString() {
153
+ const tokens = [];
154
+ for (let i = __classPrivateFieldGet(this, _TokenString_offset, "f"); i < __classPrivateFieldGet(this, _TokenString_tokens, "f").length; i++) {
155
+ const token = __classPrivateFieldGet(this, _TokenString_tokens, "f")[i];
156
+ tokens.push(`${token.type}:${token.text}`);
157
+ }
158
+ return `<TokenString ${tokens.join(" ")}>`;
159
+ }
160
+ }
161
+ _TokenString_offset = new WeakMap(), _TokenString_tokens = new WeakMap(), _TokenString_instances = new WeakSet(), _TokenString_subTokenString = function _TokenString_subTokenString(from = 0, to = 0) {
162
+ return new TokenString(__classPrivateFieldGet(this, _TokenString_tokens, "f").slice(from, to).map((t) => {
163
+ return Object.freeze(Object.assign({}, t, {
164
+ match: (t.match - from),
165
+ linkBack: (t.linkBack - from),
166
+ linkNext: (t.linkNext - from),
167
+ }));
168
+ }));
169
+ };
170
+ function lex(text) {
171
+ const tokens = [];
172
+ const throwError = (message) => {
173
+ const token = (offset < text.length) ? JSON.stringify(text[offset]) : "$EOI";
174
+ throw new Error(`invalid token ${token} at ${offset}: ${message}`);
175
+ };
176
+ let brackets = [];
177
+ let commas = [];
178
+ let offset = 0;
179
+ while (offset < text.length) {
180
+ // Strip off any leading whitespace
181
+ let cur = text.substring(offset);
182
+ let match = cur.match(regexWhitespacePrefix);
183
+ if (match) {
184
+ offset += match[1].length;
185
+ cur = text.substring(offset);
186
+ }
187
+ const token = { depth: brackets.length, linkBack: -1, linkNext: -1, match: -1, type: "", text: "", offset, value: -1 };
188
+ tokens.push(token);
189
+ let type = (SimpleTokens[cur[0]] || "");
190
+ if (type) {
191
+ token.type = type;
192
+ token.text = cur[0];
193
+ offset++;
194
+ if (type === "OPEN_PAREN") {
195
+ brackets.push(tokens.length - 1);
196
+ commas.push(tokens.length - 1);
197
+ }
198
+ else if (type == "CLOSE_PAREN") {
199
+ if (brackets.length === 0) {
200
+ throwError("no matching open bracket");
201
+ }
202
+ token.match = brackets.pop();
203
+ (tokens[token.match]).match = tokens.length - 1;
204
+ token.depth--;
205
+ token.linkBack = commas.pop();
206
+ (tokens[token.linkBack]).linkNext = tokens.length - 1;
207
+ }
208
+ else if (type === "COMMA") {
209
+ token.linkBack = commas.pop();
210
+ (tokens[token.linkBack]).linkNext = tokens.length - 1;
211
+ commas.push(tokens.length - 1);
212
+ }
213
+ else if (type === "OPEN_BRACKET") {
214
+ token.type = "BRACKET";
215
+ }
216
+ else if (type === "CLOSE_BRACKET") {
217
+ // Remove the CLOSE_BRACKET
218
+ let suffix = tokens.pop().text;
219
+ if (tokens.length > 0 && tokens[tokens.length - 1].type === "NUMBER") {
220
+ const value = tokens.pop().text;
221
+ suffix = value + suffix;
222
+ (tokens[tokens.length - 1]).value = maths.getNumber(value);
223
+ }
224
+ if (tokens.length === 0 || tokens[tokens.length - 1].type !== "BRACKET") {
225
+ throw new Error("missing opening bracket");
226
+ }
227
+ (tokens[tokens.length - 1]).text += suffix;
228
+ }
229
+ continue;
230
+ }
231
+ match = cur.match(regexIdPrefix);
232
+ if (match) {
233
+ token.text = match[1];
234
+ offset += token.text.length;
235
+ if (Keywords.has(token.text)) {
236
+ token.type = "KEYWORD";
237
+ continue;
238
+ }
239
+ if (token.text.match(regexType)) {
240
+ token.type = "TYPE";
241
+ continue;
242
+ }
243
+ token.type = "ID";
244
+ continue;
245
+ }
246
+ match = cur.match(regexNumberPrefix);
247
+ if (match) {
248
+ token.text = match[1];
249
+ token.type = "NUMBER";
250
+ offset += token.text.length;
251
+ continue;
252
+ }
253
+ throw new Error(`unexpected token ${JSON.stringify(cur[0])} at position ${offset}`);
254
+ }
255
+ return new TokenString(tokens.map((t) => Object.freeze(t)));
256
+ }
257
+ // ...all keywords matching allowed, returning the keywords
258
+ function consumeKeywords(tokens, allowed) {
259
+ const keywords = new Set();
260
+ while (true) {
261
+ const keyword = tokens.peekType("KEYWORD");
262
+ if (keyword == null || (allowed && !allowed.has(keyword))) {
263
+ break;
264
+ }
265
+ tokens.pop();
266
+ if (keywords.has(keyword)) {
267
+ throw new Error(`duplicate keywords: ${JSON.stringify(keyword)}`);
268
+ }
269
+ keywords.add(keyword);
270
+ }
271
+ return Object.freeze(keywords);
272
+ }
273
+ const regexArrayType = new RegExp(/^(.*)\[([0-9]*)\]$/);
274
+ function verifyBasicType(type) {
275
+ const match = type.match(regexType);
276
+ errors.assertArgument(match, "invalid type", "type", type);
277
+ if (type === "uint") {
278
+ return "uint256";
279
+ }
280
+ if (type === "int") {
281
+ return "int256";
282
+ }
283
+ if (match[2]) {
284
+ // bytesXX
285
+ const length = parseInt(match[2]);
286
+ errors.assertArgument(length !== 0 && length <= 32, "invalid bytes length", "type", type);
287
+ }
288
+ else if (match[3]) {
289
+ // intXX or uintXX
290
+ const size = parseInt(match[3]);
291
+ errors.assertArgument(size !== 0 && size <= 256 && (size % 8) === 0, "invalid numeric width", "type", type);
292
+ }
293
+ return type;
294
+ }
295
+ // Make the Fragment constructors effectively private
296
+ const _guard = {};
297
+ const internal = Symbol.for("_ethers_internal");
298
+ const ParamTypeInternal = "_ParamTypeInternal";
299
+ /**
300
+ * Each input and output of a [[Fragment]] is an Array of **ParamType**.
301
+ */
302
+ class ParamType {
303
+ /**
304
+ * @private
305
+ */
306
+ constructor(guard, name, type, baseType, indexed, components, arrayLength, arrayChildren) {
307
+ _ParamType_instances.add(this);
308
+ errors.assertPrivate(guard, _guard, "ParamType");
309
+ Object.defineProperty(this, internal, { value: ParamTypeInternal });
310
+ if (components) {
311
+ components = Object.freeze(components.slice());
312
+ }
313
+ if (baseType === "array") {
314
+ if (arrayLength == null || arrayChildren == null) {
315
+ throw new Error("");
316
+ }
317
+ }
318
+ else if (arrayLength != null || arrayChildren != null) {
319
+ throw new Error("");
320
+ }
321
+ if (baseType === "tuple") {
322
+ if (components == null) {
323
+ throw new Error("");
324
+ }
325
+ }
326
+ else if (components != null) {
327
+ throw new Error("");
328
+ }
329
+ properties.defineProperties(this, {
330
+ name, type, baseType, indexed, components, arrayLength, arrayChildren
331
+ });
332
+ }
333
+ /**
334
+ * Return a string representation of this type.
335
+ *
336
+ * For example,
337
+ *
338
+ * ``sighash" => "(uint256,address)"``
339
+ *
340
+ * ``"minimal" => "tuple(uint256,address) indexed"``
341
+ *
342
+ * ``"full" => "tuple(uint256 foo, address bar) indexed baz"``
343
+ */
344
+ format(format) {
345
+ if (format == null) {
346
+ format = "sighash";
347
+ }
348
+ if (format === "json") {
349
+ const name = this.name || "";
350
+ if (this.isArray()) {
351
+ const result = JSON.parse(this.arrayChildren.format("json"));
352
+ result.name = name;
353
+ result.type += `[${(this.arrayLength < 0 ? "" : String(this.arrayLength))}]`;
354
+ return JSON.stringify(result);
355
+ }
356
+ const result = {
357
+ type: ((this.baseType === "tuple") ? "tuple" : this.type),
358
+ name
359
+ };
360
+ if (typeof (this.indexed) === "boolean") {
361
+ result.indexed = this.indexed;
362
+ }
363
+ if (this.isTuple()) {
364
+ result.components = this.components.map((c) => JSON.parse(c.format(format)));
365
+ }
366
+ return JSON.stringify(result);
367
+ }
368
+ let result = "";
369
+ // Array
370
+ if (this.isArray()) {
371
+ result += this.arrayChildren.format(format);
372
+ result += `[${(this.arrayLength < 0 ? "" : String(this.arrayLength))}]`;
373
+ }
374
+ else {
375
+ if (this.isTuple()) {
376
+ result += "(" + this.components.map((comp) => comp.format(format)).join((format === "full") ? ", " : ",") + ")";
377
+ }
378
+ else {
379
+ result += this.type;
380
+ }
381
+ }
382
+ if (format !== "sighash") {
383
+ if (this.indexed === true) {
384
+ result += " indexed";
385
+ }
386
+ if (format === "full" && this.name) {
387
+ result += " " + this.name;
388
+ }
389
+ }
390
+ return result;
391
+ }
392
+ /**
393
+ * Returns true if %%this%% is an Array type.
394
+ *
395
+ * This provides a type gaurd ensuring that [[arrayChildren]]
396
+ * and [[arrayLength]] are non-null.
397
+ */
398
+ isArray() {
399
+ return (this.baseType === "array");
400
+ }
401
+ /**
402
+ * Returns true if %%this%% is a Tuple type.
403
+ *
404
+ * This provides a type gaurd ensuring that [[components]]
405
+ * is non-null.
406
+ */
407
+ isTuple() {
408
+ return (this.baseType === "tuple");
409
+ }
410
+ /**
411
+ * Returns true if %%this%% is an Indexable type.
412
+ *
413
+ * This provides a type gaurd ensuring that [[indexed]]
414
+ * is non-null.
415
+ */
416
+ isIndexable() {
417
+ return (this.indexed != null);
418
+ }
419
+ /**
420
+ * Walks the **ParamType** with %%value%%, calling %%process%%
421
+ * on each type, destructing the %%value%% recursively.
422
+ */
423
+ walk(value, process) {
424
+ if (this.isArray()) {
425
+ if (!Array.isArray(value)) {
426
+ throw new Error("invalid array value");
427
+ }
428
+ if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
429
+ throw new Error("array is wrong length");
430
+ }
431
+ const _this = this;
432
+ return value.map((v) => (_this.arrayChildren.walk(v, process)));
433
+ }
434
+ if (this.isTuple()) {
435
+ if (!Array.isArray(value)) {
436
+ throw new Error("invalid tuple value");
437
+ }
438
+ if (value.length !== this.components.length) {
439
+ throw new Error("array is wrong length");
440
+ }
441
+ const _this = this;
442
+ return value.map((v, i) => (_this.components[i].walk(v, process)));
443
+ }
444
+ return process(this.type, value);
445
+ }
446
+ /**
447
+ * Walks the **ParamType** with %%value%%, asynchronously calling
448
+ * %%process%% on each type, destructing the %%value%% recursively.
449
+ *
450
+ * This can be used to resolve ENS naes by walking and resolving each
451
+ * ``"address"`` type.
452
+ */
453
+ async walkAsync(value, process) {
454
+ const promises = [];
455
+ const result = [value];
456
+ __classPrivateFieldGet(this, _ParamType_instances, "m", _ParamType_walkAsync).call(this, promises, value, process, (value) => {
457
+ result[0] = value;
458
+ });
459
+ if (promises.length) {
460
+ await Promise.all(promises);
461
+ }
462
+ return result[0];
463
+ }
464
+ /**
465
+ * Creates a new **ParamType** for %%obj%%.
466
+ *
467
+ * If %%allowIndexed%% then the ``indexed`` keyword is permitted,
468
+ * otherwise the ``indexed`` keyword will throw an error.
469
+ */
470
+ static from(obj, allowIndexed) {
471
+ if (ParamType.isParamType(obj)) {
472
+ return obj;
473
+ }
474
+ if (typeof (obj) === "string") {
475
+ try {
476
+ return ParamType.from(lex(obj), allowIndexed);
477
+ }
478
+ catch (error) {
479
+ errors.assertArgument(false, "invalid param type", "obj", obj);
480
+ }
481
+ }
482
+ else if (obj instanceof TokenString) {
483
+ let type = "", baseType = "";
484
+ let comps = null;
485
+ if (consumeKeywords(obj, setify(["tuple"])).has("tuple") || obj.peekType("OPEN_PAREN")) {
486
+ // Tuple
487
+ baseType = "tuple";
488
+ comps = obj.popParams().map((t) => ParamType.from(t));
489
+ type = `tuple(${comps.map((c) => c.format()).join(",")})`;
490
+ }
491
+ else {
492
+ // Normal
493
+ type = verifyBasicType(obj.popType("TYPE"));
494
+ baseType = type;
495
+ }
496
+ // Check for Array
497
+ let arrayChildren = null;
498
+ let arrayLength = null;
499
+ while (obj.length && obj.peekType("BRACKET")) {
500
+ const bracket = obj.pop(); //arrays[i];
501
+ arrayChildren = new ParamType(_guard, "", type, baseType, null, comps, arrayLength, arrayChildren);
502
+ arrayLength = bracket.value;
503
+ type += bracket.text;
504
+ baseType = "array";
505
+ comps = null;
506
+ }
507
+ let indexed = null;
508
+ const keywords = consumeKeywords(obj, KwModifiers);
509
+ if (keywords.has("indexed")) {
510
+ if (!allowIndexed) {
511
+ throw new Error("");
512
+ }
513
+ indexed = true;
514
+ }
515
+ const name = (obj.peekType("ID") ? obj.pop().text : "");
516
+ if (obj.length) {
517
+ throw new Error("leftover tokens");
518
+ }
519
+ return new ParamType(_guard, name, type, baseType, indexed, comps, arrayLength, arrayChildren);
520
+ }
521
+ const name = obj.name;
522
+ errors.assertArgument(!name || (typeof (name) === "string" && name.match(regexId)), "invalid name", "obj.name", name);
523
+ let indexed = obj.indexed;
524
+ if (indexed != null) {
525
+ errors.assertArgument(allowIndexed, "parameter cannot be indexed", "obj.indexed", obj.indexed);
526
+ indexed = !!indexed;
527
+ }
528
+ let type = obj.type;
529
+ let arrayMatch = type.match(regexArrayType);
530
+ if (arrayMatch) {
531
+ const arrayLength = parseInt(arrayMatch[2] || "-1");
532
+ const arrayChildren = ParamType.from({
533
+ type: arrayMatch[1],
534
+ components: obj.components
535
+ });
536
+ return new ParamType(_guard, name || "", type, "array", indexed, null, arrayLength, arrayChildren);
537
+ }
538
+ if (type === "tuple" || type.startsWith("tuple(" /* fix: ) */) || type.startsWith("(" /* fix: ) */)) {
539
+ const comps = (obj.components != null) ? obj.components.map((c) => ParamType.from(c)) : null;
540
+ const tuple = new ParamType(_guard, name || "", type, "tuple", indexed, comps, null, null);
541
+ // @TODO: use lexer to validate and normalize type
542
+ return tuple;
543
+ }
544
+ type = verifyBasicType(obj.type);
545
+ return new ParamType(_guard, name || "", type, type, indexed, null, null, null);
546
+ }
547
+ /**
548
+ * Returns true if %%value%% is a **ParamType**.
549
+ */
550
+ static isParamType(value) {
551
+ return (value && value[internal] === ParamTypeInternal);
552
+ }
553
+ }
554
+ _ParamType_instances = new WeakSet(), _ParamType_walkAsync = function _ParamType_walkAsync(promises, value, process, setValue) {
555
+ if (this.isArray()) {
556
+ if (!Array.isArray(value)) {
557
+ throw new Error("invalid array value");
558
+ }
559
+ if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
560
+ throw new Error("array is wrong length");
561
+ }
562
+ const childType = this.arrayChildren;
563
+ const result = value.slice();
564
+ result.forEach((value, index) => {
565
+ __classPrivateFieldGet(childType, _ParamType_instances, "m", _ParamType_walkAsync).call(childType, promises, value, process, (value) => {
566
+ result[index] = value;
567
+ });
568
+ });
569
+ setValue(result);
570
+ return;
571
+ }
572
+ if (this.isTuple()) {
573
+ const components = this.components;
574
+ // Convert the object into an array
575
+ let result;
576
+ if (Array.isArray(value)) {
577
+ result = value.slice();
578
+ }
579
+ else {
580
+ if (value == null || typeof (value) !== "object") {
581
+ throw new Error("invalid tuple value");
582
+ }
583
+ result = components.map((param) => {
584
+ if (!param.name) {
585
+ throw new Error("cannot use object value with unnamed components");
586
+ }
587
+ if (!(param.name in value)) {
588
+ throw new Error(`missing value for component ${param.name}`);
589
+ }
590
+ return value[param.name];
591
+ });
592
+ }
593
+ if (result.length !== this.components.length) {
594
+ throw new Error("array is wrong length");
595
+ }
596
+ result.forEach((value, index) => {
597
+ var _a;
598
+ __classPrivateFieldGet((_a = components[index]), _ParamType_instances, "m", _ParamType_walkAsync).call(_a, promises, value, process, (value) => {
599
+ result[index] = value;
600
+ });
601
+ });
602
+ setValue(result);
603
+ return;
604
+ }
605
+ const result = process(this.type, value);
606
+ if (result.then) {
607
+ promises.push((async function () { setValue(await result); })());
608
+ }
609
+ else {
610
+ setValue(result);
611
+ }
612
+ };
613
+
614
+ exports.ParamType = ParamType;