ccxt 4.2.60 → 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 (158) hide show
  1. package/README.md +103 -102
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +107943 -100121
  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/base/Exchange.js +22 -1
  8. package/dist/cjs/src/base/functions/encode.js +5 -0
  9. package/dist/cjs/src/base/functions.js +1 -0
  10. package/dist/cjs/src/bitfinex2.js +1 -1
  11. package/dist/cjs/src/coinbase.js +108 -103
  12. package/dist/cjs/src/coinex.js +61 -1
  13. package/dist/cjs/src/hyperliquid.js +2035 -0
  14. package/dist/cjs/src/kraken.js +8 -2
  15. package/dist/cjs/src/krakenfutures.js +28 -0
  16. package/dist/cjs/src/kucoinfutures.js +2 -2
  17. package/dist/cjs/src/okx.js +1 -1
  18. package/dist/cjs/src/phemex.js +2 -2
  19. package/dist/cjs/src/pro/bingx.js +1 -0
  20. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
  21. package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
  22. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
  23. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
  24. package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
  25. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
  26. package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
  27. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
  28. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
  29. package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
  30. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
  31. package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
  32. package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
  33. package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
  34. package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
  35. package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
  36. package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
  37. package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
  38. package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
  39. package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
  40. package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
  41. package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
  42. package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
  43. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
  44. package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
  45. package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
  46. package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
  47. package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
  48. package/dist/cjs/src/tokocrypto.js +22 -2
  49. package/dist/cjs/src/wazirx.js +308 -3
  50. package/js/ccxt.d.ts +5 -2
  51. package/js/ccxt.js +4 -2
  52. package/js/src/abstract/coinbase.d.ts +3 -3
  53. package/js/src/abstract/hyperliquid.d.ts +9 -0
  54. package/js/src/abstract/hyperliquid.js +11 -0
  55. package/js/src/base/Exchange.d.ts +4 -0
  56. package/js/src/base/Exchange.js +13 -1
  57. package/js/src/base/functions/encode.d.ts +2 -1
  58. package/js/src/base/functions/encode.js +5 -1
  59. package/js/src/bitfinex2.js +1 -1
  60. package/js/src/coinbase.js +108 -103
  61. package/js/src/coinex.d.ts +3 -1
  62. package/js/src/coinex.js +61 -1
  63. package/js/src/hyperliquid.d.ts +83 -0
  64. package/js/src/hyperliquid.js +2036 -0
  65. package/js/src/kraken.js +8 -2
  66. package/js/src/krakenfutures.d.ts +2 -1
  67. package/js/src/krakenfutures.js +28 -0
  68. package/js/src/kucoinfutures.js +2 -2
  69. package/js/src/okx.js +1 -1
  70. package/js/src/phemex.js +2 -2
  71. package/js/src/pro/bingx.js +1 -0
  72. package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
  73. package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
  74. package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
  75. package/js/src/static_dependencies/ethers/address/address.js +162 -0
  76. package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
  77. package/js/src/static_dependencies/ethers/address/checks.js +119 -0
  78. package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
  79. package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
  80. package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
  81. package/js/src/static_dependencies/ethers/address/index.js +24 -0
  82. package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
  83. package/js/src/static_dependencies/ethers/bytes32.js +45 -0
  84. package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
  85. package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
  86. package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
  87. package/js/src/static_dependencies/ethers/coders/address.js +34 -0
  88. package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
  89. package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
  90. package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
  91. package/js/src/static_dependencies/ethers/coders/array.js +162 -0
  92. package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
  93. package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
  94. package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
  95. package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
  96. package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
  97. package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
  98. package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
  99. package/js/src/static_dependencies/ethers/coders/null.js +29 -0
  100. package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
  101. package/js/src/static_dependencies/ethers/coders/number.js +48 -0
  102. package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
  103. package/js/src/static_dependencies/ethers/coders/string.js +26 -0
  104. package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
  105. package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
  106. package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
  107. package/js/src/static_dependencies/ethers/fragments.js +1252 -0
  108. package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
  109. package/js/src/static_dependencies/ethers/hash/index.js +15 -0
  110. package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
  111. package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
  112. package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
  113. package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
  114. package/js/src/static_dependencies/ethers/index.d.ts +19 -0
  115. package/js/src/static_dependencies/ethers/index.js +22 -0
  116. package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
  117. package/js/src/static_dependencies/ethers/interface.js +990 -0
  118. package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
  119. package/js/src/static_dependencies/ethers/typed.js +608 -0
  120. package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
  121. package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
  122. package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
  123. package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
  124. package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
  125. package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
  126. package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
  127. package/js/src/static_dependencies/ethers/utils/data.js +175 -0
  128. package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
  129. package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
  130. package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
  131. package/js/src/static_dependencies/ethers/utils/events.js +52 -0
  132. package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
  133. package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
  134. package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
  135. package/js/src/static_dependencies/ethers/utils/index.js +38 -0
  136. package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
  137. package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
  138. package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
  139. package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
  140. package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
  141. package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
  142. package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
  143. package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
  144. package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
  145. package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
  146. package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
  147. package/js/src/static_dependencies/ethers/utils/units.js +88 -0
  148. package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
  149. package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
  150. package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
  151. package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
  152. package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
  153. package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
  154. package/js/src/tokocrypto.js +22 -2
  155. package/js/src/wazirx.d.ts +12 -1
  156. package/js/src/wazirx.js +308 -3
  157. package/package.json +1 -1
  158. package/skip-tests.json +18 -0
@@ -0,0 +1,1252 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ /**
8
+ * A fragment is a single item from an ABI, which may represent any of:
9
+ *
10
+ * - [Functions](FunctionFragment)
11
+ * - [Events](EventFragment)
12
+ * - [Constructors](ConstructorFragment)
13
+ * - Custom [Errors](ErrorFragment)
14
+ * - [Fallback or Receive](FallbackFragment) functions
15
+ *
16
+ * @_subsection api/abi/abi-coder:Fragments [about-fragments]
17
+ */
18
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
19
+ if (kind === "m") throw new TypeError("Private method is not writable");
20
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
21
+ 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");
22
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
23
+ };
24
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
25
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
26
+ 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");
27
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
28
+ };
29
+ var _TokenString_instances, _TokenString_offset, _TokenString_tokens, _TokenString_subTokenString, _ParamType_instances, _ParamType_walkAsync;
30
+ import { defineProperties, getBigInt, getNumber, assert, assertPrivate, assertArgument, id } from "./utils/index.js";
31
+ ;
32
+ // [ "a", "b" ] => { "a": 1, "b": 1 }
33
+ function setify(items) {
34
+ const result = new Set();
35
+ items.forEach((k) => result.add(k));
36
+ return Object.freeze(result);
37
+ }
38
+ const _kwVisibDeploy = "external public payable";
39
+ const KwVisibDeploy = setify(_kwVisibDeploy.split(" "));
40
+ // Visibility Keywords
41
+ const _kwVisib = "constant external internal payable private public pure view";
42
+ const KwVisib = setify(_kwVisib.split(" "));
43
+ const _kwTypes = "constructor error event fallback function receive struct";
44
+ const KwTypes = setify(_kwTypes.split(" "));
45
+ const _kwModifiers = "calldata memory storage payable indexed";
46
+ const KwModifiers = setify(_kwModifiers.split(" "));
47
+ const _kwOther = "tuple returns";
48
+ // All Keywords
49
+ const _keywords = [_kwTypes, _kwModifiers, _kwOther, _kwVisib].join(" ");
50
+ const Keywords = setify(_keywords.split(" "));
51
+ // Single character tokens
52
+ const SimpleTokens = {
53
+ "(": "OPEN_PAREN", ")": "CLOSE_PAREN",
54
+ "[": "OPEN_BRACKET", "]": "CLOSE_BRACKET",
55
+ ",": "COMMA", "@": "AT"
56
+ };
57
+ // Parser regexes to consume the next token
58
+ const regexWhitespacePrefix = new RegExp("^(\\s*)");
59
+ const regexNumberPrefix = new RegExp("^([0-9]+)");
60
+ const regexIdPrefix = new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)");
61
+ // Parser regexs to check validity
62
+ const regexId = new RegExp("^([a-zA-Z$_][a-zA-Z0-9$_]*)$");
63
+ const regexType = new RegExp("^(address|bool|bytes([0-9]*)|string|u?int([0-9]*))$");
64
+ class TokenString {
65
+ constructor(tokens) {
66
+ _TokenString_instances.add(this);
67
+ _TokenString_offset.set(this, void 0);
68
+ _TokenString_tokens.set(this, void 0);
69
+ __classPrivateFieldSet(this, _TokenString_offset, 0, "f");
70
+ __classPrivateFieldSet(this, _TokenString_tokens, tokens.slice(), "f");
71
+ }
72
+ get offset() { return __classPrivateFieldGet(this, _TokenString_offset, "f"); }
73
+ get length() { return __classPrivateFieldGet(this, _TokenString_tokens, "f").length - __classPrivateFieldGet(this, _TokenString_offset, "f"); }
74
+ clone() { return new TokenString(__classPrivateFieldGet(this, _TokenString_tokens, "f")); }
75
+ reset() { __classPrivateFieldSet(this, _TokenString_offset, 0, "f"); }
76
+ // Pops and returns the value of the next token, if it is a keyword in allowed; throws if out of tokens
77
+ popKeyword(allowed) {
78
+ const top = this.peek();
79
+ if (top.type !== "KEYWORD" || !allowed.has(top.text)) {
80
+ throw new Error(`expected keyword ${top.text}`);
81
+ }
82
+ return this.pop().text;
83
+ }
84
+ // Pops and returns the value of the next token if it is `type`; throws if out of tokens
85
+ popType(type) {
86
+ if (this.peek().type !== type) {
87
+ throw new Error(`expected ${type}; got ${JSON.stringify(this.peek())}`);
88
+ }
89
+ return this.pop().text;
90
+ }
91
+ // Pops and returns a "(" TOKENS ")"
92
+ popParen() {
93
+ const top = this.peek();
94
+ if (top.type !== "OPEN_PAREN") {
95
+ throw new Error("bad start");
96
+ }
97
+ const result = __classPrivateFieldGet(this, _TokenString_instances, "m", _TokenString_subTokenString).call(this, __classPrivateFieldGet(this, _TokenString_offset, "f") + 1, top.match + 1);
98
+ __classPrivateFieldSet(this, _TokenString_offset, top.match + 1, "f");
99
+ return result;
100
+ }
101
+ // Pops and returns the items within "(" ITEM1 "," ITEM2 "," ... ")"
102
+ popParams() {
103
+ const top = this.peek();
104
+ if (top.type !== "OPEN_PAREN") {
105
+ throw new Error("bad start");
106
+ }
107
+ const result = [];
108
+ while (__classPrivateFieldGet(this, _TokenString_offset, "f") < top.match - 1) {
109
+ const link = this.peek().linkNext;
110
+ result.push(__classPrivateFieldGet(this, _TokenString_instances, "m", _TokenString_subTokenString).call(this, __classPrivateFieldGet(this, _TokenString_offset, "f") + 1, link));
111
+ __classPrivateFieldSet(this, _TokenString_offset, link, "f");
112
+ }
113
+ __classPrivateFieldSet(this, _TokenString_offset, top.match + 1, "f");
114
+ return result;
115
+ }
116
+ // Returns the top Token, throwing if out of tokens
117
+ peek() {
118
+ if (__classPrivateFieldGet(this, _TokenString_offset, "f") >= __classPrivateFieldGet(this, _TokenString_tokens, "f").length) {
119
+ throw new Error("out-of-bounds");
120
+ }
121
+ return __classPrivateFieldGet(this, _TokenString_tokens, "f")[__classPrivateFieldGet(this, _TokenString_offset, "f")];
122
+ }
123
+ // Returns the next value, if it is a keyword in `allowed`
124
+ peekKeyword(allowed) {
125
+ const top = this.peekType("KEYWORD");
126
+ return (top != null && allowed.has(top)) ? top : null;
127
+ }
128
+ // Returns the value of the next token if it is `type`
129
+ peekType(type) {
130
+ if (this.length === 0) {
131
+ return null;
132
+ }
133
+ const top = this.peek();
134
+ return (top.type === type) ? top.text : null;
135
+ }
136
+ // Returns the next token; throws if out of tokens
137
+ pop() {
138
+ var _a;
139
+ const result = this.peek();
140
+ __classPrivateFieldSet(this, _TokenString_offset, (_a = __classPrivateFieldGet(this, _TokenString_offset, "f"), _a++, _a), "f");
141
+ return result;
142
+ }
143
+ toString() {
144
+ const tokens = [];
145
+ for (let i = __classPrivateFieldGet(this, _TokenString_offset, "f"); i < __classPrivateFieldGet(this, _TokenString_tokens, "f").length; i++) {
146
+ const token = __classPrivateFieldGet(this, _TokenString_tokens, "f")[i];
147
+ tokens.push(`${token.type}:${token.text}`);
148
+ }
149
+ return `<TokenString ${tokens.join(" ")}>`;
150
+ }
151
+ }
152
+ _TokenString_offset = new WeakMap(), _TokenString_tokens = new WeakMap(), _TokenString_instances = new WeakSet(), _TokenString_subTokenString = function _TokenString_subTokenString(from = 0, to = 0) {
153
+ return new TokenString(__classPrivateFieldGet(this, _TokenString_tokens, "f").slice(from, to).map((t) => {
154
+ return Object.freeze(Object.assign({}, t, {
155
+ match: (t.match - from),
156
+ linkBack: (t.linkBack - from),
157
+ linkNext: (t.linkNext - from),
158
+ }));
159
+ }));
160
+ };
161
+ function lex(text) {
162
+ const tokens = [];
163
+ const throwError = (message) => {
164
+ const token = (offset < text.length) ? JSON.stringify(text[offset]) : "$EOI";
165
+ throw new Error(`invalid token ${token} at ${offset}: ${message}`);
166
+ };
167
+ let brackets = [];
168
+ let commas = [];
169
+ let offset = 0;
170
+ while (offset < text.length) {
171
+ // Strip off any leading whitespace
172
+ let cur = text.substring(offset);
173
+ let match = cur.match(regexWhitespacePrefix);
174
+ if (match) {
175
+ offset += match[1].length;
176
+ cur = text.substring(offset);
177
+ }
178
+ const token = { depth: brackets.length, linkBack: -1, linkNext: -1, match: -1, type: "", text: "", offset, value: -1 };
179
+ tokens.push(token);
180
+ let type = (SimpleTokens[cur[0]] || "");
181
+ if (type) {
182
+ token.type = type;
183
+ token.text = cur[0];
184
+ offset++;
185
+ if (type === "OPEN_PAREN") {
186
+ brackets.push(tokens.length - 1);
187
+ commas.push(tokens.length - 1);
188
+ }
189
+ else if (type == "CLOSE_PAREN") {
190
+ if (brackets.length === 0) {
191
+ throwError("no matching open bracket");
192
+ }
193
+ token.match = brackets.pop();
194
+ (tokens[token.match]).match = tokens.length - 1;
195
+ token.depth--;
196
+ token.linkBack = commas.pop();
197
+ (tokens[token.linkBack]).linkNext = tokens.length - 1;
198
+ }
199
+ else if (type === "COMMA") {
200
+ token.linkBack = commas.pop();
201
+ (tokens[token.linkBack]).linkNext = tokens.length - 1;
202
+ commas.push(tokens.length - 1);
203
+ }
204
+ else if (type === "OPEN_BRACKET") {
205
+ token.type = "BRACKET";
206
+ }
207
+ else if (type === "CLOSE_BRACKET") {
208
+ // Remove the CLOSE_BRACKET
209
+ let suffix = tokens.pop().text;
210
+ if (tokens.length > 0 && tokens[tokens.length - 1].type === "NUMBER") {
211
+ const value = tokens.pop().text;
212
+ suffix = value + suffix;
213
+ (tokens[tokens.length - 1]).value = getNumber(value);
214
+ }
215
+ if (tokens.length === 0 || tokens[tokens.length - 1].type !== "BRACKET") {
216
+ throw new Error("missing opening bracket");
217
+ }
218
+ (tokens[tokens.length - 1]).text += suffix;
219
+ }
220
+ continue;
221
+ }
222
+ match = cur.match(regexIdPrefix);
223
+ if (match) {
224
+ token.text = match[1];
225
+ offset += token.text.length;
226
+ if (Keywords.has(token.text)) {
227
+ token.type = "KEYWORD";
228
+ continue;
229
+ }
230
+ if (token.text.match(regexType)) {
231
+ token.type = "TYPE";
232
+ continue;
233
+ }
234
+ token.type = "ID";
235
+ continue;
236
+ }
237
+ match = cur.match(regexNumberPrefix);
238
+ if (match) {
239
+ token.text = match[1];
240
+ token.type = "NUMBER";
241
+ offset += token.text.length;
242
+ continue;
243
+ }
244
+ throw new Error(`unexpected token ${JSON.stringify(cur[0])} at position ${offset}`);
245
+ }
246
+ return new TokenString(tokens.map((t) => Object.freeze(t)));
247
+ }
248
+ // Check only one of `allowed` is in `set`
249
+ function allowSingle(set, allowed) {
250
+ let included = [];
251
+ for (const key in allowed.keys()) {
252
+ if (set.has(key)) {
253
+ included.push(key);
254
+ }
255
+ }
256
+ if (included.length > 1) {
257
+ throw new Error(`conflicting types: ${included.join(", ")}`);
258
+ }
259
+ }
260
+ // Functions to process a Solidity Signature TokenString from left-to-right for...
261
+ // ...the name with an optional type, returning the name
262
+ function consumeName(type, tokens) {
263
+ if (tokens.peekKeyword(KwTypes)) {
264
+ const keyword = tokens.pop().text;
265
+ if (keyword !== type) {
266
+ throw new Error(`expected ${type}, got ${keyword}`);
267
+ }
268
+ }
269
+ return tokens.popType("ID");
270
+ }
271
+ // ...all keywords matching allowed, returning the keywords
272
+ function consumeKeywords(tokens, allowed) {
273
+ const keywords = new Set();
274
+ while (true) {
275
+ const keyword = tokens.peekType("KEYWORD");
276
+ if (keyword == null || (allowed && !allowed.has(keyword))) {
277
+ break;
278
+ }
279
+ tokens.pop();
280
+ if (keywords.has(keyword)) {
281
+ throw new Error(`duplicate keywords: ${JSON.stringify(keyword)}`);
282
+ }
283
+ keywords.add(keyword);
284
+ }
285
+ return Object.freeze(keywords);
286
+ }
287
+ // ...all visibility keywords, returning the coalesced mutability
288
+ function consumeMutability(tokens) {
289
+ let modifiers = consumeKeywords(tokens, KwVisib);
290
+ // Detect conflicting modifiers
291
+ allowSingle(modifiers, setify("constant payable nonpayable".split(" ")));
292
+ allowSingle(modifiers, setify("pure view payable nonpayable".split(" ")));
293
+ // Process mutability states
294
+ if (modifiers.has("view")) {
295
+ return "view";
296
+ }
297
+ if (modifiers.has("pure")) {
298
+ return "pure";
299
+ }
300
+ if (modifiers.has("payable")) {
301
+ return "payable";
302
+ }
303
+ if (modifiers.has("nonpayable")) {
304
+ return "nonpayable";
305
+ }
306
+ // Process legacy `constant` last
307
+ if (modifiers.has("constant")) {
308
+ return "view";
309
+ }
310
+ return "nonpayable";
311
+ }
312
+ // ...a parameter list, returning the ParamType list
313
+ function consumeParams(tokens, allowIndexed) {
314
+ return tokens.popParams().map((t) => ParamType.from(t, allowIndexed));
315
+ }
316
+ // ...a gas limit, returning a BigNumber or null if none
317
+ function consumeGas(tokens) {
318
+ if (tokens.peekType("AT")) {
319
+ tokens.pop();
320
+ if (tokens.peekType("NUMBER")) {
321
+ return getBigInt(tokens.pop().text);
322
+ }
323
+ throw new Error("invalid gas");
324
+ }
325
+ return null;
326
+ }
327
+ function consumeEoi(tokens) {
328
+ if (tokens.length) {
329
+ throw new Error(`unexpected tokens: ${tokens.toString()}`);
330
+ }
331
+ }
332
+ const regexArrayType = new RegExp(/^(.*)\[([0-9]*)\]$/);
333
+ function verifyBasicType(type) {
334
+ const match = type.match(regexType);
335
+ assertArgument(match, "invalid type", "type", type);
336
+ if (type === "uint") {
337
+ return "uint256";
338
+ }
339
+ if (type === "int") {
340
+ return "int256";
341
+ }
342
+ if (match[2]) {
343
+ // bytesXX
344
+ const length = parseInt(match[2]);
345
+ assertArgument(length !== 0 && length <= 32, "invalid bytes length", "type", type);
346
+ }
347
+ else if (match[3]) {
348
+ // intXX or uintXX
349
+ const size = parseInt(match[3]);
350
+ assertArgument(size !== 0 && size <= 256 && (size % 8) === 0, "invalid numeric width", "type", type);
351
+ }
352
+ return type;
353
+ }
354
+ // Make the Fragment constructors effectively private
355
+ const _guard = {};
356
+ const internal = Symbol.for("_ethers_internal");
357
+ const ParamTypeInternal = "_ParamTypeInternal";
358
+ const ErrorFragmentInternal = "_ErrorInternal";
359
+ const EventFragmentInternal = "_EventInternal";
360
+ const ConstructorFragmentInternal = "_ConstructorInternal";
361
+ const FallbackFragmentInternal = "_FallbackInternal";
362
+ const FunctionFragmentInternal = "_FunctionInternal";
363
+ const StructFragmentInternal = "_StructInternal";
364
+ /**
365
+ * Each input and output of a [[Fragment]] is an Array of **ParamType**.
366
+ */
367
+ export class ParamType {
368
+ /**
369
+ * @private
370
+ */
371
+ constructor(guard, name, type, baseType, indexed, components, arrayLength, arrayChildren) {
372
+ _ParamType_instances.add(this);
373
+ assertPrivate(guard, _guard, "ParamType");
374
+ Object.defineProperty(this, internal, { value: ParamTypeInternal });
375
+ if (components) {
376
+ components = Object.freeze(components.slice());
377
+ }
378
+ if (baseType === "array") {
379
+ if (arrayLength == null || arrayChildren == null) {
380
+ throw new Error("");
381
+ }
382
+ }
383
+ else if (arrayLength != null || arrayChildren != null) {
384
+ throw new Error("");
385
+ }
386
+ if (baseType === "tuple") {
387
+ if (components == null) {
388
+ throw new Error("");
389
+ }
390
+ }
391
+ else if (components != null) {
392
+ throw new Error("");
393
+ }
394
+ defineProperties(this, {
395
+ name, type, baseType, indexed, components, arrayLength, arrayChildren
396
+ });
397
+ }
398
+ /**
399
+ * Return a string representation of this type.
400
+ *
401
+ * For example,
402
+ *
403
+ * ``sighash" => "(uint256,address)"``
404
+ *
405
+ * ``"minimal" => "tuple(uint256,address) indexed"``
406
+ *
407
+ * ``"full" => "tuple(uint256 foo, address bar) indexed baz"``
408
+ */
409
+ format(format) {
410
+ if (format == null) {
411
+ format = "sighash";
412
+ }
413
+ if (format === "json") {
414
+ const name = this.name || "";
415
+ if (this.isArray()) {
416
+ const result = JSON.parse(this.arrayChildren.format("json"));
417
+ result.name = name;
418
+ result.type += `[${(this.arrayLength < 0 ? "" : String(this.arrayLength))}]`;
419
+ return JSON.stringify(result);
420
+ }
421
+ const result = {
422
+ type: ((this.baseType === "tuple") ? "tuple" : this.type),
423
+ name
424
+ };
425
+ if (typeof (this.indexed) === "boolean") {
426
+ result.indexed = this.indexed;
427
+ }
428
+ if (this.isTuple()) {
429
+ result.components = this.components.map((c) => JSON.parse(c.format(format)));
430
+ }
431
+ return JSON.stringify(result);
432
+ }
433
+ let result = "";
434
+ // Array
435
+ if (this.isArray()) {
436
+ result += this.arrayChildren.format(format);
437
+ result += `[${(this.arrayLength < 0 ? "" : String(this.arrayLength))}]`;
438
+ }
439
+ else {
440
+ if (this.isTuple()) {
441
+ result += "(" + this.components.map((comp) => comp.format(format)).join((format === "full") ? ", " : ",") + ")";
442
+ }
443
+ else {
444
+ result += this.type;
445
+ }
446
+ }
447
+ if (format !== "sighash") {
448
+ if (this.indexed === true) {
449
+ result += " indexed";
450
+ }
451
+ if (format === "full" && this.name) {
452
+ result += " " + this.name;
453
+ }
454
+ }
455
+ return result;
456
+ }
457
+ /**
458
+ * Returns true if %%this%% is an Array type.
459
+ *
460
+ * This provides a type gaurd ensuring that [[arrayChildren]]
461
+ * and [[arrayLength]] are non-null.
462
+ */
463
+ isArray() {
464
+ return (this.baseType === "array");
465
+ }
466
+ /**
467
+ * Returns true if %%this%% is a Tuple type.
468
+ *
469
+ * This provides a type gaurd ensuring that [[components]]
470
+ * is non-null.
471
+ */
472
+ isTuple() {
473
+ return (this.baseType === "tuple");
474
+ }
475
+ /**
476
+ * Returns true if %%this%% is an Indexable type.
477
+ *
478
+ * This provides a type gaurd ensuring that [[indexed]]
479
+ * is non-null.
480
+ */
481
+ isIndexable() {
482
+ return (this.indexed != null);
483
+ }
484
+ /**
485
+ * Walks the **ParamType** with %%value%%, calling %%process%%
486
+ * on each type, destructing the %%value%% recursively.
487
+ */
488
+ walk(value, process) {
489
+ if (this.isArray()) {
490
+ if (!Array.isArray(value)) {
491
+ throw new Error("invalid array value");
492
+ }
493
+ if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
494
+ throw new Error("array is wrong length");
495
+ }
496
+ const _this = this;
497
+ return value.map((v) => (_this.arrayChildren.walk(v, process)));
498
+ }
499
+ if (this.isTuple()) {
500
+ if (!Array.isArray(value)) {
501
+ throw new Error("invalid tuple value");
502
+ }
503
+ if (value.length !== this.components.length) {
504
+ throw new Error("array is wrong length");
505
+ }
506
+ const _this = this;
507
+ return value.map((v, i) => (_this.components[i].walk(v, process)));
508
+ }
509
+ return process(this.type, value);
510
+ }
511
+ /**
512
+ * Walks the **ParamType** with %%value%%, asynchronously calling
513
+ * %%process%% on each type, destructing the %%value%% recursively.
514
+ *
515
+ * This can be used to resolve ENS naes by walking and resolving each
516
+ * ``"address"`` type.
517
+ */
518
+ async walkAsync(value, process) {
519
+ const promises = [];
520
+ const result = [value];
521
+ __classPrivateFieldGet(this, _ParamType_instances, "m", _ParamType_walkAsync).call(this, promises, value, process, (value) => {
522
+ result[0] = value;
523
+ });
524
+ if (promises.length) {
525
+ await Promise.all(promises);
526
+ }
527
+ return result[0];
528
+ }
529
+ /**
530
+ * Creates a new **ParamType** for %%obj%%.
531
+ *
532
+ * If %%allowIndexed%% then the ``indexed`` keyword is permitted,
533
+ * otherwise the ``indexed`` keyword will throw an error.
534
+ */
535
+ static from(obj, allowIndexed) {
536
+ if (ParamType.isParamType(obj)) {
537
+ return obj;
538
+ }
539
+ if (typeof (obj) === "string") {
540
+ try {
541
+ return ParamType.from(lex(obj), allowIndexed);
542
+ }
543
+ catch (error) {
544
+ assertArgument(false, "invalid param type", "obj", obj);
545
+ }
546
+ }
547
+ else if (obj instanceof TokenString) {
548
+ let type = "", baseType = "";
549
+ let comps = null;
550
+ if (consumeKeywords(obj, setify(["tuple"])).has("tuple") || obj.peekType("OPEN_PAREN")) {
551
+ // Tuple
552
+ baseType = "tuple";
553
+ comps = obj.popParams().map((t) => ParamType.from(t));
554
+ type = `tuple(${comps.map((c) => c.format()).join(",")})`;
555
+ }
556
+ else {
557
+ // Normal
558
+ type = verifyBasicType(obj.popType("TYPE"));
559
+ baseType = type;
560
+ }
561
+ // Check for Array
562
+ let arrayChildren = null;
563
+ let arrayLength = null;
564
+ while (obj.length && obj.peekType("BRACKET")) {
565
+ const bracket = obj.pop(); //arrays[i];
566
+ arrayChildren = new ParamType(_guard, "", type, baseType, null, comps, arrayLength, arrayChildren);
567
+ arrayLength = bracket.value;
568
+ type += bracket.text;
569
+ baseType = "array";
570
+ comps = null;
571
+ }
572
+ let indexed = null;
573
+ const keywords = consumeKeywords(obj, KwModifiers);
574
+ if (keywords.has("indexed")) {
575
+ if (!allowIndexed) {
576
+ throw new Error("");
577
+ }
578
+ indexed = true;
579
+ }
580
+ const name = (obj.peekType("ID") ? obj.pop().text : "");
581
+ if (obj.length) {
582
+ throw new Error("leftover tokens");
583
+ }
584
+ return new ParamType(_guard, name, type, baseType, indexed, comps, arrayLength, arrayChildren);
585
+ }
586
+ const name = obj.name;
587
+ assertArgument(!name || (typeof (name) === "string" && name.match(regexId)), "invalid name", "obj.name", name);
588
+ let indexed = obj.indexed;
589
+ if (indexed != null) {
590
+ assertArgument(allowIndexed, "parameter cannot be indexed", "obj.indexed", obj.indexed);
591
+ indexed = !!indexed;
592
+ }
593
+ let type = obj.type;
594
+ let arrayMatch = type.match(regexArrayType);
595
+ if (arrayMatch) {
596
+ const arrayLength = parseInt(arrayMatch[2] || "-1");
597
+ const arrayChildren = ParamType.from({
598
+ type: arrayMatch[1],
599
+ components: obj.components
600
+ });
601
+ return new ParamType(_guard, name || "", type, "array", indexed, null, arrayLength, arrayChildren);
602
+ }
603
+ if (type === "tuple" || type.startsWith("tuple(" /* fix: ) */) || type.startsWith("(" /* fix: ) */)) {
604
+ const comps = (obj.components != null) ? obj.components.map((c) => ParamType.from(c)) : null;
605
+ const tuple = new ParamType(_guard, name || "", type, "tuple", indexed, comps, null, null);
606
+ // @TODO: use lexer to validate and normalize type
607
+ return tuple;
608
+ }
609
+ type = verifyBasicType(obj.type);
610
+ return new ParamType(_guard, name || "", type, type, indexed, null, null, null);
611
+ }
612
+ /**
613
+ * Returns true if %%value%% is a **ParamType**.
614
+ */
615
+ static isParamType(value) {
616
+ return (value && value[internal] === ParamTypeInternal);
617
+ }
618
+ }
619
+ _ParamType_instances = new WeakSet(), _ParamType_walkAsync = function _ParamType_walkAsync(promises, value, process, setValue) {
620
+ if (this.isArray()) {
621
+ if (!Array.isArray(value)) {
622
+ throw new Error("invalid array value");
623
+ }
624
+ if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
625
+ throw new Error("array is wrong length");
626
+ }
627
+ const childType = this.arrayChildren;
628
+ const result = value.slice();
629
+ result.forEach((value, index) => {
630
+ __classPrivateFieldGet(childType, _ParamType_instances, "m", _ParamType_walkAsync).call(childType, promises, value, process, (value) => {
631
+ result[index] = value;
632
+ });
633
+ });
634
+ setValue(result);
635
+ return;
636
+ }
637
+ if (this.isTuple()) {
638
+ const components = this.components;
639
+ // Convert the object into an array
640
+ let result;
641
+ if (Array.isArray(value)) {
642
+ result = value.slice();
643
+ }
644
+ else {
645
+ if (value == null || typeof (value) !== "object") {
646
+ throw new Error("invalid tuple value");
647
+ }
648
+ result = components.map((param) => {
649
+ if (!param.name) {
650
+ throw new Error("cannot use object value with unnamed components");
651
+ }
652
+ if (!(param.name in value)) {
653
+ throw new Error(`missing value for component ${param.name}`);
654
+ }
655
+ return value[param.name];
656
+ });
657
+ }
658
+ if (result.length !== this.components.length) {
659
+ throw new Error("array is wrong length");
660
+ }
661
+ result.forEach((value, index) => {
662
+ var _a;
663
+ __classPrivateFieldGet((_a = components[index]), _ParamType_instances, "m", _ParamType_walkAsync).call(_a, promises, value, process, (value) => {
664
+ result[index] = value;
665
+ });
666
+ });
667
+ setValue(result);
668
+ return;
669
+ }
670
+ const result = process(this.type, value);
671
+ if (result.then) {
672
+ promises.push((async function () { setValue(await result); })());
673
+ }
674
+ else {
675
+ setValue(result);
676
+ }
677
+ };
678
+ /**
679
+ * An abstract class to represent An individual fragment from a parse ABI.
680
+ */
681
+ export class Fragment {
682
+ /**
683
+ * @private
684
+ */
685
+ constructor(guard, type, inputs) {
686
+ assertPrivate(guard, _guard, "Fragment");
687
+ inputs = Object.freeze(inputs.slice());
688
+ defineProperties(this, { type, inputs });
689
+ }
690
+ /**
691
+ * Creates a new **Fragment** for %%obj%%, wich can be any supported
692
+ * ABI frgament type.
693
+ */
694
+ static from(obj) {
695
+ if (typeof (obj) === "string") {
696
+ // Try parsing JSON...
697
+ try {
698
+ Fragment.from(JSON.parse(obj));
699
+ }
700
+ catch (e) { }
701
+ // ...otherwise, use the human-readable lexer
702
+ return Fragment.from(lex(obj));
703
+ }
704
+ if (obj instanceof TokenString) {
705
+ // Human-readable ABI (already lexed)
706
+ const type = obj.peekKeyword(KwTypes);
707
+ switch (type) {
708
+ case "constructor": return ConstructorFragment.from(obj);
709
+ case "error": return ErrorFragment.from(obj);
710
+ case "event": return EventFragment.from(obj);
711
+ case "fallback":
712
+ case "receive":
713
+ return FallbackFragment.from(obj);
714
+ case "function": return FunctionFragment.from(obj);
715
+ case "struct": return StructFragment.from(obj);
716
+ }
717
+ }
718
+ else if (typeof (obj) === "object") {
719
+ // JSON ABI
720
+ switch (obj.type) {
721
+ case "constructor": return ConstructorFragment.from(obj);
722
+ case "error": return ErrorFragment.from(obj);
723
+ case "event": return EventFragment.from(obj);
724
+ case "fallback":
725
+ case "receive":
726
+ return FallbackFragment.from(obj);
727
+ case "function": return FunctionFragment.from(obj);
728
+ case "struct": return StructFragment.from(obj);
729
+ }
730
+ assert(false, `unsupported type: ${obj.type}`, "UNSUPPORTED_OPERATION", {
731
+ operation: "Fragment.from"
732
+ });
733
+ }
734
+ assertArgument(false, "unsupported frgament object", "obj", obj);
735
+ }
736
+ /**
737
+ * Returns true if %%value%% is a [[ConstructorFragment]].
738
+ */
739
+ static isConstructor(value) {
740
+ return ConstructorFragment.isFragment(value);
741
+ }
742
+ /**
743
+ * Returns true if %%value%% is an [[ErrorFragment]].
744
+ */
745
+ static isError(value) {
746
+ return ErrorFragment.isFragment(value);
747
+ }
748
+ /**
749
+ * Returns true if %%value%% is an [[EventFragment]].
750
+ */
751
+ static isEvent(value) {
752
+ return EventFragment.isFragment(value);
753
+ }
754
+ /**
755
+ * Returns true if %%value%% is a [[FunctionFragment]].
756
+ */
757
+ static isFunction(value) {
758
+ return FunctionFragment.isFragment(value);
759
+ }
760
+ /**
761
+ * Returns true if %%value%% is a [[StructFragment]].
762
+ */
763
+ static isStruct(value) {
764
+ return StructFragment.isFragment(value);
765
+ }
766
+ }
767
+ /**
768
+ * An abstract class to represent An individual fragment
769
+ * which has a name from a parse ABI.
770
+ */
771
+ export class NamedFragment extends Fragment {
772
+ /**
773
+ * @private
774
+ */
775
+ constructor(guard, type, name, inputs) {
776
+ super(guard, type, inputs);
777
+ assertArgument(typeof (name) === "string" && name.match(regexId), "invalid identifier", "name", name);
778
+ inputs = Object.freeze(inputs.slice());
779
+ defineProperties(this, { name });
780
+ }
781
+ }
782
+ function joinParams(format, params) {
783
+ return "(" + params.map((p) => p.format(format)).join((format === "full") ? ", " : ",") + ")";
784
+ }
785
+ /**
786
+ * A Fragment which represents a //Custom Error//.
787
+ */
788
+ export class ErrorFragment extends NamedFragment {
789
+ /**
790
+ * @private
791
+ */
792
+ constructor(guard, name, inputs) {
793
+ super(guard, "error", name, inputs);
794
+ Object.defineProperty(this, internal, { value: ErrorFragmentInternal });
795
+ }
796
+ /**
797
+ * The Custom Error selector.
798
+ */
799
+ get selector() {
800
+ return id(this.format("sighash")).substring(0, 10);
801
+ }
802
+ /**
803
+ * Returns a string representation of this fragment as %%format%%.
804
+ */
805
+ format(format) {
806
+ if (format == null) {
807
+ format = "sighash";
808
+ }
809
+ if (format === "json") {
810
+ return JSON.stringify({
811
+ type: "error",
812
+ name: this.name,
813
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
814
+ });
815
+ }
816
+ const result = [];
817
+ if (format !== "sighash") {
818
+ result.push("error");
819
+ }
820
+ result.push(this.name + joinParams(format, this.inputs));
821
+ return result.join(" ");
822
+ }
823
+ /**
824
+ * Returns a new **ErrorFragment** for %%obj%%.
825
+ */
826
+ static from(obj) {
827
+ if (ErrorFragment.isFragment(obj)) {
828
+ return obj;
829
+ }
830
+ if (typeof (obj) === "string") {
831
+ return ErrorFragment.from(lex(obj));
832
+ }
833
+ else if (obj instanceof TokenString) {
834
+ const name = consumeName("error", obj);
835
+ const inputs = consumeParams(obj);
836
+ consumeEoi(obj);
837
+ return new ErrorFragment(_guard, name, inputs);
838
+ }
839
+ return new ErrorFragment(_guard, obj.name, obj.inputs ? obj.inputs.map(ParamType.from) : []);
840
+ }
841
+ /**
842
+ * Returns ``true`` and provides a type guard if %%value%% is an
843
+ * **ErrorFragment**.
844
+ */
845
+ static isFragment(value) {
846
+ return (value && value[internal] === ErrorFragmentInternal);
847
+ }
848
+ }
849
+ /**
850
+ * A Fragment which represents an Event.
851
+ */
852
+ export class EventFragment extends NamedFragment {
853
+ /**
854
+ * @private
855
+ */
856
+ constructor(guard, name, inputs, anonymous) {
857
+ super(guard, "event", name, inputs);
858
+ Object.defineProperty(this, internal, { value: EventFragmentInternal });
859
+ defineProperties(this, { anonymous });
860
+ }
861
+ /**
862
+ * The Event topic hash.
863
+ */
864
+ get topicHash() {
865
+ return id(this.format("sighash"));
866
+ }
867
+ /**
868
+ * Returns a string representation of this event as %%format%%.
869
+ */
870
+ format(format) {
871
+ if (format == null) {
872
+ format = "sighash";
873
+ }
874
+ if (format === "json") {
875
+ return JSON.stringify({
876
+ type: "event",
877
+ anonymous: this.anonymous,
878
+ name: this.name,
879
+ inputs: this.inputs.map((i) => JSON.parse(i.format(format)))
880
+ });
881
+ }
882
+ const result = [];
883
+ if (format !== "sighash") {
884
+ result.push("event");
885
+ }
886
+ result.push(this.name + joinParams(format, this.inputs));
887
+ if (format !== "sighash" && this.anonymous) {
888
+ result.push("anonymous");
889
+ }
890
+ return result.join(" ");
891
+ }
892
+ /**
893
+ * Return the topic hash for an event with %%name%% and %%params%%.
894
+ */
895
+ static getTopicHash(name, params) {
896
+ params = (params || []).map((p) => ParamType.from(p));
897
+ const fragment = new EventFragment(_guard, name, params, false);
898
+ return fragment.topicHash;
899
+ }
900
+ /**
901
+ * Returns a new **EventFragment** for %%obj%%.
902
+ */
903
+ static from(obj) {
904
+ if (EventFragment.isFragment(obj)) {
905
+ return obj;
906
+ }
907
+ if (typeof (obj) === "string") {
908
+ try {
909
+ return EventFragment.from(lex(obj));
910
+ }
911
+ catch (error) {
912
+ assertArgument(false, "invalid event fragment", "obj", obj);
913
+ }
914
+ }
915
+ else if (obj instanceof TokenString) {
916
+ const name = consumeName("event", obj);
917
+ const inputs = consumeParams(obj, true);
918
+ const anonymous = !!consumeKeywords(obj, setify(["anonymous"])).has("anonymous");
919
+ consumeEoi(obj);
920
+ return new EventFragment(_guard, name, inputs, anonymous);
921
+ }
922
+ return new EventFragment(_guard, obj.name, obj.inputs ? obj.inputs.map((p) => ParamType.from(p, true)) : [], !!obj.anonymous);
923
+ }
924
+ /**
925
+ * Returns ``true`` and provides a type guard if %%value%% is an
926
+ * **EventFragment**.
927
+ */
928
+ static isFragment(value) {
929
+ return (value && value[internal] === EventFragmentInternal);
930
+ }
931
+ }
932
+ /**
933
+ * A Fragment which represents a constructor.
934
+ */
935
+ export class ConstructorFragment extends Fragment {
936
+ /**
937
+ * @private
938
+ */
939
+ constructor(guard, type, inputs, payable, gas) {
940
+ super(guard, type, inputs);
941
+ Object.defineProperty(this, internal, { value: ConstructorFragmentInternal });
942
+ defineProperties(this, { payable, gas });
943
+ }
944
+ /**
945
+ * Returns a string representation of this constructor as %%format%%.
946
+ */
947
+ format(format) {
948
+ assert(format != null && format !== "sighash", "cannot format a constructor for sighash", "UNSUPPORTED_OPERATION", { operation: "format(sighash)" });
949
+ if (format === "json") {
950
+ return JSON.stringify({
951
+ type: "constructor",
952
+ stateMutability: (this.payable ? "payable" : "undefined"),
953
+ payable: this.payable,
954
+ gas: ((this.gas != null) ? this.gas : undefined),
955
+ inputs: this.inputs.map((i) => JSON.parse(i.format(format)))
956
+ });
957
+ }
958
+ const result = [`constructor${joinParams(format, this.inputs)}`];
959
+ if (this.payable) {
960
+ result.push("payable");
961
+ }
962
+ if (this.gas != null) {
963
+ result.push(`@${this.gas.toString()}`);
964
+ }
965
+ return result.join(" ");
966
+ }
967
+ /**
968
+ * Returns a new **ConstructorFragment** for %%obj%%.
969
+ */
970
+ static from(obj) {
971
+ if (ConstructorFragment.isFragment(obj)) {
972
+ return obj;
973
+ }
974
+ if (typeof (obj) === "string") {
975
+ try {
976
+ return ConstructorFragment.from(lex(obj));
977
+ }
978
+ catch (error) {
979
+ assertArgument(false, "invalid constuctor fragment", "obj", obj);
980
+ }
981
+ }
982
+ else if (obj instanceof TokenString) {
983
+ consumeKeywords(obj, setify(["constructor"]));
984
+ const inputs = consumeParams(obj);
985
+ const payable = !!consumeKeywords(obj, KwVisibDeploy).has("payable");
986
+ const gas = consumeGas(obj);
987
+ consumeEoi(obj);
988
+ return new ConstructorFragment(_guard, "constructor", inputs, payable, gas);
989
+ }
990
+ return new ConstructorFragment(_guard, "constructor", obj.inputs ? obj.inputs.map(ParamType.from) : [], !!obj.payable, (obj.gas != null) ? obj.gas : null);
991
+ }
992
+ /**
993
+ * Returns ``true`` and provides a type guard if %%value%% is a
994
+ * **ConstructorFragment**.
995
+ */
996
+ static isFragment(value) {
997
+ return (value && value[internal] === ConstructorFragmentInternal);
998
+ }
999
+ }
1000
+ /**
1001
+ * A Fragment which represents a method.
1002
+ */
1003
+ export class FallbackFragment extends Fragment {
1004
+ constructor(guard, inputs, payable) {
1005
+ super(guard, "fallback", inputs);
1006
+ Object.defineProperty(this, internal, { value: FallbackFragmentInternal });
1007
+ defineProperties(this, { payable });
1008
+ }
1009
+ /**
1010
+ * Returns a string representation of this fallback as %%format%%.
1011
+ */
1012
+ format(format) {
1013
+ const type = ((this.inputs.length === 0) ? "receive" : "fallback");
1014
+ if (format === "json") {
1015
+ const stateMutability = (this.payable ? "payable" : "nonpayable");
1016
+ return JSON.stringify({ type, stateMutability });
1017
+ }
1018
+ return `${type}()${this.payable ? " payable" : ""}`;
1019
+ }
1020
+ /**
1021
+ * Returns a new **FallbackFragment** for %%obj%%.
1022
+ */
1023
+ static from(obj) {
1024
+ if (FallbackFragment.isFragment(obj)) {
1025
+ return obj;
1026
+ }
1027
+ if (typeof (obj) === "string") {
1028
+ try {
1029
+ return FallbackFragment.from(lex(obj));
1030
+ }
1031
+ catch (error) {
1032
+ assertArgument(false, "invalid fallback fragment", "obj", obj);
1033
+ }
1034
+ }
1035
+ else if (obj instanceof TokenString) {
1036
+ const errorObj = obj.toString();
1037
+ const topIsValid = obj.peekKeyword(setify(["fallback", "receive"]));
1038
+ assertArgument(topIsValid, "type must be fallback or receive", "obj", errorObj);
1039
+ const type = obj.popKeyword(setify(["fallback", "receive"]));
1040
+ // receive()
1041
+ if (type === "receive") {
1042
+ const inputs = consumeParams(obj);
1043
+ assertArgument(inputs.length === 0, `receive cannot have arguments`, "obj.inputs", inputs);
1044
+ consumeKeywords(obj, setify(["payable"]));
1045
+ consumeEoi(obj);
1046
+ return new FallbackFragment(_guard, [], true);
1047
+ }
1048
+ // fallback() [payable]
1049
+ // fallback(bytes) [payable] returns (bytes)
1050
+ let inputs = consumeParams(obj);
1051
+ if (inputs.length) {
1052
+ assertArgument(inputs.length === 1 && inputs[0].type === "bytes", "invalid fallback inputs", "obj.inputs", inputs.map((i) => i.format("minimal")).join(", "));
1053
+ }
1054
+ else {
1055
+ inputs = [ParamType.from("bytes")];
1056
+ }
1057
+ const mutability = consumeMutability(obj);
1058
+ assertArgument(mutability === "nonpayable" || mutability === "payable", "fallback cannot be constants", "obj.stateMutability", mutability);
1059
+ if (consumeKeywords(obj, setify(["returns"])).has("returns")) {
1060
+ const outputs = consumeParams(obj);
1061
+ assertArgument(outputs.length === 1 && outputs[0].type === "bytes", "invalid fallback outputs", "obj.outputs", outputs.map((i) => i.format("minimal")).join(", "));
1062
+ }
1063
+ consumeEoi(obj);
1064
+ return new FallbackFragment(_guard, inputs, mutability === "payable");
1065
+ }
1066
+ if (obj.type === "receive") {
1067
+ return new FallbackFragment(_guard, [], true);
1068
+ }
1069
+ if (obj.type === "fallback") {
1070
+ const inputs = [ParamType.from("bytes")];
1071
+ const payable = (obj.stateMutability === "payable");
1072
+ return new FallbackFragment(_guard, inputs, payable);
1073
+ }
1074
+ assertArgument(false, "invalid fallback description", "obj", obj);
1075
+ }
1076
+ /**
1077
+ * Returns ``true`` and provides a type guard if %%value%% is a
1078
+ * **FallbackFragment**.
1079
+ */
1080
+ static isFragment(value) {
1081
+ return (value && value[internal] === FallbackFragmentInternal);
1082
+ }
1083
+ }
1084
+ /**
1085
+ * A Fragment which represents a method.
1086
+ */
1087
+ export class FunctionFragment extends NamedFragment {
1088
+ /**
1089
+ * @private
1090
+ */
1091
+ constructor(guard, name, stateMutability, inputs, outputs, gas) {
1092
+ super(guard, "function", name, inputs);
1093
+ Object.defineProperty(this, internal, { value: FunctionFragmentInternal });
1094
+ outputs = Object.freeze(outputs.slice());
1095
+ const constant = (stateMutability === "view" || stateMutability === "pure");
1096
+ const payable = (stateMutability === "payable");
1097
+ defineProperties(this, { constant, gas, outputs, payable, stateMutability });
1098
+ }
1099
+ /**
1100
+ * The Function selector.
1101
+ */
1102
+ get selector() {
1103
+ return id(this.format("sighash")).substring(0, 10);
1104
+ }
1105
+ /**
1106
+ * Returns a string representation of this function as %%format%%.
1107
+ */
1108
+ format(format) {
1109
+ if (format == null) {
1110
+ format = "sighash";
1111
+ }
1112
+ if (format === "json") {
1113
+ return JSON.stringify({
1114
+ type: "function",
1115
+ name: this.name,
1116
+ constant: this.constant,
1117
+ stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
1118
+ payable: this.payable,
1119
+ gas: ((this.gas != null) ? this.gas : undefined),
1120
+ inputs: this.inputs.map((i) => JSON.parse(i.format(format))),
1121
+ outputs: this.outputs.map((o) => JSON.parse(o.format(format))),
1122
+ });
1123
+ }
1124
+ const result = [];
1125
+ if (format !== "sighash") {
1126
+ result.push("function");
1127
+ }
1128
+ result.push(this.name + joinParams(format, this.inputs));
1129
+ if (format !== "sighash") {
1130
+ if (this.stateMutability !== "nonpayable") {
1131
+ result.push(this.stateMutability);
1132
+ }
1133
+ if (this.outputs && this.outputs.length) {
1134
+ result.push("returns");
1135
+ result.push(joinParams(format, this.outputs));
1136
+ }
1137
+ if (this.gas != null) {
1138
+ result.push(`@${this.gas.toString()}`);
1139
+ }
1140
+ }
1141
+ return result.join(" ");
1142
+ }
1143
+ /**
1144
+ * Return the selector for a function with %%name%% and %%params%%.
1145
+ */
1146
+ static getSelector(name, params) {
1147
+ params = (params || []).map((p) => ParamType.from(p));
1148
+ const fragment = new FunctionFragment(_guard, name, "view", params, [], null);
1149
+ return fragment.selector;
1150
+ }
1151
+ /**
1152
+ * Returns a new **FunctionFragment** for %%obj%%.
1153
+ */
1154
+ static from(obj) {
1155
+ if (FunctionFragment.isFragment(obj)) {
1156
+ return obj;
1157
+ }
1158
+ if (typeof (obj) === "string") {
1159
+ try {
1160
+ return FunctionFragment.from(lex(obj));
1161
+ }
1162
+ catch (error) {
1163
+ assertArgument(false, "invalid function fragment", "obj", obj);
1164
+ }
1165
+ }
1166
+ else if (obj instanceof TokenString) {
1167
+ const name = consumeName("function", obj);
1168
+ const inputs = consumeParams(obj);
1169
+ const mutability = consumeMutability(obj);
1170
+ let outputs = [];
1171
+ if (consumeKeywords(obj, setify(["returns"])).has("returns")) {
1172
+ outputs = consumeParams(obj);
1173
+ }
1174
+ const gas = consumeGas(obj);
1175
+ consumeEoi(obj);
1176
+ return new FunctionFragment(_guard, name, mutability, inputs, outputs, gas);
1177
+ }
1178
+ let stateMutability = obj.stateMutability;
1179
+ // Use legacy Solidity ABI logic if stateMutability is missing
1180
+ if (stateMutability == null) {
1181
+ stateMutability = "payable";
1182
+ if (typeof (obj.constant) === "boolean") {
1183
+ stateMutability = "view";
1184
+ if (!obj.constant) {
1185
+ stateMutability = "payable";
1186
+ if (typeof (obj.payable) === "boolean" && !obj.payable) {
1187
+ stateMutability = "nonpayable";
1188
+ }
1189
+ }
1190
+ }
1191
+ else if (typeof (obj.payable) === "boolean" && !obj.payable) {
1192
+ stateMutability = "nonpayable";
1193
+ }
1194
+ }
1195
+ // @TODO: verifyState for stateMutability (e.g. throw if
1196
+ // payable: false but stateMutability is "nonpayable")
1197
+ return new FunctionFragment(_guard, obj.name, stateMutability, obj.inputs ? obj.inputs.map(ParamType.from) : [], obj.outputs ? obj.outputs.map(ParamType.from) : [], (obj.gas != null) ? obj.gas : null);
1198
+ }
1199
+ /**
1200
+ * Returns ``true`` and provides a type guard if %%value%% is a
1201
+ * **FunctionFragment**.
1202
+ */
1203
+ static isFragment(value) {
1204
+ return (value && value[internal] === FunctionFragmentInternal);
1205
+ }
1206
+ }
1207
+ /**
1208
+ * A Fragment which represents a structure.
1209
+ */
1210
+ export class StructFragment extends NamedFragment {
1211
+ /**
1212
+ * @private
1213
+ */
1214
+ constructor(guard, name, inputs) {
1215
+ super(guard, "struct", name, inputs);
1216
+ Object.defineProperty(this, internal, { value: StructFragmentInternal });
1217
+ }
1218
+ /**
1219
+ * Returns a string representation of this struct as %%format%%.
1220
+ */
1221
+ format() {
1222
+ throw new Error("@TODO");
1223
+ }
1224
+ /**
1225
+ * Returns a new **StructFragment** for %%obj%%.
1226
+ */
1227
+ static from(obj) {
1228
+ if (typeof (obj) === "string") {
1229
+ try {
1230
+ return StructFragment.from(lex(obj));
1231
+ }
1232
+ catch (error) {
1233
+ assertArgument(false, "invalid struct fragment", "obj", obj);
1234
+ }
1235
+ }
1236
+ else if (obj instanceof TokenString) {
1237
+ const name = consumeName("struct", obj);
1238
+ const inputs = consumeParams(obj);
1239
+ consumeEoi(obj);
1240
+ return new StructFragment(_guard, name, inputs);
1241
+ }
1242
+ return new StructFragment(_guard, obj.name, obj.inputs ? obj.inputs.map(ParamType.from) : []);
1243
+ }
1244
+ // @TODO: fix this return type
1245
+ /**
1246
+ * Returns ``true`` and provides a type guard if %%value%% is a
1247
+ * **StructFragment**.
1248
+ */
1249
+ static isFragment(value) {
1250
+ return (value && value[internal] === StructFragmentInternal);
1251
+ }
1252
+ }