ccxt 4.2.59 → 4.2.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/README.md +103 -102
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +11853 -3790
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +4 -1
  6. package/dist/cjs/src/abstract/hyperliquid.js +9 -0
  7. package/dist/cjs/src/ascendex.js +10 -12
  8. package/dist/cjs/src/base/Exchange.js +22 -1
  9. package/dist/cjs/src/base/functions/encode.js +5 -0
  10. package/dist/cjs/src/base/functions.js +1 -0
  11. package/dist/cjs/src/bingx.js +38 -0
  12. package/dist/cjs/src/bitfinex2.js +20 -3
  13. package/dist/cjs/src/bitget.js +9 -2
  14. package/dist/cjs/src/bitmart.js +41 -23
  15. package/dist/cjs/src/blofin.js +59 -1
  16. package/dist/cjs/src/coinbase.js +108 -103
  17. package/dist/cjs/src/coinex.js +61 -1
  18. package/dist/cjs/src/hitbtc.js +1 -1
  19. package/dist/cjs/src/htx.js +4 -1
  20. package/dist/cjs/src/hyperliquid.js +2035 -0
  21. package/dist/cjs/src/kraken.js +50 -41
  22. package/dist/cjs/src/krakenfutures.js +28 -0
  23. package/dist/cjs/src/kucoinfutures.js +3 -2
  24. package/dist/cjs/src/okx.js +1 -1
  25. package/dist/cjs/src/phemex.js +2 -2
  26. package/dist/cjs/src/pro/binance.js +16 -3
  27. package/dist/cjs/src/pro/bingx.js +1 -0
  28. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
  29. package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
  30. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
  31. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
  32. package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
  33. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
  34. package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
  35. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
  36. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
  37. package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
  38. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
  39. package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
  40. package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
  41. package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
  42. package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
  43. package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
  44. package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
  45. package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
  46. package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
  47. package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
  48. package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
  49. package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
  50. package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
  51. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
  52. package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
  53. package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
  54. package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
  55. package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
  56. package/dist/cjs/src/tokocrypto.js +22 -2
  57. package/dist/cjs/src/wazirx.js +314 -4
  58. package/dist/cjs/src/woo.js +157 -77
  59. package/js/ccxt.d.ts +5 -2
  60. package/js/ccxt.js +4 -2
  61. package/js/src/abstract/blofin.d.ts +1 -0
  62. package/js/src/abstract/coinbase.d.ts +3 -3
  63. package/js/src/abstract/hyperliquid.d.ts +9 -0
  64. package/js/src/abstract/hyperliquid.js +11 -0
  65. package/js/src/abstract/wazirx.d.ts +5 -0
  66. package/js/src/ascendex.d.ts +2 -2
  67. package/js/src/ascendex.js +10 -12
  68. package/js/src/base/Exchange.d.ts +4 -0
  69. package/js/src/base/Exchange.js +13 -1
  70. package/js/src/base/functions/encode.d.ts +2 -1
  71. package/js/src/base/functions/encode.js +5 -1
  72. package/js/src/bingx.d.ts +3 -1
  73. package/js/src/bingx.js +38 -0
  74. package/js/src/bitfinex2.js +20 -3
  75. package/js/src/bitget.js +9 -2
  76. package/js/src/bitmart.d.ts +9 -2
  77. package/js/src/bitmart.js +41 -23
  78. package/js/src/blofin.d.ts +2 -1
  79. package/js/src/blofin.js +59 -1
  80. package/js/src/coinbase.js +108 -103
  81. package/js/src/coinex.d.ts +3 -1
  82. package/js/src/coinex.js +61 -1
  83. package/js/src/hitbtc.js +1 -1
  84. package/js/src/htx.js +4 -1
  85. package/js/src/hyperliquid.d.ts +83 -0
  86. package/js/src/hyperliquid.js +2036 -0
  87. package/js/src/kraken.js +50 -41
  88. package/js/src/krakenfutures.d.ts +2 -1
  89. package/js/src/krakenfutures.js +28 -0
  90. package/js/src/kucoinfutures.js +3 -2
  91. package/js/src/okx.js +1 -1
  92. package/js/src/phemex.js +2 -2
  93. package/js/src/pro/binance.js +16 -3
  94. package/js/src/pro/bingx.js +1 -0
  95. package/js/src/pro/deribit.d.ts +1 -1
  96. package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
  97. package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
  98. package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
  99. package/js/src/static_dependencies/ethers/address/address.js +162 -0
  100. package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
  101. package/js/src/static_dependencies/ethers/address/checks.js +119 -0
  102. package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
  103. package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
  104. package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
  105. package/js/src/static_dependencies/ethers/address/index.js +24 -0
  106. package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
  107. package/js/src/static_dependencies/ethers/bytes32.js +45 -0
  108. package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
  109. package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
  110. package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
  111. package/js/src/static_dependencies/ethers/coders/address.js +34 -0
  112. package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
  113. package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
  114. package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
  115. package/js/src/static_dependencies/ethers/coders/array.js +162 -0
  116. package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
  117. package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
  118. package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
  119. package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
  120. package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
  121. package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
  122. package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
  123. package/js/src/static_dependencies/ethers/coders/null.js +29 -0
  124. package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
  125. package/js/src/static_dependencies/ethers/coders/number.js +48 -0
  126. package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
  127. package/js/src/static_dependencies/ethers/coders/string.js +26 -0
  128. package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
  129. package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
  130. package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
  131. package/js/src/static_dependencies/ethers/fragments.js +1252 -0
  132. package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
  133. package/js/src/static_dependencies/ethers/hash/index.js +15 -0
  134. package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
  135. package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
  136. package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
  137. package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
  138. package/js/src/static_dependencies/ethers/index.d.ts +19 -0
  139. package/js/src/static_dependencies/ethers/index.js +22 -0
  140. package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
  141. package/js/src/static_dependencies/ethers/interface.js +990 -0
  142. package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
  143. package/js/src/static_dependencies/ethers/typed.js +608 -0
  144. package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
  145. package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
  146. package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
  147. package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
  148. package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
  149. package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
  150. package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
  151. package/js/src/static_dependencies/ethers/utils/data.js +175 -0
  152. package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
  153. package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
  154. package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
  155. package/js/src/static_dependencies/ethers/utils/events.js +52 -0
  156. package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
  157. package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
  158. package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
  159. package/js/src/static_dependencies/ethers/utils/index.js +38 -0
  160. package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
  161. package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
  162. package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
  163. package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
  164. package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
  165. package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
  166. package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
  167. package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
  168. package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
  169. package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
  170. package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
  171. package/js/src/static_dependencies/ethers/utils/units.js +88 -0
  172. package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
  173. package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
  174. package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
  175. package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
  176. package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
  177. package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
  178. package/js/src/tokocrypto.js +22 -2
  179. package/js/src/wazirx.d.ts +12 -1
  180. package/js/src/wazirx.js +314 -4
  181. package/js/src/woo.d.ts +8 -0
  182. package/js/src/woo.js +157 -77
  183. package/package.json +1 -1
  184. package/skip-tests.json +60 -16
@@ -0,0 +1,220 @@
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
+ * Some mathematic operations.
9
+ *
10
+ * @_subsection: api/utils:Math Helpers [about-maths]
11
+ */
12
+ import { hexlify, isBytesLike } from "./data.js";
13
+ import { assert, assertArgument } from "./errors.js";
14
+ const BN_0 = BigInt(0);
15
+ const BN_1 = BigInt(1);
16
+ //const BN_Max256 = (BN_1 << BigInt(256)) - BN_1;
17
+ // IEEE 754 support 53-bits of mantissa
18
+ const maxValue = 0x1fffffffffffff;
19
+ /**
20
+ * Convert %%value%% from a twos-compliment representation of %%width%%
21
+ * bits to its value.
22
+ *
23
+ * If the highest bit is ``1``, the result will be negative.
24
+ */
25
+ export function fromTwos(_value, _width) {
26
+ const value = getUint(_value, "value");
27
+ const width = BigInt(getNumber(_width, "width"));
28
+ assert((value >> width) === BN_0, "overflow", "NUMERIC_FAULT", {
29
+ operation: "fromTwos", fault: "overflow", value: _value
30
+ });
31
+ // Top bit set; treat as a negative value
32
+ if (value >> (width - BN_1)) {
33
+ const mask = (BN_1 << width) - BN_1;
34
+ return -(((~value) & mask) + BN_1);
35
+ }
36
+ return value;
37
+ }
38
+ /**
39
+ * Convert %%value%% to a twos-compliment representation of
40
+ * %%width%% bits.
41
+ *
42
+ * The result will always be positive.
43
+ */
44
+ export function toTwos(_value, _width) {
45
+ let value = getBigInt(_value, "value");
46
+ const width = BigInt(getNumber(_width, "width"));
47
+ const limit = (BN_1 << (width - BN_1));
48
+ if (value < BN_0) {
49
+ value = -value;
50
+ assert(value <= limit, "too low", "NUMERIC_FAULT", {
51
+ operation: "toTwos", fault: "overflow", value: _value
52
+ });
53
+ const mask = (BN_1 << width) - BN_1;
54
+ return ((~value) & mask) + BN_1;
55
+ }
56
+ else {
57
+ assert(value < limit, "too high", "NUMERIC_FAULT", {
58
+ operation: "toTwos", fault: "overflow", value: _value
59
+ });
60
+ }
61
+ return value;
62
+ }
63
+ /**
64
+ * Mask %%value%% with a bitmask of %%bits%% ones.
65
+ */
66
+ export function mask(_value, _bits) {
67
+ const value = getUint(_value, "value");
68
+ const bits = BigInt(getNumber(_bits, "bits"));
69
+ return value & ((BN_1 << bits) - BN_1);
70
+ }
71
+ /**
72
+ * Gets a BigInt from %%value%%. If it is an invalid value for
73
+ * a BigInt, then an ArgumentError will be thrown for %%name%%.
74
+ */
75
+ export function getBigInt(value, name) {
76
+ switch (typeof (value)) {
77
+ case "bigint": return value;
78
+ case "number":
79
+ assertArgument(Number.isInteger(value), "underflow", name || "value", value);
80
+ assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
81
+ return BigInt(value);
82
+ case "string":
83
+ try {
84
+ if (value === "") {
85
+ throw new Error("empty string");
86
+ }
87
+ if (value[0] === "-" && value[1] !== "-") {
88
+ return -BigInt(value.substring(1));
89
+ }
90
+ return BigInt(value);
91
+ }
92
+ catch (e) {
93
+ assertArgument(false, `invalid BigNumberish string: ${e.message}`, name || "value", value);
94
+ }
95
+ }
96
+ assertArgument(false, "invalid BigNumberish value", name || "value", value);
97
+ }
98
+ /**
99
+ * Returns %%value%% as a bigint, validating it is valid as a bigint
100
+ * value and that it is positive.
101
+ */
102
+ export function getUint(value, name) {
103
+ const result = getBigInt(value, name);
104
+ assert(result >= BN_0, "unsigned value cannot be negative", "NUMERIC_FAULT", {
105
+ fault: "overflow", operation: "getUint", value
106
+ });
107
+ return result;
108
+ }
109
+ const Nibbles = "0123456789abcdef";
110
+ /*
111
+ * Converts %%value%% to a BigInt. If %%value%% is a Uint8Array, it
112
+ * is treated as Big Endian data.
113
+ */
114
+ export function toBigInt(value) {
115
+ if (value instanceof Uint8Array) {
116
+ let result = "0x0";
117
+ for (const v of value) {
118
+ result += Nibbles[v >> 4];
119
+ result += Nibbles[v & 0x0f];
120
+ }
121
+ return BigInt(result);
122
+ }
123
+ return getBigInt(value);
124
+ }
125
+ /**
126
+ * Gets a //number// from %%value%%. If it is an invalid value for
127
+ * a //number//, then an ArgumentError will be thrown for %%name%%.
128
+ */
129
+ export function getNumber(value, name) {
130
+ switch (typeof (value)) {
131
+ case "bigint":
132
+ assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
133
+ return Number(value);
134
+ case "number":
135
+ assertArgument(Number.isInteger(value), "underflow", name || "value", value);
136
+ assertArgument(value >= -maxValue && value <= maxValue, "overflow", name || "value", value);
137
+ return value;
138
+ case "string":
139
+ try {
140
+ if (value === "") {
141
+ throw new Error("empty string");
142
+ }
143
+ return getNumber(BigInt(value), name);
144
+ }
145
+ catch (e) {
146
+ assertArgument(false, `invalid numeric string: ${e.message}`, name || "value", value);
147
+ }
148
+ }
149
+ assertArgument(false, "invalid numeric value", name || "value", value);
150
+ }
151
+ /**
152
+ * Converts %%value%% to a number. If %%value%% is a Uint8Array, it
153
+ * is treated as Big Endian data. Throws if the value is not safe.
154
+ */
155
+ export function toNumber(value) {
156
+ return getNumber(toBigInt(value));
157
+ }
158
+ /**
159
+ * Converts %%value%% to a Big Endian hexstring, optionally padded to
160
+ * %%width%% bytes.
161
+ */
162
+ export function toBeHex(_value, _width) {
163
+ const value = getUint(_value, "value");
164
+ let result = value.toString(16);
165
+ if (_width == null) {
166
+ // Ensure the value is of even length
167
+ if (result.length % 2) {
168
+ result = "0" + result;
169
+ }
170
+ }
171
+ else {
172
+ const width = getNumber(_width, "width");
173
+ assert(width * 2 >= result.length, `value exceeds width (${width} bytes)`, "NUMERIC_FAULT", {
174
+ operation: "toBeHex",
175
+ fault: "overflow",
176
+ value: _value
177
+ });
178
+ // Pad the value to the required width
179
+ while (result.length < (width * 2)) {
180
+ result = "0" + result;
181
+ }
182
+ }
183
+ return "0x" + result;
184
+ }
185
+ /**
186
+ * Converts %%value%% to a Big Endian Uint8Array.
187
+ */
188
+ export function toBeArray(_value) {
189
+ const value = getUint(_value, "value");
190
+ if (value === BN_0) {
191
+ return new Uint8Array([]);
192
+ }
193
+ let hex = value.toString(16);
194
+ if (hex.length % 2) {
195
+ hex = "0" + hex;
196
+ }
197
+ const result = new Uint8Array(hex.length / 2);
198
+ for (let i = 0; i < result.length; i++) {
199
+ const offset = i * 2;
200
+ result[i] = parseInt(hex.substring(offset, offset + 2), 16);
201
+ }
202
+ return result;
203
+ }
204
+ /**
205
+ * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//.
206
+ *
207
+ * A //Quantity// does not have and leading 0 values unless the value is
208
+ * the literal value `0x0`. This is most commonly used for JSSON-RPC
209
+ * numeric values.
210
+ */
211
+ export function toQuantity(value) {
212
+ let result = hexlify(isBytesLike(value) ? value : toBeArray(value)).substring(2);
213
+ while (result.startsWith("0")) {
214
+ result = result.substring(1);
215
+ }
216
+ if (result === "") {
217
+ result = "0";
218
+ }
219
+ return "0x" + result;
220
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Property helper functions.
3
+ *
4
+ * @_subsection api/utils:Properties [about-properties]
5
+ */
6
+ /**
7
+ * Resolves to a new object that is a copy of %%value%%, but with all
8
+ * values resolved.
9
+ */
10
+ export declare function resolveProperties<T>(value: {
11
+ [P in keyof T]: T[P] | Promise<T[P]>;
12
+ }): Promise<T>;
13
+ /**
14
+ * Assigns the %%values%% to %%target%% as read-only values.
15
+ *
16
+ * It %%types%% is specified, the values are checked.
17
+ */
18
+ export declare function defineProperties<T>(target: T, values: {
19
+ [K in keyof T]?: T[K];
20
+ }, types?: {
21
+ [K in keyof T]?: string;
22
+ }): void;
@@ -0,0 +1,59 @@
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
+ * Property helper functions.
9
+ *
10
+ * @_subsection api/utils:Properties [about-properties]
11
+ */
12
+ function checkType(value, type, name) {
13
+ const types = type.split("|").map(t => t.trim());
14
+ for (let i = 0; i < types.length; i++) {
15
+ switch (type) {
16
+ case "any":
17
+ return;
18
+ case "bigint":
19
+ case "boolean":
20
+ case "number":
21
+ case "string":
22
+ if (typeof (value) === type) {
23
+ return;
24
+ }
25
+ }
26
+ }
27
+ const error = new Error(`invalid value for type ${type}`);
28
+ error.code = "INVALID_ARGUMENT";
29
+ error.argument = `value.${name}`;
30
+ error.value = value;
31
+ throw error;
32
+ }
33
+ /**
34
+ * Resolves to a new object that is a copy of %%value%%, but with all
35
+ * values resolved.
36
+ */
37
+ export async function resolveProperties(value) {
38
+ const keys = Object.keys(value);
39
+ const results = await Promise.all(keys.map((k) => Promise.resolve(value[k])));
40
+ return results.reduce((accum, v, index) => {
41
+ accum[keys[index]] = v;
42
+ return accum;
43
+ }, {});
44
+ }
45
+ /**
46
+ * Assigns the %%values%% to %%target%% as read-only values.
47
+ *
48
+ * It %%types%% is specified, the values are checked.
49
+ */
50
+ export function defineProperties(target, values, types) {
51
+ for (let key in values) {
52
+ let value = values[key];
53
+ const type = (types ? types[key] : null);
54
+ if (type) {
55
+ checkType(value, type, key);
56
+ }
57
+ Object.defineProperty(target, key, { enumerable: true, value, writable: false });
58
+ }
59
+ }
@@ -0,0 +1,5 @@
1
+ import type { BytesLike, RlpStructuredData } from "./index.js";
2
+ /**
3
+ * Decodes %%data%% into the structured data it represents.
4
+ */
5
+ export declare function decodeRlp(_data: BytesLike): RlpStructuredData;
@@ -0,0 +1,84 @@
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
+ //See: https://github.com/ethereum/wiki/wiki/RLP
8
+ import { hexlify } from "./data.js";
9
+ import { assert, assertArgument } from "./errors.js";
10
+ import { getBytes } from "./data.js";
11
+ function hexlifyByte(value) {
12
+ let result = value.toString(16);
13
+ while (result.length < 2) {
14
+ result = "0" + result;
15
+ }
16
+ return "0x" + result;
17
+ }
18
+ function unarrayifyInteger(data, offset, length) {
19
+ let result = 0;
20
+ for (let i = 0; i < length; i++) {
21
+ result = (result * 256) + data[offset + i];
22
+ }
23
+ return result;
24
+ }
25
+ function _decodeChildren(data, offset, childOffset, length) {
26
+ const result = [];
27
+ while (childOffset < offset + 1 + length) {
28
+ const decoded = _decode(data, childOffset);
29
+ result.push(decoded.result);
30
+ childOffset += decoded.consumed;
31
+ assert(childOffset <= offset + 1 + length, "child data too short", "BUFFER_OVERRUN", {
32
+ buffer: data, length, offset
33
+ });
34
+ }
35
+ return { consumed: (1 + length), result: result };
36
+ }
37
+ // returns { consumed: number, result: Object }
38
+ function _decode(data, offset) {
39
+ assert(data.length !== 0, "data too short", "BUFFER_OVERRUN", {
40
+ buffer: data, length: 0, offset: 1
41
+ });
42
+ const checkOffset = (offset) => {
43
+ assert(offset <= data.length, "data short segment too short", "BUFFER_OVERRUN", {
44
+ buffer: data, length: data.length, offset
45
+ });
46
+ };
47
+ // Array with extra length prefix
48
+ if (data[offset] >= 0xf8) {
49
+ const lengthLength = data[offset] - 0xf7;
50
+ checkOffset(offset + 1 + lengthLength);
51
+ const length = unarrayifyInteger(data, offset + 1, lengthLength);
52
+ checkOffset(offset + 1 + lengthLength + length);
53
+ return _decodeChildren(data, offset, offset + 1 + lengthLength, lengthLength + length);
54
+ }
55
+ else if (data[offset] >= 0xc0) {
56
+ const length = data[offset] - 0xc0;
57
+ checkOffset(offset + 1 + length);
58
+ return _decodeChildren(data, offset, offset + 1, length);
59
+ }
60
+ else if (data[offset] >= 0xb8) {
61
+ const lengthLength = data[offset] - 0xb7;
62
+ checkOffset(offset + 1 + lengthLength);
63
+ const length = unarrayifyInteger(data, offset + 1, lengthLength);
64
+ checkOffset(offset + 1 + lengthLength + length);
65
+ const result = hexlify(data.slice(offset + 1 + lengthLength, offset + 1 + lengthLength + length));
66
+ return { consumed: (1 + lengthLength + length), result: result };
67
+ }
68
+ else if (data[offset] >= 0x80) {
69
+ const length = data[offset] - 0x80;
70
+ checkOffset(offset + 1 + length);
71
+ const result = hexlify(data.slice(offset + 1, offset + 1 + length));
72
+ return { consumed: (1 + length), result: result };
73
+ }
74
+ return { consumed: 1, result: hexlifyByte(data[offset]) };
75
+ }
76
+ /**
77
+ * Decodes %%data%% into the structured data it represents.
78
+ */
79
+ export function decodeRlp(_data) {
80
+ const data = getBytes(_data, "data");
81
+ const decoded = _decode(data, 0);
82
+ assertArgument(decoded.consumed === data.length, "unexpected junk after rlp payload", "data", _data);
83
+ return decoded.result;
84
+ }
@@ -0,0 +1,5 @@
1
+ import type { RlpStructuredDataish } from "./rlp.js";
2
+ /**
3
+ * Encodes %%object%% as an RLP-encoded [[DataHexString]].
4
+ */
5
+ export declare function encodeRlp(object: RlpStructuredDataish): string;
@@ -0,0 +1,54 @@
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
+ //See: https://github.com/ethereum/wiki/wiki/RLP
8
+ import { getBytes } from "./data.js";
9
+ function arrayifyInteger(value) {
10
+ const result = [];
11
+ while (value) {
12
+ result.unshift(value & 0xff);
13
+ value >>= 8;
14
+ }
15
+ return result;
16
+ }
17
+ function _encode(object) {
18
+ if (Array.isArray(object)) {
19
+ let payload = [];
20
+ object.forEach(function (child) {
21
+ payload = payload.concat(_encode(child));
22
+ });
23
+ if (payload.length <= 55) {
24
+ payload.unshift(0xc0 + payload.length);
25
+ return payload;
26
+ }
27
+ const length = arrayifyInteger(payload.length);
28
+ length.unshift(0xf7 + length.length);
29
+ return length.concat(payload);
30
+ }
31
+ const data = Array.prototype.slice.call(getBytes(object, "object"));
32
+ if (data.length === 1 && data[0] <= 0x7f) {
33
+ return data;
34
+ }
35
+ else if (data.length <= 55) {
36
+ data.unshift(0x80 + data.length);
37
+ return data;
38
+ }
39
+ const length = arrayifyInteger(data.length);
40
+ length.unshift(0xb7 + length.length);
41
+ return length.concat(data);
42
+ }
43
+ const nibbles = "0123456789abcdef";
44
+ /**
45
+ * Encodes %%object%% as an RLP-encoded [[DataHexString]].
46
+ */
47
+ export function encodeRlp(object) {
48
+ let result = "0x";
49
+ for (const v of _encode(object)) {
50
+ result += nibbles[v >> 4];
51
+ result += nibbles[v & 0xf];
52
+ }
53
+ return result;
54
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The [[link-rlp]] (RLP) encoding is used throughout Ethereum
3
+ * to serialize nested structures of Arrays and data.
4
+ *
5
+ * @_subsection api/utils:Recursive-Length Prefix [about-rlp]
6
+ */
7
+ export { decodeRlp } from "./rlp-decode.js";
8
+ export { encodeRlp } from "./rlp-encode.js";
9
+ /**
10
+ * An RLP-encoded structure.
11
+ */
12
+ export declare type RlpStructuredData = string | Array<RlpStructuredData>;
13
+ /**
14
+ * An RLP-encoded structure, which allows Uint8Array.
15
+ */
16
+ export declare type RlpStructuredDataish = string | Uint8Array | Array<RlpStructuredDataish>;
@@ -0,0 +1,14 @@
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 [[link-rlp]] (RLP) encoding is used throughout Ethereum
9
+ * to serialize nested structures of Arrays and data.
10
+ *
11
+ * @_subsection api/utils:Recursive-Length Prefix [about-rlp]
12
+ */
13
+ export { decodeRlp } from "./rlp-decode.js";
14
+ export { encodeRlp } from "./rlp-encode.js";
@@ -0,0 +1,23 @@
1
+ import type { BigNumberish, Numeric } from "../utils/index.js";
2
+ /**
3
+ * Converts %%value%% into a //decimal string//, assuming %%unit%% decimal
4
+ * places. The %%unit%% may be the number of decimal places or the name of
5
+ * a unit (e.g. ``"gwei"`` for 9 decimal places).
6
+ *
7
+ */
8
+ export declare function formatUnits(value: BigNumberish, unit?: string | Numeric): string;
9
+ /**
10
+ * Converts the //decimal string// %%value%% to a BigInt, assuming
11
+ * %%unit%% decimal places. The %%unit%% may the number of decimal places
12
+ * or the name of a unit (e.g. ``"gwei"`` for 9 decimal places).
13
+ */
14
+ export declare function parseUnits(value: string, unit?: string | Numeric): bigint;
15
+ /**
16
+ * Converts %%value%% into a //decimal string// using 18 decimal places.
17
+ */
18
+ export declare function formatEther(wei: BigNumberish): string;
19
+ /**
20
+ * Converts the //decimal string// %%ether%% to a BigInt, using 18
21
+ * decimal places.
22
+ */
23
+ export declare function parseEther(ether: string): bigint;
@@ -0,0 +1,88 @@
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
+ * Most interactions with Ethereum requires integer values, which use
9
+ * the smallest magnitude unit.
10
+ *
11
+ * For example, imagine dealing with dollars and cents. Since dollars
12
+ * are divisible, non-integer values are possible, such as ``$10.77``.
13
+ * By using the smallest indivisible unit (i.e. cents), the value can
14
+ * be kept as the integer ``1077``.
15
+ *
16
+ * When receiving decimal input from the user (as a decimal string),
17
+ * the value should be converted to an integer and when showing a user
18
+ * a value, the integer value should be converted to a decimal string.
19
+ *
20
+ * This creates a clear distinction, between values to be used by code
21
+ * (integers) and values used for display logic to users (decimals).
22
+ *
23
+ * The native unit in Ethereum, //ether// is divisible to 18 decimal places,
24
+ * where each individual unit is called a //wei//.
25
+ *
26
+ * @_subsection api/utils:Unit Conversion [about-units]
27
+ */
28
+ import { assertArgument } from "./errors.js";
29
+ import { FixedNumber } from "./fixednumber.js";
30
+ import { getNumber } from "./maths.js";
31
+ const names = [
32
+ "wei",
33
+ "kwei",
34
+ "mwei",
35
+ "gwei",
36
+ "szabo",
37
+ "finney",
38
+ "ether",
39
+ ];
40
+ /**
41
+ * Converts %%value%% into a //decimal string//, assuming %%unit%% decimal
42
+ * places. The %%unit%% may be the number of decimal places or the name of
43
+ * a unit (e.g. ``"gwei"`` for 9 decimal places).
44
+ *
45
+ */
46
+ export function formatUnits(value, unit) {
47
+ let decimals = 18;
48
+ if (typeof (unit) === "string") {
49
+ const index = names.indexOf(unit);
50
+ assertArgument(index >= 0, "invalid unit", "unit", unit);
51
+ decimals = 3 * index;
52
+ }
53
+ else if (unit != null) {
54
+ decimals = getNumber(unit, "unit");
55
+ }
56
+ return FixedNumber.fromValue(value, decimals, { decimals, width: 512 }).toString();
57
+ }
58
+ /**
59
+ * Converts the //decimal string// %%value%% to a BigInt, assuming
60
+ * %%unit%% decimal places. The %%unit%% may the number of decimal places
61
+ * or the name of a unit (e.g. ``"gwei"`` for 9 decimal places).
62
+ */
63
+ export function parseUnits(value, unit) {
64
+ assertArgument(typeof (value) === "string", "value must be a string", "value", value);
65
+ let decimals = 18;
66
+ if (typeof (unit) === "string") {
67
+ const index = names.indexOf(unit);
68
+ assertArgument(index >= 0, "invalid unit", "unit", unit);
69
+ decimals = 3 * index;
70
+ }
71
+ else if (unit != null) {
72
+ decimals = getNumber(unit, "unit");
73
+ }
74
+ return FixedNumber.fromString(value, { decimals, width: 512 }).value;
75
+ }
76
+ /**
77
+ * Converts %%value%% into a //decimal string// using 18 decimal places.
78
+ */
79
+ export function formatEther(wei) {
80
+ return formatUnits(wei, 18);
81
+ }
82
+ /**
83
+ * Converts the //decimal string// %%ether%% to a BigInt, using 18
84
+ * decimal places.
85
+ */
86
+ export function parseEther(ether) {
87
+ return parseUnits(ether, 18);
88
+ }