ccxt 4.2.60 → 4.2.62

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 (160) hide show
  1. package/README.md +6 -5
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +11280 -3407
  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/bitget.js +74 -23
  12. package/dist/cjs/src/coinbase.js +108 -103
  13. package/dist/cjs/src/coinex.js +61 -1
  14. package/dist/cjs/src/hyperliquid.js +2035 -0
  15. package/dist/cjs/src/kraken.js +8 -2
  16. package/dist/cjs/src/krakenfutures.js +28 -0
  17. package/dist/cjs/src/kucoinfutures.js +2 -2
  18. package/dist/cjs/src/okx.js +1 -1
  19. package/dist/cjs/src/phemex.js +2 -2
  20. package/dist/cjs/src/pro/bingx.js +1 -0
  21. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
  22. package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
  23. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
  24. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
  25. package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
  26. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
  27. package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
  28. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
  29. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
  30. package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
  31. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
  32. package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
  33. package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
  34. package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
  35. package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
  36. package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
  37. package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
  38. package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
  39. package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
  40. package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
  41. package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
  42. package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
  43. package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
  44. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
  45. package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
  46. package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
  47. package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
  48. package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
  49. package/dist/cjs/src/tokocrypto.js +22 -2
  50. package/dist/cjs/src/wazirx.js +308 -3
  51. package/js/ccxt.d.ts +5 -2
  52. package/js/ccxt.js +4 -2
  53. package/js/src/abstract/coinbase.d.ts +3 -3
  54. package/js/src/abstract/hyperliquid.d.ts +9 -0
  55. package/js/src/abstract/hyperliquid.js +11 -0
  56. package/js/src/base/Exchange.d.ts +4 -0
  57. package/js/src/base/Exchange.js +13 -1
  58. package/js/src/base/functions/encode.d.ts +2 -1
  59. package/js/src/base/functions/encode.js +5 -1
  60. package/js/src/bitfinex2.js +1 -1
  61. package/js/src/bitget.js +74 -23
  62. package/js/src/coinbase.js +108 -103
  63. package/js/src/coinex.d.ts +3 -1
  64. package/js/src/coinex.js +61 -1
  65. package/js/src/hyperliquid.d.ts +83 -0
  66. package/js/src/hyperliquid.js +2036 -0
  67. package/js/src/kraken.js +8 -2
  68. package/js/src/krakenfutures.d.ts +2 -1
  69. package/js/src/krakenfutures.js +28 -0
  70. package/js/src/kucoinfutures.js +2 -2
  71. package/js/src/okx.js +1 -1
  72. package/js/src/phemex.js +2 -2
  73. package/js/src/pro/bingx.js +1 -0
  74. package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
  75. package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
  76. package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
  77. package/js/src/static_dependencies/ethers/address/address.js +162 -0
  78. package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
  79. package/js/src/static_dependencies/ethers/address/checks.js +119 -0
  80. package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
  81. package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
  82. package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
  83. package/js/src/static_dependencies/ethers/address/index.js +24 -0
  84. package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
  85. package/js/src/static_dependencies/ethers/bytes32.js +45 -0
  86. package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
  87. package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
  88. package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
  89. package/js/src/static_dependencies/ethers/coders/address.js +34 -0
  90. package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
  91. package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
  92. package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
  93. package/js/src/static_dependencies/ethers/coders/array.js +162 -0
  94. package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
  95. package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
  96. package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
  97. package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
  98. package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
  99. package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
  100. package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
  101. package/js/src/static_dependencies/ethers/coders/null.js +29 -0
  102. package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
  103. package/js/src/static_dependencies/ethers/coders/number.js +48 -0
  104. package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
  105. package/js/src/static_dependencies/ethers/coders/string.js +26 -0
  106. package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
  107. package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
  108. package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
  109. package/js/src/static_dependencies/ethers/fragments.js +1252 -0
  110. package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
  111. package/js/src/static_dependencies/ethers/hash/index.js +15 -0
  112. package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
  113. package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
  114. package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
  115. package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
  116. package/js/src/static_dependencies/ethers/index.d.ts +19 -0
  117. package/js/src/static_dependencies/ethers/index.js +22 -0
  118. package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
  119. package/js/src/static_dependencies/ethers/interface.js +990 -0
  120. package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
  121. package/js/src/static_dependencies/ethers/typed.js +608 -0
  122. package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
  123. package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
  124. package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
  125. package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
  126. package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
  127. package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
  128. package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
  129. package/js/src/static_dependencies/ethers/utils/data.js +175 -0
  130. package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
  131. package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
  132. package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
  133. package/js/src/static_dependencies/ethers/utils/events.js +52 -0
  134. package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
  135. package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
  136. package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
  137. package/js/src/static_dependencies/ethers/utils/index.js +38 -0
  138. package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
  139. package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
  140. package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
  141. package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
  142. package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
  143. package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
  144. package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
  145. package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
  146. package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
  147. package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
  148. package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
  149. package/js/src/static_dependencies/ethers/utils/units.js +88 -0
  150. package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
  151. package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
  152. package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
  153. package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
  154. package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
  155. package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
  156. package/js/src/tokocrypto.js +22 -2
  157. package/js/src/wazirx.d.ts +12 -1
  158. package/js/src/wazirx.js +308 -3
  159. package/package.json +1 -1
  160. package/skip-tests.json +18 -0
@@ -0,0 +1,529 @@
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
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ 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");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
14
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
15
+ 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");
16
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17
+ };
18
+ var _FixedNumber_instances, _FixedNumber_format, _FixedNumber_val, _FixedNumber_tens, _FixedNumber_checkFormat, _FixedNumber_checkValue, _FixedNumber_add, _FixedNumber_sub, _FixedNumber_mul, _FixedNumber_div;
19
+ /**
20
+ * The **FixedNumber** class permits using values with decimal places,
21
+ * using fixed-pont math.
22
+ *
23
+ * Fixed-point math is still based on integers under-the-hood, but uses an
24
+ * internal offset to store fractional components below, and each operation
25
+ * corrects for this after each operation.
26
+ *
27
+ * @_section: api/utils/fixed-point-math:Fixed-Point Maths [about-fixed-point-math]
28
+ */
29
+ import { getBytes } from "./data.js";
30
+ import { assert, assertArgument, assertPrivate } from "./errors.js";
31
+ import { getBigInt, getNumber, fromTwos, mask, toBigInt } from "./maths.js";
32
+ import { defineProperties } from "./properties.js";
33
+ const BN_N1 = BigInt(-1);
34
+ const BN_0 = BigInt(0);
35
+ const BN_1 = BigInt(1);
36
+ const BN_5 = BigInt(5);
37
+ const _guard = {};
38
+ // Constant to pull zeros from for multipliers
39
+ let Zeros = "0000";
40
+ while (Zeros.length < 80) {
41
+ Zeros += Zeros;
42
+ }
43
+ // Returns a string "1" followed by decimal "0"s
44
+ function getTens(decimals) {
45
+ let result = Zeros;
46
+ while (result.length < decimals) {
47
+ result += result;
48
+ }
49
+ return BigInt("1" + result.substring(0, decimals));
50
+ }
51
+ function checkValue(val, format, safeOp) {
52
+ const width = BigInt(format.width);
53
+ if (format.signed) {
54
+ const limit = (BN_1 << (width - BN_1));
55
+ assert(safeOp == null || (val >= -limit && val < limit), "overflow", "NUMERIC_FAULT", {
56
+ operation: safeOp, fault: "overflow", value: val
57
+ });
58
+ if (val > BN_0) {
59
+ val = fromTwos(mask(val, width), width);
60
+ }
61
+ else {
62
+ val = -fromTwos(mask(-val, width), width);
63
+ }
64
+ }
65
+ else {
66
+ const limit = (BN_1 << width);
67
+ assert(safeOp == null || (val >= 0 && val < limit), "overflow", "NUMERIC_FAULT", {
68
+ operation: safeOp, fault: "overflow", value: val
69
+ });
70
+ val = (((val % limit) + limit) % limit) & (limit - BN_1);
71
+ }
72
+ return val;
73
+ }
74
+ function getFormat(value) {
75
+ if (typeof (value) === "number") {
76
+ value = `fixed128x${value}`;
77
+ }
78
+ let signed = true;
79
+ let width = 128;
80
+ let decimals = 18;
81
+ if (typeof (value) === "string") {
82
+ // Parse the format string
83
+ if (value === "fixed") {
84
+ // defaults...
85
+ }
86
+ else if (value === "ufixed") {
87
+ signed = false;
88
+ }
89
+ else {
90
+ const match = value.match(/^(u?)fixed([0-9]+)x([0-9]+)$/);
91
+ assertArgument(match, "invalid fixed format", "format", value);
92
+ signed = (match[1] !== "u");
93
+ width = parseInt(match[2]);
94
+ decimals = parseInt(match[3]);
95
+ }
96
+ }
97
+ else if (value) {
98
+ // Extract the values from the object
99
+ const v = value;
100
+ const check = (key, type, defaultValue) => {
101
+ if (v[key] == null) {
102
+ return defaultValue;
103
+ }
104
+ assertArgument(typeof (v[key]) === type, "invalid fixed format (" + key + " not " + type + ")", "format." + key, v[key]);
105
+ return v[key];
106
+ };
107
+ signed = check("signed", "boolean", signed);
108
+ width = check("width", "number", width);
109
+ decimals = check("decimals", "number", decimals);
110
+ }
111
+ assertArgument((width % 8) === 0, "invalid FixedNumber width (not byte aligned)", "format.width", width);
112
+ assertArgument(decimals <= 80, "invalid FixedNumber decimals (too large)", "format.decimals", decimals);
113
+ const name = (signed ? "" : "u") + "fixed" + String(width) + "x" + String(decimals);
114
+ return { signed, width, decimals, name };
115
+ }
116
+ function toString(val, decimals) {
117
+ let negative = "";
118
+ if (val < BN_0) {
119
+ negative = "-";
120
+ val *= BN_N1;
121
+ }
122
+ let str = val.toString();
123
+ // No decimal point for whole values
124
+ if (decimals === 0) {
125
+ return (negative + str);
126
+ }
127
+ // Pad out to the whole component (including a whole digit)
128
+ while (str.length <= decimals) {
129
+ str = Zeros + str;
130
+ }
131
+ // Insert the decimal point
132
+ const index = str.length - decimals;
133
+ str = str.substring(0, index) + "." + str.substring(index);
134
+ // Trim the whole component (leaving at least one 0)
135
+ while (str[0] === "0" && str[1] !== ".") {
136
+ str = str.substring(1);
137
+ }
138
+ // Trim the decimal component (leaving at least one 0)
139
+ while (str[str.length - 1] === "0" && str[str.length - 2] !== ".") {
140
+ str = str.substring(0, str.length - 1);
141
+ }
142
+ return (negative + str);
143
+ }
144
+ /**
145
+ * A FixedNumber represents a value over its [[FixedFormat]]
146
+ * arithmetic field.
147
+ *
148
+ * A FixedNumber can be used to perform math, losslessly, on
149
+ * values which have decmial places.
150
+ *
151
+ * A FixedNumber has a fixed bit-width to store values in, and stores all
152
+ * values internally by multiplying the value by 10 raised to the power of
153
+ * %%decimals%%.
154
+ *
155
+ * If operations are performed that cause a value to grow too high (close to
156
+ * positive infinity) or too low (close to negative infinity), the value
157
+ * is said to //overflow//.
158
+ *
159
+ * For example, an 8-bit signed value, with 0 decimals may only be within
160
+ * the range ``-128`` to ``127``; so ``-128 - 1`` will overflow and become
161
+ * ``127``. Likewise, ``127 + 1`` will overflow and become ``-127``.
162
+ *
163
+ * Many operation have a normal and //unsafe// variant. The normal variant
164
+ * will throw a [[NumericFaultError]] on any overflow, while the //unsafe//
165
+ * variant will silently allow overflow, corrupting its value value.
166
+ *
167
+ * If operations are performed that cause a value to become too small
168
+ * (close to zero), the value loses precison and is said to //underflow//.
169
+ *
170
+ * For example, an value with 1 decimal place may store a number as small
171
+ * as ``0.1``, but the value of ``0.1 / 2`` is ``0.05``, which cannot fit
172
+ * into 1 decimal place, so underflow occurs which means precision is lost
173
+ * and the value becomes ``0``.
174
+ *
175
+ * Some operations have a normal and //signalling// variant. The normal
176
+ * variant will silently ignore underflow, while the //signalling// variant
177
+ * will thow a [[NumericFaultError]] on underflow.
178
+ */
179
+ export class FixedNumber {
180
+ // Use this when changing this file to get some typing info,
181
+ // but then switch to any to mask the internal type
182
+ //constructor(guard: any, value: bigint, format: _FixedFormat) {
183
+ /**
184
+ * @private
185
+ */
186
+ constructor(guard, value, format) {
187
+ _FixedNumber_instances.add(this);
188
+ _FixedNumber_format.set(this, void 0);
189
+ // The actual value (accounting for decimals)
190
+ _FixedNumber_val.set(this, void 0);
191
+ // A base-10 value to multiple values by to maintain the magnitude
192
+ _FixedNumber_tens.set(this, void 0);
193
+ assertPrivate(guard, _guard, "FixedNumber");
194
+ __classPrivateFieldSet(this, _FixedNumber_val, value, "f");
195
+ __classPrivateFieldSet(this, _FixedNumber_format, format, "f");
196
+ const _value = toString(value, format.decimals);
197
+ defineProperties(this, { format: format.name, _value });
198
+ __classPrivateFieldSet(this, _FixedNumber_tens, getTens(format.decimals), "f");
199
+ }
200
+ /**
201
+ * If true, negative values are permitted, otherwise only
202
+ * positive values and zero are allowed.
203
+ */
204
+ get signed() { return __classPrivateFieldGet(this, _FixedNumber_format, "f").signed; }
205
+ /**
206
+ * The number of bits available to store the value.
207
+ */
208
+ get width() { return __classPrivateFieldGet(this, _FixedNumber_format, "f").width; }
209
+ /**
210
+ * The number of decimal places in the fixed-point arithment field.
211
+ */
212
+ get decimals() { return __classPrivateFieldGet(this, _FixedNumber_format, "f").decimals; }
213
+ /**
214
+ * The value as an integer, based on the smallest unit the
215
+ * [[decimals]] allow.
216
+ */
217
+ get value() { return __classPrivateFieldGet(this, _FixedNumber_val, "f"); }
218
+ /**
219
+ * Returns a new [[FixedNumber]] with the result of %%this%% added
220
+ * to %%other%%, ignoring overflow.
221
+ */
222
+ addUnsafe(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_add).call(this, other); }
223
+ /**
224
+ * Returns a new [[FixedNumber]] with the result of %%this%% added
225
+ * to %%other%%. A [[NumericFaultError]] is thrown if overflow
226
+ * occurs.
227
+ */
228
+ add(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_add).call(this, other, "add"); }
229
+ /**
230
+ * Returns a new [[FixedNumber]] with the result of %%other%% subtracted
231
+ * from %%this%%, ignoring overflow.
232
+ */
233
+ subUnsafe(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_sub).call(this, other); }
234
+ /**
235
+ * Returns a new [[FixedNumber]] with the result of %%other%% subtracted
236
+ * from %%this%%. A [[NumericFaultError]] is thrown if overflow
237
+ * occurs.
238
+ */
239
+ sub(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_sub).call(this, other, "sub"); }
240
+ /**
241
+ * Returns a new [[FixedNumber]] with the result of %%this%% multiplied
242
+ * by %%other%%, ignoring overflow and underflow (precision loss).
243
+ */
244
+ mulUnsafe(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_mul).call(this, other); }
245
+ /**
246
+ * Returns a new [[FixedNumber]] with the result of %%this%% multiplied
247
+ * by %%other%%. A [[NumericFaultError]] is thrown if overflow
248
+ * occurs.
249
+ */
250
+ mul(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_mul).call(this, other, "mul"); }
251
+ /**
252
+ * Returns a new [[FixedNumber]] with the result of %%this%% multiplied
253
+ * by %%other%%. A [[NumericFaultError]] is thrown if overflow
254
+ * occurs or if underflow (precision loss) occurs.
255
+ */
256
+ mulSignal(other) {
257
+ __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkFormat).call(this, other);
258
+ const value = __classPrivateFieldGet(this, _FixedNumber_val, "f") * __classPrivateFieldGet(other, _FixedNumber_val, "f");
259
+ assert((value % __classPrivateFieldGet(this, _FixedNumber_tens, "f")) === BN_0, "precision lost during signalling mul", "NUMERIC_FAULT", {
260
+ operation: "mulSignal", fault: "underflow", value: this
261
+ });
262
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, value / __classPrivateFieldGet(this, _FixedNumber_tens, "f"), "mulSignal");
263
+ }
264
+ /**
265
+ * Returns a new [[FixedNumber]] with the result of %%this%% divided
266
+ * by %%other%%, ignoring underflow (precision loss). A
267
+ * [[NumericFaultError]] is thrown if overflow occurs.
268
+ */
269
+ divUnsafe(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_div).call(this, other); }
270
+ /**
271
+ * Returns a new [[FixedNumber]] with the result of %%this%% divided
272
+ * by %%other%%, ignoring underflow (precision loss). A
273
+ * [[NumericFaultError]] is thrown if overflow occurs.
274
+ */
275
+ div(other) { return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_div).call(this, other, "div"); }
276
+ /**
277
+ * Returns a new [[FixedNumber]] with the result of %%this%% divided
278
+ * by %%other%%. A [[NumericFaultError]] is thrown if underflow
279
+ * (precision loss) occurs.
280
+ */
281
+ divSignal(other) {
282
+ assert(__classPrivateFieldGet(other, _FixedNumber_val, "f") !== BN_0, "division by zero", "NUMERIC_FAULT", {
283
+ operation: "div", fault: "divide-by-zero", value: this
284
+ });
285
+ __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkFormat).call(this, other);
286
+ const value = (__classPrivateFieldGet(this, _FixedNumber_val, "f") * __classPrivateFieldGet(this, _FixedNumber_tens, "f"));
287
+ assert((value % __classPrivateFieldGet(other, _FixedNumber_val, "f")) === BN_0, "precision lost during signalling div", "NUMERIC_FAULT", {
288
+ operation: "divSignal", fault: "underflow", value: this
289
+ });
290
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, value / __classPrivateFieldGet(other, _FixedNumber_val, "f"), "divSignal");
291
+ }
292
+ /**
293
+ * Returns a comparison result between %%this%% and %%other%%.
294
+ *
295
+ * This is suitable for use in sorting, where ``-1`` implies %%this%%
296
+ * is smaller, ``1`` implies %%this%% is larger and ``0`` implies
297
+ * both are equal.
298
+ */
299
+ cmp(other) {
300
+ let a = this.value, b = other.value;
301
+ // Coerce a and b to the same magnitude
302
+ const delta = this.decimals - other.decimals;
303
+ if (delta > 0) {
304
+ b *= getTens(delta);
305
+ }
306
+ else if (delta < 0) {
307
+ a *= getTens(-delta);
308
+ }
309
+ // Comnpare
310
+ if (a < b) {
311
+ return -1;
312
+ }
313
+ if (a > b) {
314
+ return 1;
315
+ }
316
+ return 0;
317
+ }
318
+ /**
319
+ * Returns true if %%other%% is equal to %%this%%.
320
+ */
321
+ eq(other) { return this.cmp(other) === 0; }
322
+ /**
323
+ * Returns true if %%other%% is less than to %%this%%.
324
+ */
325
+ lt(other) { return this.cmp(other) < 0; }
326
+ /**
327
+ * Returns true if %%other%% is less than or equal to %%this%%.
328
+ */
329
+ lte(other) { return this.cmp(other) <= 0; }
330
+ /**
331
+ * Returns true if %%other%% is greater than to %%this%%.
332
+ */
333
+ gt(other) { return this.cmp(other) > 0; }
334
+ /**
335
+ * Returns true if %%other%% is greater than or equal to %%this%%.
336
+ */
337
+ gte(other) { return this.cmp(other) >= 0; }
338
+ /**
339
+ * Returns a new [[FixedNumber]] which is the largest **integer**
340
+ * that is less than or equal to %%this%%.
341
+ *
342
+ * The decimal component of the result will always be ``0``.
343
+ */
344
+ floor() {
345
+ let val = __classPrivateFieldGet(this, _FixedNumber_val, "f");
346
+ if (__classPrivateFieldGet(this, _FixedNumber_val, "f") < BN_0) {
347
+ val -= __classPrivateFieldGet(this, _FixedNumber_tens, "f") - BN_1;
348
+ }
349
+ val = (__classPrivateFieldGet(this, _FixedNumber_val, "f") / __classPrivateFieldGet(this, _FixedNumber_tens, "f")) * __classPrivateFieldGet(this, _FixedNumber_tens, "f");
350
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, val, "floor");
351
+ }
352
+ /**
353
+ * Returns a new [[FixedNumber]] which is the smallest **integer**
354
+ * that is greater than or equal to %%this%%.
355
+ *
356
+ * The decimal component of the result will always be ``0``.
357
+ */
358
+ ceiling() {
359
+ let val = __classPrivateFieldGet(this, _FixedNumber_val, "f");
360
+ if (__classPrivateFieldGet(this, _FixedNumber_val, "f") > BN_0) {
361
+ val += __classPrivateFieldGet(this, _FixedNumber_tens, "f") - BN_1;
362
+ }
363
+ val = (__classPrivateFieldGet(this, _FixedNumber_val, "f") / __classPrivateFieldGet(this, _FixedNumber_tens, "f")) * __classPrivateFieldGet(this, _FixedNumber_tens, "f");
364
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, val, "ceiling");
365
+ }
366
+ /**
367
+ * Returns a new [[FixedNumber]] with the decimal component
368
+ * rounded up on ties at %%decimals%% places.
369
+ */
370
+ round(decimals) {
371
+ if (decimals == null) {
372
+ decimals = 0;
373
+ }
374
+ // Not enough precision to not already be rounded
375
+ if (decimals >= this.decimals) {
376
+ return this;
377
+ }
378
+ const delta = this.decimals - decimals;
379
+ const bump = BN_5 * getTens(delta - 1);
380
+ let value = this.value + bump;
381
+ const tens = getTens(delta);
382
+ value = (value / tens) * tens;
383
+ checkValue(value, __classPrivateFieldGet(this, _FixedNumber_format, "f"), "round");
384
+ return new FixedNumber(_guard, value, __classPrivateFieldGet(this, _FixedNumber_format, "f"));
385
+ }
386
+ /**
387
+ * Returns true if %%this%% is equal to ``0``.
388
+ */
389
+ isZero() { return (__classPrivateFieldGet(this, _FixedNumber_val, "f") === BN_0); }
390
+ /**
391
+ * Returns true if %%this%% is less than ``0``.
392
+ */
393
+ isNegative() { return (__classPrivateFieldGet(this, _FixedNumber_val, "f") < BN_0); }
394
+ /**
395
+ * Returns the string representation of %%this%%.
396
+ */
397
+ toString() { return this._value; }
398
+ /**
399
+ * Returns a float approximation.
400
+ *
401
+ * Due to IEEE 754 precission (or lack thereof), this function
402
+ * can only return an approximation and most values will contain
403
+ * rounding errors.
404
+ */
405
+ toUnsafeFloat() { return parseFloat(this.toString()); }
406
+ /**
407
+ * Return a new [[FixedNumber]] with the same value but has had
408
+ * its field set to %%format%%.
409
+ *
410
+ * This will throw if the value cannot fit into %%format%%.
411
+ */
412
+ toFormat(format) {
413
+ return FixedNumber.fromString(this.toString(), format);
414
+ }
415
+ /**
416
+ * Creates a new [[FixedNumber]] for %%value%% divided by
417
+ * %%decimal%% places with %%format%%.
418
+ *
419
+ * This will throw a [[NumericFaultError]] if %%value%% (once adjusted
420
+ * for %%decimals%%) cannot fit in %%format%%, either due to overflow
421
+ * or underflow (precision loss).
422
+ */
423
+ static fromValue(_value, _decimals, _format) {
424
+ const decimals = (_decimals == null) ? 0 : getNumber(_decimals);
425
+ const format = getFormat(_format);
426
+ let value = getBigInt(_value, "value");
427
+ const delta = decimals - format.decimals;
428
+ if (delta > 0) {
429
+ const tens = getTens(delta);
430
+ assert((value % tens) === BN_0, "value loses precision for format", "NUMERIC_FAULT", {
431
+ operation: "fromValue", fault: "underflow", value: _value
432
+ });
433
+ value /= tens;
434
+ }
435
+ else if (delta < 0) {
436
+ value *= getTens(-delta);
437
+ }
438
+ checkValue(value, format, "fromValue");
439
+ return new FixedNumber(_guard, value, format);
440
+ }
441
+ /**
442
+ * Creates a new [[FixedNumber]] for %%value%% with %%format%%.
443
+ *
444
+ * This will throw a [[NumericFaultError]] if %%value%% cannot fit
445
+ * in %%format%%, either due to overflow or underflow (precision loss).
446
+ */
447
+ static fromString(_value, _format) {
448
+ const match = _value.match(/^(-?)([0-9]*)\.?([0-9]*)$/);
449
+ assertArgument(match && (match[2].length + match[3].length) > 0, "invalid FixedNumber string value", "value", _value);
450
+ const format = getFormat(_format);
451
+ let whole = (match[2] || "0"), decimal = (match[3] || "");
452
+ // Pad out the decimals
453
+ while (decimal.length < format.decimals) {
454
+ decimal += Zeros;
455
+ }
456
+ // Check precision is safe
457
+ assert(decimal.substring(format.decimals).match(/^0*$/), "too many decimals for format", "NUMERIC_FAULT", {
458
+ operation: "fromString", fault: "underflow", value: _value
459
+ });
460
+ // Remove extra padding
461
+ decimal = decimal.substring(0, format.decimals);
462
+ const value = BigInt(match[1] + whole + decimal);
463
+ checkValue(value, format, "fromString");
464
+ return new FixedNumber(_guard, value, format);
465
+ }
466
+ /**
467
+ * Creates a new [[FixedNumber]] with the big-endian representation
468
+ * %%value%% with %%format%%.
469
+ *
470
+ * This will throw a [[NumericFaultError]] if %%value%% cannot fit
471
+ * in %%format%% due to overflow.
472
+ */
473
+ static fromBytes(_value, _format) {
474
+ let value = toBigInt(getBytes(_value, "value"));
475
+ const format = getFormat(_format);
476
+ if (format.signed) {
477
+ value = fromTwos(value, format.width);
478
+ }
479
+ checkValue(value, format, "fromBytes");
480
+ return new FixedNumber(_guard, value, format);
481
+ }
482
+ }
483
+ _FixedNumber_format = new WeakMap(), _FixedNumber_val = new WeakMap(), _FixedNumber_tens = new WeakMap(), _FixedNumber_instances = new WeakSet(), _FixedNumber_checkFormat = function _FixedNumber_checkFormat(other) {
484
+ assertArgument(this.format === other.format, "incompatible format; use fixedNumber.toFormat", "other", other);
485
+ }, _FixedNumber_checkValue = function _FixedNumber_checkValue(val, safeOp) {
486
+ /*
487
+ const width = BigInt(this.width);
488
+ if (this.signed) {
489
+ const limit = (BN_1 << (width - BN_1));
490
+ assert(safeOp == null || (val >= -limit && val < limit), "overflow", "NUMERIC_FAULT", {
491
+ operation: <string>safeOp, fault: "overflow", value: val
492
+ });
493
+
494
+ if (val > BN_0) {
495
+ val = fromTwos(mask(val, width), width);
496
+ } else {
497
+ val = -fromTwos(mask(-val, width), width);
498
+ }
499
+
500
+ } else {
501
+ const masked = mask(val, width);
502
+ assert(safeOp == null || (val >= 0 && val === masked), "overflow", "NUMERIC_FAULT", {
503
+ operation: <string>safeOp, fault: "overflow", value: val
504
+ });
505
+ val = masked;
506
+ }
507
+ */
508
+ val = checkValue(val, __classPrivateFieldGet(this, _FixedNumber_format, "f"), safeOp);
509
+ return new FixedNumber(_guard, val, __classPrivateFieldGet(this, _FixedNumber_format, "f"));
510
+ }, _FixedNumber_add = function _FixedNumber_add(o, safeOp) {
511
+ __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkFormat).call(this, o);
512
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, __classPrivateFieldGet(this, _FixedNumber_val, "f") + __classPrivateFieldGet(o, _FixedNumber_val, "f"), safeOp);
513
+ }, _FixedNumber_sub = function _FixedNumber_sub(o, safeOp) {
514
+ __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkFormat).call(this, o);
515
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, __classPrivateFieldGet(this, _FixedNumber_val, "f") - __classPrivateFieldGet(o, _FixedNumber_val, "f"), safeOp);
516
+ }, _FixedNumber_mul = function _FixedNumber_mul(o, safeOp) {
517
+ __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkFormat).call(this, o);
518
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, (__classPrivateFieldGet(this, _FixedNumber_val, "f") * __classPrivateFieldGet(o, _FixedNumber_val, "f")) / __classPrivateFieldGet(this, _FixedNumber_tens, "f"), safeOp);
519
+ }, _FixedNumber_div = function _FixedNumber_div(o, safeOp) {
520
+ assert(__classPrivateFieldGet(o, _FixedNumber_val, "f") !== BN_0, "division by zero", "NUMERIC_FAULT", {
521
+ operation: "div", fault: "divide-by-zero", value: this
522
+ });
523
+ __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkFormat).call(this, o);
524
+ return __classPrivateFieldGet(this, _FixedNumber_instances, "m", _FixedNumber_checkValue).call(this, (__classPrivateFieldGet(this, _FixedNumber_val, "f") * __classPrivateFieldGet(this, _FixedNumber_tens, "f")) / __classPrivateFieldGet(o, _FixedNumber_val, "f"), safeOp);
525
+ };
526
+ //const f1 = FixedNumber.fromString("12.56", "fixed16x2");
527
+ //const f2 = FixedNumber.fromString("0.3", "fixed16x2");
528
+ //console.log(f1.divSignal(f2));
529
+ //const BUMP = FixedNumber.from("0.5");
@@ -0,0 +1,30 @@
1
+ /**
2
+ * There are many simple utilities required to interact with
3
+ * Ethereum and to simplify the library, without increasing
4
+ * the library dependencies for simple functions.
5
+ *
6
+ * @_section api/utils:Utilities [about-utils]
7
+ */
8
+ export { decodeBase58, encodeBase58 } from "./base58.js";
9
+ export { decodeBase64, encodeBase64 } from "./base64.js";
10
+ export { getBytes, getBytesCopy, isHexString, isBytesLike, hexlify, concat, dataLength, dataSlice, stripZerosLeft, zeroPadValue, zeroPadBytes } from "./data.js";
11
+ export { isCallException, isError, assert, assertArgument, assertArgumentCount, assertPrivate, assertNormalize, makeError } from "./errors.js";
12
+ export { EventPayload } from "./events.js";
13
+ export { FixedNumber } from "./fixednumber.js";
14
+ export { fromTwos, toTwos, mask, getBigInt, getNumber, getUint, toBigInt, toNumber, toBeHex, toBeArray, toQuantity } from "./maths.js";
15
+ export { resolveProperties, defineProperties } from "./properties.js";
16
+ export { decodeRlp } from "./rlp-decode.js";
17
+ export { encodeRlp } from "./rlp-encode.js";
18
+ export { formatEther, parseEther, formatUnits, parseUnits } from "./units.js";
19
+ export { toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, } from "./utf8.js";
20
+ export { uuidV4 } from "./uuid.js";
21
+ export type { BytesLike } from "./data.js";
22
+ export type { ErrorCode, EthersError, UnknownError, NotImplementedError, UnsupportedOperationError, NetworkError, ServerError, TimeoutError, BadDataError, CancelledError, BufferOverrunError, NumericFaultError, InvalidArgumentError, MissingArgumentError, UnexpectedArgumentError, CallExceptionError, InsufficientFundsError, NonceExpiredError, OffchainFaultError, ReplacementUnderpricedError, TransactionReplacedError, UnconfiguredNameError, ActionRejectedError, CallExceptionAction, CallExceptionTransaction, CodedEthersError } from "./errors.js";
23
+ export type { EventEmitterable, Listener } from "./events.js";
24
+ export type { FixedFormat } from "./fixednumber.js";
25
+ export type { BigNumberish, Numeric } from "./maths.js";
26
+ export type { RlpStructuredData, RlpStructuredDataish } from "./rlp.js";
27
+ export type { Utf8ErrorFunc, UnicodeNormalizationForm, Utf8ErrorReason } from "./utf8.js";
28
+ export declare function id(value: any): string;
29
+ export declare function keccak256(value: any): string;
30
+ export declare function sha256(value: any): string;
@@ -0,0 +1,38 @@
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
+ * There are many simple utilities required to interact with
9
+ * Ethereum and to simplify the library, without increasing
10
+ * the library dependencies for simple functions.
11
+ *
12
+ * @_section api/utils:Utilities [about-utils]
13
+ */
14
+ export { decodeBase58, encodeBase58 } from "./base58.js";
15
+ export { decodeBase64, encodeBase64 } from "./base64.js";
16
+ export { getBytes, getBytesCopy, isHexString, isBytesLike, hexlify, concat, dataLength, dataSlice, stripZerosLeft, zeroPadValue, zeroPadBytes } from "./data.js";
17
+ export { isCallException, isError, assert, assertArgument, assertArgumentCount, assertPrivate, assertNormalize, makeError } from "./errors.js";
18
+ export { EventPayload } from "./events.js";
19
+ export { FixedNumber } from "./fixednumber.js";
20
+ export { fromTwos, toTwos, mask, getBigInt, getNumber, getUint, toBigInt, toNumber, toBeHex, toBeArray, toQuantity } from "./maths.js";
21
+ export { resolveProperties, defineProperties } from "./properties.js";
22
+ export { decodeRlp } from "./rlp-decode.js";
23
+ export { encodeRlp } from "./rlp-encode.js";
24
+ export { formatEther, parseEther, formatUnits, parseUnits } from "./units.js";
25
+ export { toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs, } from "./utf8.js";
26
+ export { uuidV4 } from "./uuid.js";
27
+ import { hash } from '../../../base/functions.js';
28
+ import { keccak_256 } from '../../noble-hashes/sha3.js';
29
+ import { sha256 as sha_256 } from '../../noble-hashes/sha256.js';
30
+ export function id(value) {
31
+ return '0x' + hash(value, keccak_256, 'hex');
32
+ }
33
+ export function keccak256(value) {
34
+ return '0x' + hash(value, keccak_256, 'hex');
35
+ }
36
+ export function sha256(value) {
37
+ return '0x' + hash(value, sha_256, 'hex');
38
+ }
@@ -0,0 +1,65 @@
1
+ import type { BytesLike } from "./data.js";
2
+ /**
3
+ * Any type that can be used where a numeric value is needed.
4
+ */
5
+ export declare type Numeric = number | bigint;
6
+ /**
7
+ * Any type that can be used where a big number is needed.
8
+ */
9
+ export declare type BigNumberish = string | Numeric;
10
+ /**
11
+ * Convert %%value%% from a twos-compliment representation of %%width%%
12
+ * bits to its value.
13
+ *
14
+ * If the highest bit is ``1``, the result will be negative.
15
+ */
16
+ export declare function fromTwos(_value: BigNumberish, _width: Numeric): bigint;
17
+ /**
18
+ * Convert %%value%% to a twos-compliment representation of
19
+ * %%width%% bits.
20
+ *
21
+ * The result will always be positive.
22
+ */
23
+ export declare function toTwos(_value: BigNumberish, _width: Numeric): bigint;
24
+ /**
25
+ * Mask %%value%% with a bitmask of %%bits%% ones.
26
+ */
27
+ export declare function mask(_value: BigNumberish, _bits: Numeric): bigint;
28
+ /**
29
+ * Gets a BigInt from %%value%%. If it is an invalid value for
30
+ * a BigInt, then an ArgumentError will be thrown for %%name%%.
31
+ */
32
+ export declare function getBigInt(value: BigNumberish, name?: string): bigint;
33
+ /**
34
+ * Returns %%value%% as a bigint, validating it is valid as a bigint
35
+ * value and that it is positive.
36
+ */
37
+ export declare function getUint(value: BigNumberish, name?: string): bigint;
38
+ export declare function toBigInt(value: BigNumberish | Uint8Array): bigint;
39
+ /**
40
+ * Gets a //number// from %%value%%. If it is an invalid value for
41
+ * a //number//, then an ArgumentError will be thrown for %%name%%.
42
+ */
43
+ export declare function getNumber(value: BigNumberish, name?: string): number;
44
+ /**
45
+ * Converts %%value%% to a number. If %%value%% is a Uint8Array, it
46
+ * is treated as Big Endian data. Throws if the value is not safe.
47
+ */
48
+ export declare function toNumber(value: BigNumberish | Uint8Array): number;
49
+ /**
50
+ * Converts %%value%% to a Big Endian hexstring, optionally padded to
51
+ * %%width%% bytes.
52
+ */
53
+ export declare function toBeHex(_value: BigNumberish, _width?: Numeric): string;
54
+ /**
55
+ * Converts %%value%% to a Big Endian Uint8Array.
56
+ */
57
+ export declare function toBeArray(_value: BigNumberish): Uint8Array;
58
+ /**
59
+ * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//.
60
+ *
61
+ * A //Quantity// does not have and leading 0 values unless the value is
62
+ * the literal value `0x0`. This is most commonly used for JSSON-RPC
63
+ * numeric values.
64
+ */
65
+ export declare function toQuantity(value: BytesLike | BigNumberish): string;