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,990 @@
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
+ * The Interface class is a low-level class that accepts an
9
+ * ABI and provides all the necessary functionality to encode
10
+ * and decode paramaters to and results from methods, events
11
+ * and errors.
12
+ *
13
+ * It also provides several convenience methods to automatically
14
+ * search and find matching transactions and events to parse them.
15
+ *
16
+ * @_subsection api/abi:Interfaces [interfaces]
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 _Interface_instances, _Interface_errors, _Interface_events, _Interface_functions, _Interface_abiCoder, _Interface_getFunction, _Interface_getEvent;
30
+ import { id, keccak256 } from "./utils/index.js";
31
+ import { concat, dataSlice, getBigInt, getBytes, getBytesCopy, hexlify, zeroPadBytes, zeroPadValue, isHexString, defineProperties, assertArgument, toBeHex, assert } from "./utils/index.js";
32
+ import { AbiCoder } from "./abi-coder.js";
33
+ import { checkResultErrors, Result } from "./coders/abstract-coder.js";
34
+ import { ConstructorFragment, ErrorFragment, EventFragment, Fragment, FunctionFragment, ParamType } from "./fragments.js";
35
+ import { Typed } from "./typed.js";
36
+ export { checkResultErrors, Result };
37
+ /**
38
+ * When using the [[Interface-parseLog]] to automatically match a Log to its event
39
+ * for parsing, a **LogDescription** is returned.
40
+ */
41
+ export class LogDescription {
42
+ /**
43
+ * @_ignore:
44
+ */
45
+ constructor(fragment, topic, args) {
46
+ const name = fragment.name, signature = fragment.format();
47
+ defineProperties(this, {
48
+ fragment, name, signature, topic, args
49
+ });
50
+ }
51
+ }
52
+ /**
53
+ * When using the [[Interface-parseTransaction]] to automatically match
54
+ * a transaction data to its function for parsing,
55
+ * a **TransactionDescription** is returned.
56
+ */
57
+ export class TransactionDescription {
58
+ /**
59
+ * @_ignore:
60
+ */
61
+ constructor(fragment, selector, args, value) {
62
+ const name = fragment.name, signature = fragment.format();
63
+ defineProperties(this, {
64
+ fragment, name, args, signature, selector, value
65
+ });
66
+ }
67
+ }
68
+ /**
69
+ * When using the [[Interface-parseError]] to automatically match an
70
+ * error for a call result for parsing, an **ErrorDescription** is returned.
71
+ */
72
+ export class ErrorDescription {
73
+ /**
74
+ * @_ignore:
75
+ */
76
+ constructor(fragment, selector, args) {
77
+ const name = fragment.name, signature = fragment.format();
78
+ defineProperties(this, {
79
+ fragment, name, args, signature, selector
80
+ });
81
+ }
82
+ }
83
+ /**
84
+ * An **Indexed** is used as a value when a value that does not
85
+ * fit within a topic (i.e. not a fixed-length, 32-byte type). It
86
+ * is the ``keccak256`` of the value, and used for types such as
87
+ * arrays, tuples, bytes and strings.
88
+ */
89
+ export class Indexed {
90
+ /**
91
+ * @_ignore:
92
+ */
93
+ constructor(hash) {
94
+ defineProperties(this, { hash, _isIndexed: true });
95
+ }
96
+ /**
97
+ * Returns ``true`` if %%value%% is an **Indexed**.
98
+ *
99
+ * This provides a Type Guard for property access.
100
+ */
101
+ static isIndexed(value) {
102
+ return !!(value && value._isIndexed);
103
+ }
104
+ }
105
+ // https://docs.soliditylang.org/en/v0.8.13/control-structures.html?highlight=panic#panic-via-assert-and-error-via-require
106
+ const PanicReasons = {
107
+ "0": "generic panic",
108
+ "1": "assert(false)",
109
+ "17": "arithmetic overflow",
110
+ "18": "division or modulo by zero",
111
+ "33": "enum overflow",
112
+ "34": "invalid encoded storage byte array accessed",
113
+ "49": "out-of-bounds array access; popping on an empty array",
114
+ "50": "out-of-bounds access of an array or bytesN",
115
+ "65": "out of memory",
116
+ "81": "uninitialized function",
117
+ };
118
+ const BuiltinErrors = {
119
+ "0x08c379a0": {
120
+ signature: "Error(string)",
121
+ name: "Error",
122
+ inputs: ["string"],
123
+ reason: (message) => {
124
+ return `reverted with reason string ${JSON.stringify(message)}`;
125
+ }
126
+ },
127
+ "0x4e487b71": {
128
+ signature: "Panic(uint256)",
129
+ name: "Panic",
130
+ inputs: ["uint256"],
131
+ reason: (code) => {
132
+ let reason = "unknown panic code";
133
+ if (code >= 0 && code <= 0xff && PanicReasons[code.toString()]) {
134
+ reason = PanicReasons[code.toString()];
135
+ }
136
+ return `reverted with panic code 0x${code.toString(16)} (${reason})`;
137
+ }
138
+ }
139
+ };
140
+ /**
141
+ * An Interface abstracts many of the low-level details for
142
+ * encoding and decoding the data on the blockchain.
143
+ *
144
+ * An ABI provides information on how to encode data to send to
145
+ * a Contract, how to decode the results and events and how to
146
+ * interpret revert errors.
147
+ *
148
+ * The ABI can be specified by [any supported format](InterfaceAbi).
149
+ */
150
+ export class Interface {
151
+ /**
152
+ * Create a new Interface for the %%fragments%%.
153
+ */
154
+ constructor(fragments) {
155
+ _Interface_instances.add(this);
156
+ _Interface_errors.set(this, void 0);
157
+ _Interface_events.set(this, void 0);
158
+ _Interface_functions.set(this, void 0);
159
+ // #structs: Map<string, StructFragment>;
160
+ _Interface_abiCoder.set(this, void 0);
161
+ let abi = [];
162
+ if (typeof (fragments) === "string") {
163
+ abi = JSON.parse(fragments);
164
+ }
165
+ else {
166
+ abi = fragments;
167
+ }
168
+ __classPrivateFieldSet(this, _Interface_functions, new Map(), "f");
169
+ __classPrivateFieldSet(this, _Interface_errors, new Map(), "f");
170
+ __classPrivateFieldSet(this, _Interface_events, new Map(), "f");
171
+ // this.#structs = new Map();
172
+ const frags = [];
173
+ for (const a of abi) {
174
+ try {
175
+ frags.push(Fragment.from(a));
176
+ }
177
+ catch (error) {
178
+ console.log("EE", error);
179
+ }
180
+ }
181
+ defineProperties(this, {
182
+ fragments: Object.freeze(frags)
183
+ });
184
+ let fallback = null;
185
+ let receive = false;
186
+ __classPrivateFieldSet(this, _Interface_abiCoder, this.getAbiCoder(), "f");
187
+ // Add all fragments by their signature
188
+ this.fragments.forEach((fragment, index) => {
189
+ let bucket;
190
+ switch (fragment.type) {
191
+ case "constructor":
192
+ if (this.deploy) {
193
+ console.log("duplicate definition - constructor");
194
+ return;
195
+ }
196
+ //checkNames(fragment, "input", fragment.inputs);
197
+ defineProperties(this, { deploy: fragment });
198
+ return;
199
+ case "fallback":
200
+ if (fragment.inputs.length === 0) {
201
+ receive = true;
202
+ }
203
+ else {
204
+ assertArgument(!fallback || fragment.payable !== fallback.payable, "conflicting fallback fragments", `fragments[${index}]`, fragment);
205
+ fallback = fragment;
206
+ receive = fallback.payable;
207
+ }
208
+ return;
209
+ case "function":
210
+ //checkNames(fragment, "input", fragment.inputs);
211
+ //checkNames(fragment, "output", (<FunctionFragment>fragment).outputs);
212
+ bucket = __classPrivateFieldGet(this, _Interface_functions, "f");
213
+ break;
214
+ case "event":
215
+ //checkNames(fragment, "input", fragment.inputs);
216
+ bucket = __classPrivateFieldGet(this, _Interface_events, "f");
217
+ break;
218
+ case "error":
219
+ bucket = __classPrivateFieldGet(this, _Interface_errors, "f");
220
+ break;
221
+ default:
222
+ return;
223
+ }
224
+ // Two identical entries; ignore it
225
+ const signature = fragment.format();
226
+ if (bucket.has(signature)) {
227
+ return;
228
+ }
229
+ bucket.set(signature, fragment);
230
+ });
231
+ // If we do not have a constructor add a default
232
+ if (!this.deploy) {
233
+ defineProperties(this, {
234
+ deploy: ConstructorFragment.from("constructor()")
235
+ });
236
+ }
237
+ defineProperties(this, { fallback, receive });
238
+ }
239
+ /**
240
+ * Returns the entire Human-Readable ABI, as an array of
241
+ * signatures, optionally as %%minimal%% strings, which
242
+ * removes parameter names and unneceesary spaces.
243
+ */
244
+ format(minimal) {
245
+ const format = (minimal ? "minimal" : "full");
246
+ const abi = this.fragments.map((f) => f.format(format));
247
+ return abi;
248
+ }
249
+ /**
250
+ * Return the JSON-encoded ABI. This is the format Solidiy
251
+ * returns.
252
+ */
253
+ formatJson() {
254
+ const abi = this.fragments.map((f) => f.format("json"));
255
+ // We need to re-bundle the JSON fragments a bit
256
+ return JSON.stringify(abi.map((j) => JSON.parse(j)));
257
+ }
258
+ /**
259
+ * The ABI coder that will be used to encode and decode binary
260
+ * data.
261
+ */
262
+ getAbiCoder() {
263
+ return AbiCoder.defaultAbiCoder();
264
+ }
265
+ /**
266
+ * Get the function name for %%key%%, which may be a function selector,
267
+ * function name or function signature that belongs to the ABI.
268
+ */
269
+ getFunctionName(key) {
270
+ const fragment = __classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getFunction).call(this, key, null, false);
271
+ assertArgument(fragment, "no matching function", "key", key);
272
+ return fragment.name;
273
+ }
274
+ /**
275
+ * Returns true if %%key%% (a function selector, function name or
276
+ * function signature) is present in the ABI.
277
+ *
278
+ * In the case of a function name, the name may be ambiguous, so
279
+ * accessing the [[FunctionFragment]] may require refinement.
280
+ */
281
+ hasFunction(key) {
282
+ return !!__classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getFunction).call(this, key, null, false);
283
+ }
284
+ /**
285
+ * Get the [[FunctionFragment]] for %%key%%, which may be a function
286
+ * selector, function name or function signature that belongs to the ABI.
287
+ *
288
+ * If %%values%% is provided, it will use the Typed API to handle
289
+ * ambiguous cases where multiple functions match by name.
290
+ *
291
+ * If the %%key%% and %%values%% do not refine to a single function in
292
+ * the ABI, this will throw.
293
+ */
294
+ getFunction(key, values) {
295
+ return __classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getFunction).call(this, key, values || null, true);
296
+ }
297
+ /**
298
+ * Iterate over all functions, calling %%callback%%, sorted by their name.
299
+ */
300
+ forEachFunction(callback) {
301
+ const names = Array.from(__classPrivateFieldGet(this, _Interface_functions, "f").keys());
302
+ names.sort((a, b) => a.localeCompare(b));
303
+ for (let i = 0; i < names.length; i++) {
304
+ const name = names[i];
305
+ callback((__classPrivateFieldGet(this, _Interface_functions, "f").get(name)), i);
306
+ }
307
+ }
308
+ /**
309
+ * Get the event name for %%key%%, which may be a topic hash,
310
+ * event name or event signature that belongs to the ABI.
311
+ */
312
+ getEventName(key) {
313
+ const fragment = __classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getEvent).call(this, key, null, false);
314
+ assertArgument(fragment, "no matching event", "key", key);
315
+ return fragment.name;
316
+ }
317
+ /**
318
+ * Returns true if %%key%% (an event topic hash, event name or
319
+ * event signature) is present in the ABI.
320
+ *
321
+ * In the case of an event name, the name may be ambiguous, so
322
+ * accessing the [[EventFragment]] may require refinement.
323
+ */
324
+ hasEvent(key) {
325
+ return !!__classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getEvent).call(this, key, null, false);
326
+ }
327
+ /**
328
+ * Get the [[EventFragment]] for %%key%%, which may be a topic hash,
329
+ * event name or event signature that belongs to the ABI.
330
+ *
331
+ * If %%values%% is provided, it will use the Typed API to handle
332
+ * ambiguous cases where multiple events match by name.
333
+ *
334
+ * If the %%key%% and %%values%% do not refine to a single event in
335
+ * the ABI, this will throw.
336
+ */
337
+ getEvent(key, values) {
338
+ return __classPrivateFieldGet(this, _Interface_instances, "m", _Interface_getEvent).call(this, key, values || null, true);
339
+ }
340
+ /**
341
+ * Iterate over all events, calling %%callback%%, sorted by their name.
342
+ */
343
+ forEachEvent(callback) {
344
+ const names = Array.from(__classPrivateFieldGet(this, _Interface_events, "f").keys());
345
+ names.sort((a, b) => a.localeCompare(b));
346
+ for (let i = 0; i < names.length; i++) {
347
+ const name = names[i];
348
+ callback((__classPrivateFieldGet(this, _Interface_events, "f").get(name)), i);
349
+ }
350
+ }
351
+ /**
352
+ * Get the [[ErrorFragment]] for %%key%%, which may be an error
353
+ * selector, error name or error signature that belongs to the ABI.
354
+ *
355
+ * If %%values%% is provided, it will use the Typed API to handle
356
+ * ambiguous cases where multiple errors match by name.
357
+ *
358
+ * If the %%key%% and %%values%% do not refine to a single error in
359
+ * the ABI, this will throw.
360
+ */
361
+ getError(key, values) {
362
+ if (isHexString(key)) {
363
+ const selector = key.toLowerCase();
364
+ if (BuiltinErrors[selector]) {
365
+ return ErrorFragment.from(BuiltinErrors[selector].signature);
366
+ }
367
+ for (const fragment of __classPrivateFieldGet(this, _Interface_errors, "f").values()) {
368
+ if (selector === fragment.selector) {
369
+ return fragment;
370
+ }
371
+ }
372
+ return null;
373
+ }
374
+ // It is a bare name, look up the function (will return null if ambiguous)
375
+ if (key.indexOf("(") === -1) {
376
+ const matching = [];
377
+ for (const [name, fragment] of __classPrivateFieldGet(this, _Interface_errors, "f")) {
378
+ if (name.split("(" /* fix:) */)[0] === key) {
379
+ matching.push(fragment);
380
+ }
381
+ }
382
+ if (matching.length === 0) {
383
+ if (key === "Error") {
384
+ return ErrorFragment.from("error Error(string)");
385
+ }
386
+ if (key === "Panic") {
387
+ return ErrorFragment.from("error Panic(uint256)");
388
+ }
389
+ return null;
390
+ }
391
+ else if (matching.length > 1) {
392
+ const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", ");
393
+ assertArgument(false, `ambiguous error description (i.e. ${matchStr})`, "name", key);
394
+ }
395
+ return matching[0];
396
+ }
397
+ // Normalize the signature and lookup the function
398
+ key = ErrorFragment.from(key).format();
399
+ if (key === "Error(string)") {
400
+ return ErrorFragment.from("error Error(string)");
401
+ }
402
+ if (key === "Panic(uint256)") {
403
+ return ErrorFragment.from("error Panic(uint256)");
404
+ }
405
+ const result = __classPrivateFieldGet(this, _Interface_errors, "f").get(key);
406
+ if (result) {
407
+ return result;
408
+ }
409
+ return null;
410
+ }
411
+ /**
412
+ * Iterate over all errors, calling %%callback%%, sorted by their name.
413
+ */
414
+ forEachError(callback) {
415
+ const names = Array.from(__classPrivateFieldGet(this, _Interface_errors, "f").keys());
416
+ names.sort((a, b) => a.localeCompare(b));
417
+ for (let i = 0; i < names.length; i++) {
418
+ const name = names[i];
419
+ callback((__classPrivateFieldGet(this, _Interface_errors, "f").get(name)), i);
420
+ }
421
+ }
422
+ // Get the 4-byte selector used by Solidity to identify a function
423
+ /*
424
+ getSelector(fragment: ErrorFragment | FunctionFragment): string {
425
+ if (typeof(fragment) === "string") {
426
+ const matches: Array<Fragment> = [ ];
427
+
428
+ try { matches.push(this.getFunction(fragment)); } catch (error) { }
429
+ try { matches.push(this.getError(<string>fragment)); } catch (_) { }
430
+
431
+ if (matches.length === 0) {
432
+ logger.throwArgumentError("unknown fragment", "key", fragment);
433
+ } else if (matches.length > 1) {
434
+ logger.throwArgumentError("ambiguous fragment matches function and error", "key", fragment);
435
+ }
436
+
437
+ fragment = matches[0];
438
+ }
439
+
440
+ return dataSlice(id(fragment.format()), 0, 4);
441
+ }
442
+ */
443
+ // Get the 32-byte topic hash used by Solidity to identify an event
444
+ /*
445
+ getEventTopic(fragment: EventFragment): string {
446
+ //if (typeof(fragment) === "string") { fragment = this.getEvent(eventFragment); }
447
+ return id(fragment.format());
448
+ }
449
+ */
450
+ _decodeParams(params, data) {
451
+ return __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(params, data);
452
+ }
453
+ _encodeParams(params, values) {
454
+ return __classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(params, values);
455
+ }
456
+ /**
457
+ * Encodes a ``tx.data`` object for deploying the Contract with
458
+ * the %%values%% as the constructor arguments.
459
+ */
460
+ encodeDeploy(values) {
461
+ return this._encodeParams(this.deploy.inputs, values || []);
462
+ }
463
+ /**
464
+ * Decodes the result %%data%% (e.g. from an ``eth_call``) for the
465
+ * specified error (see [[getError]] for valid values for
466
+ * %%key%%).
467
+ *
468
+ * Most developers should prefer the [[parseCallResult]] method instead,
469
+ * which will automatically detect a ``CALL_EXCEPTION`` and throw the
470
+ * corresponding error.
471
+ */
472
+ decodeErrorResult(fragment, data) {
473
+ if (typeof (fragment) === "string") {
474
+ const f = this.getError(fragment);
475
+ assertArgument(f, "unknown error", "fragment", fragment);
476
+ fragment = f;
477
+ }
478
+ assertArgument(dataSlice(data, 0, 4) === fragment.selector, `data signature does not match error ${fragment.name}.`, "data", data);
479
+ return this._decodeParams(fragment.inputs, dataSlice(data, 4));
480
+ }
481
+ /**
482
+ * Encodes the transaction revert data for a call result that
483
+ * reverted from the the Contract with the sepcified %%error%%
484
+ * (see [[getError]] for valid values for %%fragment%%) with the %%values%%.
485
+ *
486
+ * This is generally not used by most developers, unless trying to mock
487
+ * a result from a Contract.
488
+ */
489
+ encodeErrorResult(fragment, values) {
490
+ if (typeof (fragment) === "string") {
491
+ const f = this.getError(fragment);
492
+ assertArgument(f, "unknown error", "fragment", fragment);
493
+ fragment = f;
494
+ }
495
+ return concat([
496
+ fragment.selector,
497
+ this._encodeParams(fragment.inputs, values || [])
498
+ ]);
499
+ }
500
+ /**
501
+ * Decodes the %%data%% from a transaction ``tx.data`` for
502
+ * the function specified (see [[getFunction]] for valid values
503
+ * for %%fragment%%).
504
+ *
505
+ * Most developers should prefer the [[parseTransaction]] method
506
+ * instead, which will automatically detect the fragment.
507
+ */
508
+ decodeFunctionData(fragment, data) {
509
+ if (typeof (fragment) === "string") {
510
+ const f = this.getFunction(fragment);
511
+ assertArgument(f, "unknown function", "fragment", fragment);
512
+ fragment = f;
513
+ }
514
+ assertArgument(dataSlice(data, 0, 4) === fragment.selector, `data signature does not match function ${fragment.name}.`, "data", data);
515
+ return this._decodeParams(fragment.inputs, dataSlice(data, 4));
516
+ }
517
+ /**
518
+ * Encodes the ``tx.data`` for a transaction that calls the function
519
+ * specified (see [[getFunction]] for valid values for %%fragment%%) with
520
+ * the %%values%%.
521
+ */
522
+ encodeFunctionData(fragment, values) {
523
+ if (typeof (fragment) === "string") {
524
+ const f = this.getFunction(fragment);
525
+ assertArgument(f, "unknown function", "fragment", fragment);
526
+ fragment = f;
527
+ }
528
+ return concat([
529
+ fragment.selector,
530
+ this._encodeParams(fragment.inputs, values || [])
531
+ ]);
532
+ }
533
+ /**
534
+ * Decodes the result %%data%% (e.g. from an ``eth_call``) for the
535
+ * specified function (see [[getFunction]] for valid values for
536
+ * %%key%%).
537
+ *
538
+ * Most developers should prefer the [[parseCallResult]] method instead,
539
+ * which will automatically detect a ``CALL_EXCEPTION`` and throw the
540
+ * corresponding error.
541
+ */
542
+ decodeFunctionResult(fragment, data) {
543
+ if (typeof (fragment) === "string") {
544
+ const f = this.getFunction(fragment);
545
+ assertArgument(f, "unknown function", "fragment", fragment);
546
+ fragment = f;
547
+ }
548
+ let message = "invalid length for result data";
549
+ const bytes = getBytesCopy(data);
550
+ if ((bytes.length % 32) === 0) {
551
+ try {
552
+ return __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(fragment.outputs, bytes);
553
+ }
554
+ catch (error) {
555
+ message = "could not decode result data";
556
+ }
557
+ }
558
+ // Call returned data with no error, but the data is junk
559
+ assert(false, message, "BAD_DATA", {
560
+ value: hexlify(bytes),
561
+ info: { method: fragment.name, signature: fragment.format() }
562
+ });
563
+ }
564
+ /**
565
+ * Encodes the result data (e.g. from an ``eth_call``) for the
566
+ * specified function (see [[getFunction]] for valid values
567
+ * for %%fragment%%) with %%values%%.
568
+ *
569
+ * This is generally not used by most developers, unless trying to mock
570
+ * a result from a Contract.
571
+ */
572
+ encodeFunctionResult(fragment, values) {
573
+ if (typeof (fragment) === "string") {
574
+ const f = this.getFunction(fragment);
575
+ assertArgument(f, "unknown function", "fragment", fragment);
576
+ fragment = f;
577
+ }
578
+ return hexlify(__classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(fragment.outputs, values || []));
579
+ }
580
+ /*
581
+ spelunk(inputs: Array<ParamType>, values: ReadonlyArray<any>, processfunc: (type: string, value: any) => Promise<any>): Promise<Array<any>> {
582
+ const promises: Array<Promise<>> = [ ];
583
+ const process = function(type: ParamType, value: any): any {
584
+ if (type.baseType === "array") {
585
+ return descend(type.child
586
+ }
587
+ if (type. === "address") {
588
+ }
589
+ };
590
+
591
+ const descend = function (inputs: Array<ParamType>, values: ReadonlyArray<any>) {
592
+ if (inputs.length !== values.length) { throw new Error("length mismatch"); }
593
+
594
+ };
595
+
596
+ const result: Array<any> = [ ];
597
+ values.forEach((value, index) => {
598
+ if (value == null) {
599
+ topics.push(null);
600
+ } else if (param.baseType === "array" || param.baseType === "tuple") {
601
+ logger.throwArgumentError("filtering with tuples or arrays not supported", ("contract." + param.name), value);
602
+ } else if (Array.isArray(value)) {
603
+ topics.push(value.map((value) => encodeTopic(param, value)));
604
+ } else {
605
+ topics.push(encodeTopic(param, value));
606
+ }
607
+ });
608
+ }
609
+ */
610
+ // Create the filter for the event with search criteria (e.g. for eth_filterLog)
611
+ encodeFilterTopics(fragment, values) {
612
+ if (typeof (fragment) === "string") {
613
+ const f = this.getEvent(fragment);
614
+ assertArgument(f, "unknown event", "eventFragment", fragment);
615
+ fragment = f;
616
+ }
617
+ assert(values.length <= fragment.inputs.length, `too many arguments for ${fragment.format()}`, "UNEXPECTED_ARGUMENT", { count: values.length, expectedCount: fragment.inputs.length });
618
+ const topics = [];
619
+ if (!fragment.anonymous) {
620
+ topics.push(fragment.topicHash);
621
+ }
622
+ // @TODO: Use the coders for this; to properly support tuples, etc.
623
+ const encodeTopic = (param, value) => {
624
+ if (param.type === "string") {
625
+ return id(value);
626
+ }
627
+ else if (param.type === "bytes") {
628
+ return keccak256(value);
629
+ }
630
+ if (param.type === "bool" && typeof (value) === "boolean") {
631
+ value = (value ? "0x01" : "0x00");
632
+ }
633
+ else if (param.type.match(/^u?int/)) {
634
+ value = toBeHex(value); // @TODO: Should this toTwos??
635
+ }
636
+ else if (param.type.match(/^bytes/)) {
637
+ value = zeroPadBytes(value, 32);
638
+ }
639
+ else if (param.type === "address") {
640
+ // Check addresses are valid
641
+ __classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(["address"], [value]);
642
+ }
643
+ return zeroPadValue(hexlify(value), 32);
644
+ };
645
+ values.forEach((value, index) => {
646
+ const param = fragment.inputs[index];
647
+ if (!param.indexed) {
648
+ assertArgument(value == null, "cannot filter non-indexed parameters; must be null", ("contract." + param.name), value);
649
+ return;
650
+ }
651
+ if (value == null) {
652
+ topics.push(null);
653
+ }
654
+ else if (param.baseType === "array" || param.baseType === "tuple") {
655
+ assertArgument(false, "filtering with tuples or arrays not supported", ("contract." + param.name), value);
656
+ }
657
+ else if (Array.isArray(value)) {
658
+ topics.push(value.map((value) => encodeTopic(param, value)));
659
+ }
660
+ else {
661
+ topics.push(encodeTopic(param, value));
662
+ }
663
+ });
664
+ // Trim off trailing nulls
665
+ while (topics.length && topics[topics.length - 1] === null) {
666
+ topics.pop();
667
+ }
668
+ return topics;
669
+ }
670
+ encodeEventLog(fragment, values) {
671
+ if (typeof (fragment) === "string") {
672
+ const f = this.getEvent(fragment);
673
+ assertArgument(f, "unknown event", "eventFragment", fragment);
674
+ fragment = f;
675
+ }
676
+ const topics = [];
677
+ const dataTypes = [];
678
+ const dataValues = [];
679
+ if (!fragment.anonymous) {
680
+ topics.push(fragment.topicHash);
681
+ }
682
+ assertArgument(values.length === fragment.inputs.length, "event arguments/values mismatch", "values", values);
683
+ fragment.inputs.forEach((param, index) => {
684
+ const value = values[index];
685
+ if (param.indexed) {
686
+ if (param.type === "string") {
687
+ topics.push(id(value));
688
+ }
689
+ else if (param.type === "bytes") {
690
+ topics.push(keccak256(value));
691
+ }
692
+ else if (param.baseType === "tuple" || param.baseType === "array") {
693
+ // @TODO
694
+ throw new Error("not implemented");
695
+ }
696
+ else {
697
+ topics.push(__classPrivateFieldGet(this, _Interface_abiCoder, "f").encode([param.type], [value]));
698
+ }
699
+ }
700
+ else {
701
+ dataTypes.push(param);
702
+ dataValues.push(value);
703
+ }
704
+ });
705
+ return {
706
+ data: __classPrivateFieldGet(this, _Interface_abiCoder, "f").encode(dataTypes, dataValues),
707
+ topics: topics
708
+ };
709
+ }
710
+ // Decode a filter for the event and the search criteria
711
+ decodeEventLog(fragment, data, topics) {
712
+ if (typeof (fragment) === "string") {
713
+ const f = this.getEvent(fragment);
714
+ assertArgument(f, "unknown event", "eventFragment", fragment);
715
+ fragment = f;
716
+ }
717
+ if (topics != null && !fragment.anonymous) {
718
+ const eventTopic = fragment.topicHash;
719
+ assertArgument(isHexString(topics[0], 32) && topics[0].toLowerCase() === eventTopic, "fragment/topic mismatch", "topics[0]", topics[0]);
720
+ topics = topics.slice(1);
721
+ }
722
+ const indexed = [];
723
+ const nonIndexed = [];
724
+ const dynamic = [];
725
+ fragment.inputs.forEach((param, index) => {
726
+ if (param.indexed) {
727
+ if (param.type === "string" || param.type === "bytes" || param.baseType === "tuple" || param.baseType === "array") {
728
+ indexed.push(ParamType.from({ type: "bytes32", name: param.name }));
729
+ dynamic.push(true);
730
+ }
731
+ else {
732
+ indexed.push(param);
733
+ dynamic.push(false);
734
+ }
735
+ }
736
+ else {
737
+ nonIndexed.push(param);
738
+ dynamic.push(false);
739
+ }
740
+ });
741
+ const resultIndexed = (topics != null) ? __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(indexed, concat(topics)) : null;
742
+ const resultNonIndexed = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(nonIndexed, data, true);
743
+ //const result: (Array<any> & { [ key: string ]: any }) = [ ];
744
+ const values = [];
745
+ const keys = [];
746
+ let nonIndexedIndex = 0, indexedIndex = 0;
747
+ fragment.inputs.forEach((param, index) => {
748
+ let value = null;
749
+ if (param.indexed) {
750
+ if (resultIndexed == null) {
751
+ value = new Indexed(null);
752
+ }
753
+ else if (dynamic[index]) {
754
+ value = new Indexed(resultIndexed[indexedIndex++]);
755
+ }
756
+ else {
757
+ try {
758
+ value = resultIndexed[indexedIndex++];
759
+ }
760
+ catch (error) {
761
+ value = error;
762
+ }
763
+ }
764
+ }
765
+ else {
766
+ try {
767
+ value = resultNonIndexed[nonIndexedIndex++];
768
+ }
769
+ catch (error) {
770
+ value = error;
771
+ }
772
+ }
773
+ values.push(value);
774
+ keys.push(param.name || null);
775
+ });
776
+ return Result.fromItems(values, keys);
777
+ }
778
+ /**
779
+ * Parses a transaction, finding the matching function and extracts
780
+ * the parameter values along with other useful function details.
781
+ *
782
+ * If the matching function cannot be found, return null.
783
+ */
784
+ parseTransaction(tx) {
785
+ const data = getBytes(tx.data, "tx.data");
786
+ const value = getBigInt((tx.value != null) ? tx.value : 0, "tx.value");
787
+ const fragment = this.getFunction(hexlify(data.slice(0, 4)));
788
+ if (!fragment) {
789
+ return null;
790
+ }
791
+ const args = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(fragment.inputs, data.slice(4));
792
+ return new TransactionDescription(fragment, fragment.selector, args, value);
793
+ }
794
+ parseCallResult(data) {
795
+ throw new Error("@TODO");
796
+ }
797
+ /**
798
+ * Parses a receipt log, finding the matching event and extracts
799
+ * the parameter values along with other useful event details.
800
+ *
801
+ * If the matching event cannot be found, returns null.
802
+ */
803
+ parseLog(log) {
804
+ const fragment = this.getEvent(log.topics[0]);
805
+ if (!fragment || fragment.anonymous) {
806
+ return null;
807
+ }
808
+ // @TODO: If anonymous, and the only method, and the input count matches, should we parse?
809
+ // Probably not, because just because it is the only event in the ABI does
810
+ // not mean we have the full ABI; maybe just a fragment?
811
+ return new LogDescription(fragment, fragment.topicHash, this.decodeEventLog(fragment, log.data, log.topics));
812
+ }
813
+ /**
814
+ * Parses a revert data, finding the matching error and extracts
815
+ * the parameter values along with other useful error details.
816
+ *
817
+ * If the matching error cannot be found, returns null.
818
+ */
819
+ parseError(data) {
820
+ const hexData = hexlify(data);
821
+ const fragment = this.getError(dataSlice(hexData, 0, 4));
822
+ if (!fragment) {
823
+ return null;
824
+ }
825
+ const args = __classPrivateFieldGet(this, _Interface_abiCoder, "f").decode(fragment.inputs, dataSlice(hexData, 4));
826
+ return new ErrorDescription(fragment, fragment.selector, args);
827
+ }
828
+ /**
829
+ * Creates a new [[Interface]] from the ABI %%value%%.
830
+ *
831
+ * The %%value%% may be provided as an existing [[Interface]] object,
832
+ * a JSON-encoded ABI or any Human-Readable ABI format.
833
+ */
834
+ static from(value) {
835
+ // Already an Interface, which is immutable
836
+ if (value instanceof Interface) {
837
+ return value;
838
+ }
839
+ // JSON
840
+ if (typeof (value) === "string") {
841
+ return new Interface(JSON.parse(value));
842
+ }
843
+ // Maybe an interface from an older version, or from a symlinked copy
844
+ if (typeof (value.format) === "function") {
845
+ return new Interface(value.format("json"));
846
+ }
847
+ // Array of fragments
848
+ return new Interface(value);
849
+ }
850
+ }
851
+ _Interface_errors = new WeakMap(), _Interface_events = new WeakMap(), _Interface_functions = new WeakMap(), _Interface_abiCoder = new WeakMap(), _Interface_instances = new WeakSet(), _Interface_getFunction = function _Interface_getFunction(key, values, forceUnique) {
852
+ // Selector
853
+ if (isHexString(key)) {
854
+ const selector = key.toLowerCase();
855
+ for (const fragment of __classPrivateFieldGet(this, _Interface_functions, "f").values()) {
856
+ if (selector === fragment.selector) {
857
+ return fragment;
858
+ }
859
+ }
860
+ return null;
861
+ }
862
+ // It is a bare name, look up the function (will return null if ambiguous)
863
+ if (key.indexOf("(") === -1) {
864
+ const matching = [];
865
+ for (const [name, fragment] of __classPrivateFieldGet(this, _Interface_functions, "f")) {
866
+ if (name.split("(" /* fix:) */)[0] === key) {
867
+ matching.push(fragment);
868
+ }
869
+ }
870
+ if (values) {
871
+ const lastValue = (values.length > 0) ? values[values.length - 1] : null;
872
+ let valueLength = values.length;
873
+ let allowOptions = true;
874
+ if (Typed.isTyped(lastValue) && lastValue.type === "overrides") {
875
+ allowOptions = false;
876
+ valueLength--;
877
+ }
878
+ // Remove all matches that don't have a compatible length. The args
879
+ // may contain an overrides, so the match may have n or n - 1 parameters
880
+ for (let i = matching.length - 1; i >= 0; i--) {
881
+ const inputs = matching[i].inputs.length;
882
+ if (inputs !== valueLength && (!allowOptions || inputs !== valueLength - 1)) {
883
+ matching.splice(i, 1);
884
+ }
885
+ }
886
+ // Remove all matches that don't match the Typed signature
887
+ for (let i = matching.length - 1; i >= 0; i--) {
888
+ const inputs = matching[i].inputs;
889
+ for (let j = 0; j < values.length; j++) {
890
+ // Not a typed value
891
+ if (!Typed.isTyped(values[j])) {
892
+ continue;
893
+ }
894
+ // We are past the inputs
895
+ if (j >= inputs.length) {
896
+ if (values[j].type === "overrides") {
897
+ continue;
898
+ }
899
+ matching.splice(i, 1);
900
+ break;
901
+ }
902
+ // Make sure the value type matches the input type
903
+ if (values[j].type !== inputs[j].baseType) {
904
+ matching.splice(i, 1);
905
+ break;
906
+ }
907
+ }
908
+ }
909
+ }
910
+ // We found a single matching signature with an overrides, but the
911
+ // last value is something that cannot possibly be an options
912
+ if (matching.length === 1 && values && values.length !== matching[0].inputs.length) {
913
+ const lastArg = values[values.length - 1];
914
+ if (lastArg == null || Array.isArray(lastArg) || typeof (lastArg) !== "object") {
915
+ matching.splice(0, 1);
916
+ }
917
+ }
918
+ if (matching.length === 0) {
919
+ return null;
920
+ }
921
+ if (matching.length > 1 && forceUnique) {
922
+ const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", ");
923
+ assertArgument(false, `ambiguous function description (i.e. matches ${matchStr})`, "key", key);
924
+ }
925
+ return matching[0];
926
+ }
927
+ // Normalize the signature and lookup the function
928
+ const result = __classPrivateFieldGet(this, _Interface_functions, "f").get(FunctionFragment.from(key).format());
929
+ if (result) {
930
+ return result;
931
+ }
932
+ return null;
933
+ }, _Interface_getEvent = function _Interface_getEvent(key, values, forceUnique) {
934
+ // EventTopic
935
+ if (isHexString(key)) {
936
+ const eventTopic = key.toLowerCase();
937
+ for (const fragment of __classPrivateFieldGet(this, _Interface_events, "f").values()) {
938
+ if (eventTopic === fragment.topicHash) {
939
+ return fragment;
940
+ }
941
+ }
942
+ return null;
943
+ }
944
+ // It is a bare name, look up the function (will return null if ambiguous)
945
+ if (key.indexOf("(") === -1) {
946
+ const matching = [];
947
+ for (const [name, fragment] of __classPrivateFieldGet(this, _Interface_events, "f")) {
948
+ if (name.split("(" /* fix:) */)[0] === key) {
949
+ matching.push(fragment);
950
+ }
951
+ }
952
+ if (values) {
953
+ // Remove all matches that don't have a compatible length.
954
+ for (let i = matching.length - 1; i >= 0; i--) {
955
+ if (matching[i].inputs.length < values.length) {
956
+ matching.splice(i, 1);
957
+ }
958
+ }
959
+ // Remove all matches that don't match the Typed signature
960
+ for (let i = matching.length - 1; i >= 0; i--) {
961
+ const inputs = matching[i].inputs;
962
+ for (let j = 0; j < values.length; j++) {
963
+ // Not a typed value
964
+ if (!Typed.isTyped(values[j])) {
965
+ continue;
966
+ }
967
+ // Make sure the value type matches the input type
968
+ if (values[j].type !== inputs[j].baseType) {
969
+ matching.splice(i, 1);
970
+ break;
971
+ }
972
+ }
973
+ }
974
+ }
975
+ if (matching.length === 0) {
976
+ return null;
977
+ }
978
+ if (matching.length > 1 && forceUnique) {
979
+ const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", ");
980
+ assertArgument(false, `ambiguous event description (i.e. matches ${matchStr})`, "key", key);
981
+ }
982
+ return matching[0];
983
+ }
984
+ // Normalize the signature and lookup the function
985
+ const result = __classPrivateFieldGet(this, _Interface_events, "f").get(EventFragment.from(key).format());
986
+ if (result) {
987
+ return result;
988
+ }
989
+ return null;
990
+ };