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.
- package/README.md +6 -5
- package/build.sh +1 -1
- package/dist/ccxt.browser.js +11280 -3407
- package/dist/ccxt.browser.min.js +7 -7
- package/dist/cjs/ccxt.js +4 -1
- package/dist/cjs/src/abstract/hyperliquid.js +9 -0
- package/dist/cjs/src/base/Exchange.js +22 -1
- package/dist/cjs/src/base/functions/encode.js +5 -0
- package/dist/cjs/src/base/functions.js +1 -0
- package/dist/cjs/src/bitfinex2.js +1 -1
- package/dist/cjs/src/bitget.js +74 -23
- package/dist/cjs/src/coinbase.js +108 -103
- package/dist/cjs/src/coinex.js +61 -1
- package/dist/cjs/src/hyperliquid.js +2035 -0
- package/dist/cjs/src/kraken.js +8 -2
- package/dist/cjs/src/krakenfutures.js +28 -0
- package/dist/cjs/src/kucoinfutures.js +2 -2
- package/dist/cjs/src/okx.js +1 -1
- package/dist/cjs/src/phemex.js +2 -2
- package/dist/cjs/src/pro/bingx.js +1 -0
- package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +158 -0
- package/dist/cjs/src/static_dependencies/ethers/address/address.js +144 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +407 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/address.js +45 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +28 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/array.js +176 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +27 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +52 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +45 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/null.js +30 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/number.js +60 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/string.js +27 -0
- package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +68 -0
- package/dist/cjs/src/static_dependencies/ethers/fragments.js +614 -0
- package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +492 -0
- package/dist/cjs/src/static_dependencies/ethers/index.js +35 -0
- package/dist/cjs/src/static_dependencies/ethers/interface.js +44 -0
- package/dist/cjs/src/static_dependencies/ethers/typed.js +618 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +20 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/data.js +134 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +228 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/events.js +13 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +29 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/index.js +53 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +231 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +47 -0
- package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +218 -0
- package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +292 -0
- package/dist/cjs/src/tokocrypto.js +22 -2
- package/dist/cjs/src/wazirx.js +308 -3
- package/js/ccxt.d.ts +5 -2
- package/js/ccxt.js +4 -2
- package/js/src/abstract/coinbase.d.ts +3 -3
- package/js/src/abstract/hyperliquid.d.ts +9 -0
- package/js/src/abstract/hyperliquid.js +11 -0
- package/js/src/base/Exchange.d.ts +4 -0
- package/js/src/base/Exchange.js +13 -1
- package/js/src/base/functions/encode.d.ts +2 -1
- package/js/src/base/functions/encode.js +5 -1
- package/js/src/bitfinex2.js +1 -1
- package/js/src/bitget.js +74 -23
- package/js/src/coinbase.js +108 -103
- package/js/src/coinex.d.ts +3 -1
- package/js/src/coinex.js +61 -1
- package/js/src/hyperliquid.d.ts +83 -0
- package/js/src/hyperliquid.js +2036 -0
- package/js/src/kraken.js +8 -2
- package/js/src/krakenfutures.d.ts +2 -1
- package/js/src/krakenfutures.js +28 -0
- package/js/src/kucoinfutures.js +2 -2
- package/js/src/okx.js +1 -1
- package/js/src/phemex.js +2 -2
- package/js/src/pro/bingx.js +1 -0
- package/js/src/static_dependencies/ethers/abi-coder.d.ts +50 -0
- package/js/src/static_dependencies/ethers/abi-coder.js +148 -0
- package/js/src/static_dependencies/ethers/address/address.d.ts +55 -0
- package/js/src/static_dependencies/ethers/address/address.js +162 -0
- package/js/src/static_dependencies/ethers/address/checks.d.ts +80 -0
- package/js/src/static_dependencies/ethers/address/checks.js +119 -0
- package/js/src/static_dependencies/ethers/address/contract-address.d.ts +47 -0
- package/js/src/static_dependencies/ethers/address/contract-address.js +73 -0
- package/js/src/static_dependencies/ethers/address/index.d.ts +48 -0
- package/js/src/static_dependencies/ethers/address/index.js +24 -0
- package/js/src/static_dependencies/ethers/bytes32.d.ts +14 -0
- package/js/src/static_dependencies/ethers/bytes32.js +45 -0
- package/js/src/static_dependencies/ethers/coders/abstract-coder.d.ts +120 -0
- package/js/src/static_dependencies/ethers/coders/abstract-coder.js +424 -0
- package/js/src/static_dependencies/ethers/coders/address.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/address.js +34 -0
- package/js/src/static_dependencies/ethers/coders/anonymous.d.ts +14 -0
- package/js/src/static_dependencies/ethers/coders/anonymous.js +27 -0
- package/js/src/static_dependencies/ethers/coders/array.d.ts +24 -0
- package/js/src/static_dependencies/ethers/coders/array.js +162 -0
- package/js/src/static_dependencies/ethers/coders/boolean.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/boolean.js +26 -0
- package/js/src/static_dependencies/ethers/coders/bytes.d.ts +18 -0
- package/js/src/static_dependencies/ethers/coders/bytes.js +39 -0
- package/js/src/static_dependencies/ethers/coders/fixed-bytes.d.ts +14 -0
- package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +32 -0
- package/js/src/static_dependencies/ethers/coders/null.d.ts +11 -0
- package/js/src/static_dependencies/ethers/coders/null.js +29 -0
- package/js/src/static_dependencies/ethers/coders/number.d.ts +15 -0
- package/js/src/static_dependencies/ethers/coders/number.js +48 -0
- package/js/src/static_dependencies/ethers/coders/string.d.ts +12 -0
- package/js/src/static_dependencies/ethers/coders/string.js +26 -0
- package/js/src/static_dependencies/ethers/coders/tuple.d.ts +15 -0
- package/js/src/static_dependencies/ethers/coders/tuple.js +67 -0
- package/js/src/static_dependencies/ethers/fragments.d.ts +458 -0
- package/js/src/static_dependencies/ethers/fragments.js +1252 -0
- package/js/src/static_dependencies/ethers/hash/index.d.ts +10 -0
- package/js/src/static_dependencies/ethers/hash/index.js +15 -0
- package/js/src/static_dependencies/ethers/hash/solidity.d.ts +30 -0
- package/js/src/static_dependencies/ethers/hash/solidity.js +107 -0
- package/js/src/static_dependencies/ethers/hash/typed-data.d.ts +144 -0
- package/js/src/static_dependencies/ethers/hash/typed-data.js +490 -0
- package/js/src/static_dependencies/ethers/index.d.ts +19 -0
- package/js/src/static_dependencies/ethers/index.js +22 -0
- package/js/src/static_dependencies/ethers/interface.d.ts +380 -0
- package/js/src/static_dependencies/ethers/interface.js +990 -0
- package/js/src/static_dependencies/ethers/typed.d.ts +569 -0
- package/js/src/static_dependencies/ethers/typed.js +608 -0
- package/js/src/static_dependencies/ethers/utils/base58.d.ts +22 -0
- package/js/src/static_dependencies/ethers/utils/base58.js +68 -0
- package/js/src/static_dependencies/ethers/utils/base64-browser.d.ts +3 -0
- package/js/src/static_dependencies/ethers/utils/base64-browser.js +24 -0
- package/js/src/static_dependencies/ethers/utils/base64.d.ts +39 -0
- package/js/src/static_dependencies/ethers/utils/base64.js +58 -0
- package/js/src/static_dependencies/ethers/utils/data.d.ts +92 -0
- package/js/src/static_dependencies/ethers/utils/data.js +175 -0
- package/js/src/static_dependencies/ethers/utils/errors.d.ts +509 -0
- package/js/src/static_dependencies/ethers/utils/errors.js +227 -0
- package/js/src/static_dependencies/ethers/utils/events.d.ts +76 -0
- package/js/src/static_dependencies/ethers/utils/events.js +52 -0
- package/js/src/static_dependencies/ethers/utils/fixednumber.d.ts +251 -0
- package/js/src/static_dependencies/ethers/utils/fixednumber.js +529 -0
- package/js/src/static_dependencies/ethers/utils/index.d.ts +30 -0
- package/js/src/static_dependencies/ethers/utils/index.js +38 -0
- package/js/src/static_dependencies/ethers/utils/maths.d.ts +65 -0
- package/js/src/static_dependencies/ethers/utils/maths.js +220 -0
- package/js/src/static_dependencies/ethers/utils/properties.d.ts +22 -0
- package/js/src/static_dependencies/ethers/utils/properties.js +59 -0
- package/js/src/static_dependencies/ethers/utils/rlp-decode.d.ts +5 -0
- package/js/src/static_dependencies/ethers/utils/rlp-decode.js +84 -0
- package/js/src/static_dependencies/ethers/utils/rlp-encode.d.ts +5 -0
- package/js/src/static_dependencies/ethers/utils/rlp-encode.js +54 -0
- package/js/src/static_dependencies/ethers/utils/rlp.d.ts +16 -0
- package/js/src/static_dependencies/ethers/utils/rlp.js +14 -0
- package/js/src/static_dependencies/ethers/utils/units.d.ts +23 -0
- package/js/src/static_dependencies/ethers/utils/units.js +88 -0
- package/js/src/static_dependencies/ethers/utils/utf8.d.ts +95 -0
- package/js/src/static_dependencies/ethers/utils/utf8.js +225 -0
- package/js/src/static_dependencies/ethers/utils/uuid.d.ts +7 -0
- package/js/src/static_dependencies/ethers/utils/uuid.js +35 -0
- package/js/src/static_dependencies/messagepack/msgpack.d.ts +2 -0
- package/js/src/static_dependencies/messagepack/msgpack.js +572 -0
- package/js/src/tokocrypto.js +22 -2
- package/js/src/wazirx.d.ts +12 -1
- package/js/src/wazirx.js +308 -3
- package/package.json +1 -1
- package/skip-tests.json +18 -0
package/dist/cjs/src/kraken.js
CHANGED
|
@@ -1547,8 +1547,14 @@ class kraken extends kraken$1 {
|
|
|
1547
1547
|
// }
|
|
1548
1548
|
// }
|
|
1549
1549
|
//
|
|
1550
|
-
const description = this.
|
|
1551
|
-
|
|
1550
|
+
const description = this.safeDict(order, 'descr', {});
|
|
1551
|
+
let orderDescription = undefined;
|
|
1552
|
+
if (description !== undefined) {
|
|
1553
|
+
orderDescription = this.safeString(description, 'order');
|
|
1554
|
+
}
|
|
1555
|
+
else {
|
|
1556
|
+
orderDescription = this.safeString(order, 'descr');
|
|
1557
|
+
}
|
|
1552
1558
|
let side = undefined;
|
|
1553
1559
|
let type = undefined;
|
|
1554
1560
|
let marketId = undefined;
|
|
@@ -55,6 +55,7 @@ class krakenfutures extends krakenfutures$1 {
|
|
|
55
55
|
'fetchIsolatedBorrowRates': false,
|
|
56
56
|
'fetchIsolatedPositions': false,
|
|
57
57
|
'fetchLeverage': true,
|
|
58
|
+
'fetchLeverages': true,
|
|
58
59
|
'fetchLeverageTiers': true,
|
|
59
60
|
'fetchMarketLeverageTiers': 'emulated',
|
|
60
61
|
'fetchMarkets': true,
|
|
@@ -2456,6 +2457,33 @@ class krakenfutures extends krakenfutures$1 {
|
|
|
2456
2457
|
//
|
|
2457
2458
|
return await this.privatePutLeveragepreferences(this.extend(request, params));
|
|
2458
2459
|
}
|
|
2460
|
+
async fetchLeverages(symbols = undefined, params = {}) {
|
|
2461
|
+
/**
|
|
2462
|
+
* @method
|
|
2463
|
+
* @name krakenfutures#fetchLeverages
|
|
2464
|
+
* @description fetch the set leverage for all contract and margin markets
|
|
2465
|
+
* @see https://docs.futures.kraken.com/#http-api-trading-v3-api-multi-collateral-get-the-leverage-setting-for-a-market
|
|
2466
|
+
* @param {string[]} [symbols] a list of unified market symbols
|
|
2467
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
2468
|
+
* @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/#/?id=leverage-structure}
|
|
2469
|
+
*/
|
|
2470
|
+
await this.loadMarkets();
|
|
2471
|
+
const response = await this.privateGetLeveragepreferences(params);
|
|
2472
|
+
//
|
|
2473
|
+
// {
|
|
2474
|
+
// "result": "success",
|
|
2475
|
+
// "serverTime": "2024-03-06T02:35:46.336Z",
|
|
2476
|
+
// "leveragePreferences": [
|
|
2477
|
+
// {
|
|
2478
|
+
// "symbol": "PF_ETHUSD",
|
|
2479
|
+
// "maxLeverage": 30.00
|
|
2480
|
+
// },
|
|
2481
|
+
// ]
|
|
2482
|
+
// }
|
|
2483
|
+
//
|
|
2484
|
+
const leveragePreferences = this.safeList(response, 'leveragePreferences', []);
|
|
2485
|
+
return this.parseLeverages(leveragePreferences, symbols, 'symbol');
|
|
2486
|
+
}
|
|
2459
2487
|
async fetchLeverage(symbol, params = {}) {
|
|
2460
2488
|
/**
|
|
2461
2489
|
* @method
|
|
@@ -2071,8 +2071,8 @@ class kucoinfutures extends kucoinfutures$1 {
|
|
|
2071
2071
|
// }
|
|
2072
2072
|
// }
|
|
2073
2073
|
//
|
|
2074
|
-
const data = this.
|
|
2075
|
-
const trades = this.
|
|
2074
|
+
const data = this.safeDict(response, 'data', {});
|
|
2075
|
+
const trades = this.safeList(data, 'items', []);
|
|
2076
2076
|
return this.parseTrades(trades, market, since, limit);
|
|
2077
2077
|
}
|
|
2078
2078
|
async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
|
package/dist/cjs/src/okx.js
CHANGED
|
@@ -5668,7 +5668,7 @@ class okx extends okx$1 {
|
|
|
5668
5668
|
const fromAccountId = this.safeString(transfer, 'from');
|
|
5669
5669
|
const toAccountId = this.safeString(transfer, 'to');
|
|
5670
5670
|
const accountsById = this.safeValue(this.options, 'accountsById', {});
|
|
5671
|
-
const timestamp = this.safeInteger(transfer, 'ts'
|
|
5671
|
+
const timestamp = this.safeInteger(transfer, 'ts');
|
|
5672
5672
|
const balanceChange = this.safeString(transfer, 'sz');
|
|
5673
5673
|
if (balanceChange !== undefined) {
|
|
5674
5674
|
amount = this.parseNumber(Precise["default"].stringAbs(balanceChange));
|
package/dist/cjs/src/phemex.js
CHANGED
|
@@ -3358,7 +3358,7 @@ class phemex extends phemex$1 {
|
|
|
3358
3358
|
// ]
|
|
3359
3359
|
// }
|
|
3360
3360
|
//
|
|
3361
|
-
const data = this.
|
|
3361
|
+
const data = this.safeList(response, 'data', []);
|
|
3362
3362
|
return this.parseTransactions(data, currency, since, limit);
|
|
3363
3363
|
}
|
|
3364
3364
|
async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
|
|
@@ -3398,7 +3398,7 @@ class phemex extends phemex$1 {
|
|
|
3398
3398
|
// ]
|
|
3399
3399
|
// }
|
|
3400
3400
|
//
|
|
3401
|
-
const data = this.
|
|
3401
|
+
const data = this.safeList(response, 'data', []);
|
|
3402
3402
|
return this.parseTransactions(data, currency, since, limit);
|
|
3403
3403
|
}
|
|
3404
3404
|
parseTransactionStatus(status) {
|
|
@@ -556,6 +556,7 @@ class bingx extends bingx$1 {
|
|
|
556
556
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
557
557
|
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
|
|
558
558
|
*/
|
|
559
|
+
await this.loadMarkets();
|
|
559
560
|
const market = this.market(symbol);
|
|
560
561
|
const [marketType, query] = this.handleMarketTypeAndParams('watchOHLCV', market, params);
|
|
561
562
|
const url = this.safeValue(this.urls['api']['ws'], marketType);
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('./utils/base58.js');
|
|
6
|
+
var errors = require('./utils/errors.js');
|
|
7
|
+
require('./utils/events.js');
|
|
8
|
+
require('./utils/fixednumber.js');
|
|
9
|
+
require('./utils/maths.js');
|
|
10
|
+
require('./utils/utf8.js');
|
|
11
|
+
require('../../base/functions/platform.js');
|
|
12
|
+
require('../../base/functions/encode.js');
|
|
13
|
+
require('../../base/functions/crypto.js');
|
|
14
|
+
require('../noble-hashes/sha3.js');
|
|
15
|
+
require('../noble-hashes/sha256.js');
|
|
16
|
+
var abstractCoder = require('./coders/abstract-coder.js');
|
|
17
|
+
var address = require('./coders/address.js');
|
|
18
|
+
var array = require('./coders/array.js');
|
|
19
|
+
var boolean = require('./coders/boolean.js');
|
|
20
|
+
var bytes = require('./coders/bytes.js');
|
|
21
|
+
var fixedBytes = require('./coders/fixed-bytes.js');
|
|
22
|
+
var _null = require('./coders/null.js');
|
|
23
|
+
var number = require('./coders/number.js');
|
|
24
|
+
var string = require('./coders/string.js');
|
|
25
|
+
var tuple = require('./coders/tuple.js');
|
|
26
|
+
var fragments = require('./fragments.js');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* When sending values to or receiving values from a [[Contract]], the
|
|
30
|
+
* data is generally encoded using the [ABI standard](link-solc-abi).
|
|
31
|
+
*
|
|
32
|
+
* The AbiCoder provides a utility to encode values to ABI data and
|
|
33
|
+
* decode values from ABI data.
|
|
34
|
+
*
|
|
35
|
+
* Most of the time, developers should favour the [[Contract]] class,
|
|
36
|
+
* which further abstracts a lot of the finer details of ABI data.
|
|
37
|
+
*
|
|
38
|
+
* @_section api/abi/abi-coder:ABI Encoding
|
|
39
|
+
*/
|
|
40
|
+
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
41
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
42
|
+
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");
|
|
43
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
44
|
+
};
|
|
45
|
+
var _AbiCoder_instances, _AbiCoder_getCoder;
|
|
46
|
+
// https://docs.soliditylang.org/en/v0.8.17/control-structures.html
|
|
47
|
+
const PanicReasons = new Map();
|
|
48
|
+
PanicReasons.set(0x00, "GENERIC_PANIC");
|
|
49
|
+
PanicReasons.set(0x01, "ASSERT_FALSE");
|
|
50
|
+
PanicReasons.set(0x11, "OVERFLOW");
|
|
51
|
+
PanicReasons.set(0x12, "DIVIDE_BY_ZERO");
|
|
52
|
+
PanicReasons.set(0x21, "ENUM_RANGE_ERROR");
|
|
53
|
+
PanicReasons.set(0x22, "BAD_STORAGE_DATA");
|
|
54
|
+
PanicReasons.set(0x31, "STACK_UNDERFLOW");
|
|
55
|
+
PanicReasons.set(0x32, "ARRAY_RANGE_ERROR");
|
|
56
|
+
PanicReasons.set(0x41, "OUT_OF_MEMORY");
|
|
57
|
+
PanicReasons.set(0x51, "UNINITIALIZED_FUNCTION_CALL");
|
|
58
|
+
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
|
59
|
+
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
|
60
|
+
let defaultCoder = null;
|
|
61
|
+
let defaultMaxInflation = 1024;
|
|
62
|
+
/**
|
|
63
|
+
* The **AbiCoder** is a low-level class responsible for encoding JavaScript
|
|
64
|
+
* values into binary data and decoding binary data into JavaScript values.
|
|
65
|
+
*/
|
|
66
|
+
class AbiCoder {
|
|
67
|
+
constructor() {
|
|
68
|
+
_AbiCoder_instances.add(this);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the default values for the given %%types%%.
|
|
72
|
+
*
|
|
73
|
+
* For example, a ``uint`` is by default ``0`` and ``bool``
|
|
74
|
+
* is by default ``false``.
|
|
75
|
+
*/
|
|
76
|
+
getDefaultValue(types) {
|
|
77
|
+
const coders = types.map((type) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, fragments.ParamType.from(type)));
|
|
78
|
+
const coder = new tuple.TupleCoder(coders, "_");
|
|
79
|
+
return coder.defaultValue();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Encode the %%values%% as the %%types%% into ABI data.
|
|
83
|
+
*
|
|
84
|
+
* @returns DataHexstring
|
|
85
|
+
*/
|
|
86
|
+
encode(types, values) {
|
|
87
|
+
errors.assertArgumentCount(values.length, types.length, "types/values length mismatch");
|
|
88
|
+
const coders = types.map((type) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, fragments.ParamType.from(type)));
|
|
89
|
+
const coder = (new tuple.TupleCoder(coders, "_"));
|
|
90
|
+
const writer = new abstractCoder.Writer();
|
|
91
|
+
coder.encode(writer, values);
|
|
92
|
+
return writer.data;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Decode the ABI %%data%% as the %%types%% into values.
|
|
96
|
+
*
|
|
97
|
+
* If %%loose%% decoding is enabled, then strict padding is
|
|
98
|
+
* not enforced. Some older versions of Solidity incorrectly
|
|
99
|
+
* padded event data emitted from ``external`` functions.
|
|
100
|
+
*/
|
|
101
|
+
decode(types, data, loose) {
|
|
102
|
+
const coders = types.map((type) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, fragments.ParamType.from(type)));
|
|
103
|
+
const coder = new tuple.TupleCoder(coders, "_");
|
|
104
|
+
return coder.decode(new abstractCoder.Reader(data, loose, defaultMaxInflation));
|
|
105
|
+
}
|
|
106
|
+
static _setDefaultMaxInflation(value) {
|
|
107
|
+
errors.assertArgument(typeof (value) === "number" && Number.isInteger(value), "invalid defaultMaxInflation factor", "value", value);
|
|
108
|
+
defaultMaxInflation = value;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns the shared singleton instance of a default [[AbiCoder]].
|
|
112
|
+
*
|
|
113
|
+
* On the first call, the instance is created internally.
|
|
114
|
+
*/
|
|
115
|
+
static defaultAbiCoder() {
|
|
116
|
+
if (defaultCoder == null) {
|
|
117
|
+
defaultCoder = new AbiCoder();
|
|
118
|
+
}
|
|
119
|
+
return defaultCoder;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
_AbiCoder_instances = new WeakSet(), _AbiCoder_getCoder = function _AbiCoder_getCoder(param) {
|
|
123
|
+
if (param.isArray()) {
|
|
124
|
+
return new array.ArrayCoder(__classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, param.arrayChildren), param.arrayLength, param.name);
|
|
125
|
+
}
|
|
126
|
+
if (param.isTuple()) {
|
|
127
|
+
return new tuple.TupleCoder(param.components.map((c) => __classPrivateFieldGet(this, _AbiCoder_instances, "m", _AbiCoder_getCoder).call(this, c)), param.name);
|
|
128
|
+
}
|
|
129
|
+
switch (param.baseType) {
|
|
130
|
+
case "address":
|
|
131
|
+
return new address.AddressCoder(param.name);
|
|
132
|
+
case "bool":
|
|
133
|
+
return new boolean.BooleanCoder(param.name);
|
|
134
|
+
case "string":
|
|
135
|
+
return new string.StringCoder(param.name);
|
|
136
|
+
case "bytes":
|
|
137
|
+
return new bytes.BytesCoder(param.name);
|
|
138
|
+
case "":
|
|
139
|
+
return new _null.NullCoder(param.name);
|
|
140
|
+
}
|
|
141
|
+
// u?int[0-9]*
|
|
142
|
+
let match = param.type.match(paramTypeNumber);
|
|
143
|
+
if (match) {
|
|
144
|
+
let size = parseInt(match[2] || "256");
|
|
145
|
+
errors.assertArgument(size !== 0 && size <= 256 && (size % 8) === 0, "invalid " + match[1] + " bit length", "param", param);
|
|
146
|
+
return new number.NumberCoder(size / 8, (match[1] === "int"), param.name);
|
|
147
|
+
}
|
|
148
|
+
// bytes[0-9]+
|
|
149
|
+
match = param.type.match(paramTypeBytes);
|
|
150
|
+
if (match) {
|
|
151
|
+
let size = parseInt(match[1]);
|
|
152
|
+
errors.assertArgument(size !== 0 && size <= 32, "invalid bytes length", "param", param);
|
|
153
|
+
return new fixedBytes.FixedBytesCoder(size, param.name);
|
|
154
|
+
}
|
|
155
|
+
errors.assertArgument(false, "invalid type", "type", param.type);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
exports.AbiCoder = AbiCoder;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var sha3 = require('../../noble-hashes/sha3.js');
|
|
6
|
+
require('../utils/base58.js');
|
|
7
|
+
var errors = require('../utils/errors.js');
|
|
8
|
+
require('../utils/events.js');
|
|
9
|
+
require('../utils/fixednumber.js');
|
|
10
|
+
require('../utils/maths.js');
|
|
11
|
+
require('../utils/utf8.js');
|
|
12
|
+
require('../../../base/functions/platform.js');
|
|
13
|
+
require('../../../base/functions/encode.js');
|
|
14
|
+
require('../../../base/functions/crypto.js');
|
|
15
|
+
require('../../noble-hashes/sha256.js');
|
|
16
|
+
|
|
17
|
+
// TODO: unify address functions in other language? or remove it?
|
|
18
|
+
const BN_0 = BigInt(0);
|
|
19
|
+
const BN_36 = BigInt(36);
|
|
20
|
+
function getChecksumAddress(address) {
|
|
21
|
+
// if (!isHexString(address, 20)) {
|
|
22
|
+
// logger.throwArgumentError("invalid address", "address", address);
|
|
23
|
+
// }
|
|
24
|
+
address = address.toLowerCase();
|
|
25
|
+
const chars = address.substring(2).split("");
|
|
26
|
+
const expanded = new Uint8Array(40);
|
|
27
|
+
for (let i = 0; i < 40; i++) {
|
|
28
|
+
expanded[i] = chars[i].charCodeAt(0);
|
|
29
|
+
}
|
|
30
|
+
const hashed = sha3.keccak_256(expanded);
|
|
31
|
+
for (let i = 0; i < 40; i += 2) {
|
|
32
|
+
if ((hashed[i >> 1] >> 4) >= 8) {
|
|
33
|
+
chars[i] = chars[i].toUpperCase();
|
|
34
|
+
}
|
|
35
|
+
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
|
36
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return "0x" + chars.join("");
|
|
40
|
+
}
|
|
41
|
+
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
|
42
|
+
// Create lookup table
|
|
43
|
+
const ibanLookup = {};
|
|
44
|
+
for (let i = 0; i < 10; i++) {
|
|
45
|
+
ibanLookup[String(i)] = String(i);
|
|
46
|
+
}
|
|
47
|
+
for (let i = 0; i < 26; i++) {
|
|
48
|
+
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
|
49
|
+
}
|
|
50
|
+
// How many decimal digits can we process? (for 64-bit float, this is 15)
|
|
51
|
+
// i.e. Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
|
|
52
|
+
const safeDigits = 15;
|
|
53
|
+
function ibanChecksum(address) {
|
|
54
|
+
address = address.toUpperCase();
|
|
55
|
+
address = address.substring(4) + address.substring(0, 2) + "00";
|
|
56
|
+
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
|
|
57
|
+
// Javascript can handle integers safely up to 15 (decimal) digits
|
|
58
|
+
while (expanded.length >= safeDigits) {
|
|
59
|
+
let block = expanded.substring(0, safeDigits);
|
|
60
|
+
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
|
61
|
+
}
|
|
62
|
+
let checksum = String(98 - (parseInt(expanded, 10) % 97));
|
|
63
|
+
while (checksum.length < 2) {
|
|
64
|
+
checksum = "0" + checksum;
|
|
65
|
+
}
|
|
66
|
+
return checksum;
|
|
67
|
+
}
|
|
68
|
+
const Base36 = (function () {
|
|
69
|
+
const result = {};
|
|
70
|
+
for (let i = 0; i < 36; i++) {
|
|
71
|
+
const key = "0123456789abcdefghijklmnopqrstuvwxyz"[i];
|
|
72
|
+
result[key] = BigInt(i);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
})();
|
|
76
|
+
function fromBase36(value) {
|
|
77
|
+
value = value.toLowerCase();
|
|
78
|
+
let result = BN_0;
|
|
79
|
+
for (let i = 0; i < value.length; i++) {
|
|
80
|
+
result = result * BN_36 + Base36[value[i]];
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns a normalized and checksumed address for %%address%%.
|
|
86
|
+
* This accepts non-checksum addresses, checksum addresses and
|
|
87
|
+
* [[getIcapAddress]] formats.
|
|
88
|
+
*
|
|
89
|
+
* The checksum in Ethereum uses the capitalization (upper-case
|
|
90
|
+
* vs lower-case) of the characters within an address to encode
|
|
91
|
+
* its checksum, which offers, on average, a checksum of 15-bits.
|
|
92
|
+
*
|
|
93
|
+
* If %%address%% contains both upper-case and lower-case, it is
|
|
94
|
+
* assumed to already be a checksum address and its checksum is
|
|
95
|
+
* validated, and if the address fails its expected checksum an
|
|
96
|
+
* error is thrown.
|
|
97
|
+
*
|
|
98
|
+
* If you wish the checksum of %%address%% to be ignore, it should
|
|
99
|
+
* be converted to lower-case (i.e. ``.toLowercase()``) before
|
|
100
|
+
* being passed in. This should be a very rare situation though,
|
|
101
|
+
* that you wish to bypass the safegaurds in place to protect
|
|
102
|
+
* against an address that has been incorrectly copied from another
|
|
103
|
+
* source.
|
|
104
|
+
*
|
|
105
|
+
* @example:
|
|
106
|
+
* // Adds the checksum (via upper-casing specific letters)
|
|
107
|
+
* getAddress("0x8ba1f109551bd432803012645ac136ddd64dba72")
|
|
108
|
+
* //_result:
|
|
109
|
+
*
|
|
110
|
+
* // Converts ICAP address and adds checksum
|
|
111
|
+
* getAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36");
|
|
112
|
+
* //_result:
|
|
113
|
+
*
|
|
114
|
+
* // Throws an error if an address contains mixed case,
|
|
115
|
+
* // but the checksum fails
|
|
116
|
+
* getAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72")
|
|
117
|
+
* //_error:
|
|
118
|
+
*/
|
|
119
|
+
function getAddress(address) {
|
|
120
|
+
errors.assertArgument(typeof (address) === "string", "invalid address", "address", address);
|
|
121
|
+
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
|
122
|
+
// Missing the 0x prefix
|
|
123
|
+
if (!address.startsWith("0x")) {
|
|
124
|
+
address = "0x" + address;
|
|
125
|
+
}
|
|
126
|
+
const result = getChecksumAddress(address);
|
|
127
|
+
// It is a checksummed address with a bad checksum
|
|
128
|
+
errors.assertArgument(!address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) || result === address, "bad address checksum", "address", address);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
// Maybe ICAP? (we only support direct mode)
|
|
132
|
+
if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
|
133
|
+
// It is an ICAP address with a bad checksum
|
|
134
|
+
errors.assertArgument(address.substring(2, 4) === ibanChecksum(address), "bad icap checksum", "address", address);
|
|
135
|
+
let result = fromBase36(address.substring(4)).toString(16);
|
|
136
|
+
while (result.length < 40) {
|
|
137
|
+
result = "0" + result;
|
|
138
|
+
}
|
|
139
|
+
return getChecksumAddress("0x" + result);
|
|
140
|
+
}
|
|
141
|
+
errors.assertArgument(false, "invalid address", "address", address);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
exports.getAddress = getAddress;
|