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.
- package/README.md +103 -102
- package/build.sh +2 -2
- package/dist/ccxt.browser.js +11853 -3790
- 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/ascendex.js +10 -12
- 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/bingx.js +38 -0
- package/dist/cjs/src/bitfinex2.js +20 -3
- package/dist/cjs/src/bitget.js +9 -2
- package/dist/cjs/src/bitmart.js +41 -23
- package/dist/cjs/src/blofin.js +59 -1
- package/dist/cjs/src/coinbase.js +108 -103
- package/dist/cjs/src/coinex.js +61 -1
- package/dist/cjs/src/hitbtc.js +1 -1
- package/dist/cjs/src/htx.js +4 -1
- package/dist/cjs/src/hyperliquid.js +2035 -0
- package/dist/cjs/src/kraken.js +50 -41
- package/dist/cjs/src/krakenfutures.js +28 -0
- package/dist/cjs/src/kucoinfutures.js +3 -2
- package/dist/cjs/src/okx.js +1 -1
- package/dist/cjs/src/phemex.js +2 -2
- package/dist/cjs/src/pro/binance.js +16 -3
- 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 +314 -4
- package/dist/cjs/src/woo.js +157 -77
- package/js/ccxt.d.ts +5 -2
- package/js/ccxt.js +4 -2
- package/js/src/abstract/blofin.d.ts +1 -0
- 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/abstract/wazirx.d.ts +5 -0
- package/js/src/ascendex.d.ts +2 -2
- package/js/src/ascendex.js +10 -12
- 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/bingx.d.ts +3 -1
- package/js/src/bingx.js +38 -0
- package/js/src/bitfinex2.js +20 -3
- package/js/src/bitget.js +9 -2
- package/js/src/bitmart.d.ts +9 -2
- package/js/src/bitmart.js +41 -23
- package/js/src/blofin.d.ts +2 -1
- package/js/src/blofin.js +59 -1
- 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/hitbtc.js +1 -1
- package/js/src/htx.js +4 -1
- package/js/src/hyperliquid.d.ts +83 -0
- package/js/src/hyperliquid.js +2036 -0
- package/js/src/kraken.js +50 -41
- package/js/src/krakenfutures.d.ts +2 -1
- package/js/src/krakenfutures.js +28 -0
- package/js/src/kucoinfutures.js +3 -2
- package/js/src/okx.js +1 -1
- package/js/src/phemex.js +2 -2
- package/js/src/pro/binance.js +16 -3
- package/js/src/pro/bingx.js +1 -0
- package/js/src/pro/deribit.d.ts +1 -1
- 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 +314 -4
- package/js/src/woo.d.ts +8 -0
- package/js/src/woo.js +157 -77
- package/package.json +1 -1
- package/skip-tests.json +60 -16
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
// TODO: unify address functions in other language? or remove it?
|
|
8
|
+
import { keccak_256 as keccak256 } from '../../noble-hashes/sha3.js';
|
|
9
|
+
import { assertArgument } from "../utils/index.js";
|
|
10
|
+
const BN_0 = BigInt(0);
|
|
11
|
+
const BN_36 = BigInt(36);
|
|
12
|
+
function getChecksumAddress(address) {
|
|
13
|
+
// if (!isHexString(address, 20)) {
|
|
14
|
+
// logger.throwArgumentError("invalid address", "address", address);
|
|
15
|
+
// }
|
|
16
|
+
address = address.toLowerCase();
|
|
17
|
+
const chars = address.substring(2).split("");
|
|
18
|
+
const expanded = new Uint8Array(40);
|
|
19
|
+
for (let i = 0; i < 40; i++) {
|
|
20
|
+
expanded[i] = chars[i].charCodeAt(0);
|
|
21
|
+
}
|
|
22
|
+
const hashed = keccak256(expanded);
|
|
23
|
+
for (let i = 0; i < 40; i += 2) {
|
|
24
|
+
if ((hashed[i >> 1] >> 4) >= 8) {
|
|
25
|
+
chars[i] = chars[i].toUpperCase();
|
|
26
|
+
}
|
|
27
|
+
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
|
28
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return "0x" + chars.join("");
|
|
32
|
+
}
|
|
33
|
+
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
|
34
|
+
// Create lookup table
|
|
35
|
+
const ibanLookup = {};
|
|
36
|
+
for (let i = 0; i < 10; i++) {
|
|
37
|
+
ibanLookup[String(i)] = String(i);
|
|
38
|
+
}
|
|
39
|
+
for (let i = 0; i < 26; i++) {
|
|
40
|
+
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
|
41
|
+
}
|
|
42
|
+
// How many decimal digits can we process? (for 64-bit float, this is 15)
|
|
43
|
+
// i.e. Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
|
|
44
|
+
const safeDigits = 15;
|
|
45
|
+
function ibanChecksum(address) {
|
|
46
|
+
address = address.toUpperCase();
|
|
47
|
+
address = address.substring(4) + address.substring(0, 2) + "00";
|
|
48
|
+
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
|
|
49
|
+
// Javascript can handle integers safely up to 15 (decimal) digits
|
|
50
|
+
while (expanded.length >= safeDigits) {
|
|
51
|
+
let block = expanded.substring(0, safeDigits);
|
|
52
|
+
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
|
53
|
+
}
|
|
54
|
+
let checksum = String(98 - (parseInt(expanded, 10) % 97));
|
|
55
|
+
while (checksum.length < 2) {
|
|
56
|
+
checksum = "0" + checksum;
|
|
57
|
+
}
|
|
58
|
+
return checksum;
|
|
59
|
+
}
|
|
60
|
+
;
|
|
61
|
+
const Base36 = (function () {
|
|
62
|
+
;
|
|
63
|
+
const result = {};
|
|
64
|
+
for (let i = 0; i < 36; i++) {
|
|
65
|
+
const key = "0123456789abcdefghijklmnopqrstuvwxyz"[i];
|
|
66
|
+
result[key] = BigInt(i);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
})();
|
|
70
|
+
function fromBase36(value) {
|
|
71
|
+
value = value.toLowerCase();
|
|
72
|
+
let result = BN_0;
|
|
73
|
+
for (let i = 0; i < value.length; i++) {
|
|
74
|
+
result = result * BN_36 + Base36[value[i]];
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns a normalized and checksumed address for %%address%%.
|
|
80
|
+
* This accepts non-checksum addresses, checksum addresses and
|
|
81
|
+
* [[getIcapAddress]] formats.
|
|
82
|
+
*
|
|
83
|
+
* The checksum in Ethereum uses the capitalization (upper-case
|
|
84
|
+
* vs lower-case) of the characters within an address to encode
|
|
85
|
+
* its checksum, which offers, on average, a checksum of 15-bits.
|
|
86
|
+
*
|
|
87
|
+
* If %%address%% contains both upper-case and lower-case, it is
|
|
88
|
+
* assumed to already be a checksum address and its checksum is
|
|
89
|
+
* validated, and if the address fails its expected checksum an
|
|
90
|
+
* error is thrown.
|
|
91
|
+
*
|
|
92
|
+
* If you wish the checksum of %%address%% to be ignore, it should
|
|
93
|
+
* be converted to lower-case (i.e. ``.toLowercase()``) before
|
|
94
|
+
* being passed in. This should be a very rare situation though,
|
|
95
|
+
* that you wish to bypass the safegaurds in place to protect
|
|
96
|
+
* against an address that has been incorrectly copied from another
|
|
97
|
+
* source.
|
|
98
|
+
*
|
|
99
|
+
* @example:
|
|
100
|
+
* // Adds the checksum (via upper-casing specific letters)
|
|
101
|
+
* getAddress("0x8ba1f109551bd432803012645ac136ddd64dba72")
|
|
102
|
+
* //_result:
|
|
103
|
+
*
|
|
104
|
+
* // Converts ICAP address and adds checksum
|
|
105
|
+
* getAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36");
|
|
106
|
+
* //_result:
|
|
107
|
+
*
|
|
108
|
+
* // Throws an error if an address contains mixed case,
|
|
109
|
+
* // but the checksum fails
|
|
110
|
+
* getAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72")
|
|
111
|
+
* //_error:
|
|
112
|
+
*/
|
|
113
|
+
export function getAddress(address) {
|
|
114
|
+
assertArgument(typeof (address) === "string", "invalid address", "address", address);
|
|
115
|
+
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
|
116
|
+
// Missing the 0x prefix
|
|
117
|
+
if (!address.startsWith("0x")) {
|
|
118
|
+
address = "0x" + address;
|
|
119
|
+
}
|
|
120
|
+
const result = getChecksumAddress(address);
|
|
121
|
+
// It is a checksummed address with a bad checksum
|
|
122
|
+
assertArgument(!address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) || result === address, "bad address checksum", "address", address);
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
// Maybe ICAP? (we only support direct mode)
|
|
126
|
+
if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
|
127
|
+
// It is an ICAP address with a bad checksum
|
|
128
|
+
assertArgument(address.substring(2, 4) === ibanChecksum(address), "bad icap checksum", "address", address);
|
|
129
|
+
let result = fromBase36(address.substring(4)).toString(16);
|
|
130
|
+
while (result.length < 40) {
|
|
131
|
+
result = "0" + result;
|
|
132
|
+
}
|
|
133
|
+
return getChecksumAddress("0x" + result);
|
|
134
|
+
}
|
|
135
|
+
assertArgument(false, "invalid address", "address", address);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The [ICAP Address format](link-icap) format is an early checksum
|
|
139
|
+
* format which attempts to be compatible with the banking
|
|
140
|
+
* industry [IBAN format](link-wiki-iban) for bank accounts.
|
|
141
|
+
*
|
|
142
|
+
* It is no longer common or a recommended format.
|
|
143
|
+
*
|
|
144
|
+
* @example:
|
|
145
|
+
* getIcapAddress("0x8ba1f109551bd432803012645ac136ddd64dba72");
|
|
146
|
+
* //_result:
|
|
147
|
+
*
|
|
148
|
+
* getIcapAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36");
|
|
149
|
+
* //_result:
|
|
150
|
+
*
|
|
151
|
+
* // Throws an error if the ICAP checksum is wrong
|
|
152
|
+
* getIcapAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK37");
|
|
153
|
+
* //_error:
|
|
154
|
+
*/
|
|
155
|
+
export function getIcapAddress(address) {
|
|
156
|
+
//let base36 = _base16To36(getAddress(address).substring(2)).toUpperCase();
|
|
157
|
+
let base36 = BigInt(getAddress(address)).toString(36).toUpperCase();
|
|
158
|
+
while (base36.length < 30) {
|
|
159
|
+
base36 = "0" + base36;
|
|
160
|
+
}
|
|
161
|
+
return "XE" + ibanChecksum("XE00" + base36) + base36;
|
|
162
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Addressable, AddressLike, NameResolver } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if %%value%% is an object which implements the
|
|
4
|
+
* [[Addressable]] interface.
|
|
5
|
+
*
|
|
6
|
+
* @example:
|
|
7
|
+
* // Wallets and AbstractSigner sub-classes
|
|
8
|
+
* isAddressable(Wallet.createRandom())
|
|
9
|
+
* //_result:
|
|
10
|
+
*
|
|
11
|
+
* // Contracts
|
|
12
|
+
* contract = new Contract("dai.tokens.ethers.eth", [ ], provider)
|
|
13
|
+
* isAddressable(contract)
|
|
14
|
+
* //_result:
|
|
15
|
+
*/
|
|
16
|
+
export declare function isAddressable(value: any): value is Addressable;
|
|
17
|
+
/**
|
|
18
|
+
* Returns true if %%value%% is a valid address.
|
|
19
|
+
*
|
|
20
|
+
* @example:
|
|
21
|
+
* // Valid address
|
|
22
|
+
* isAddress("0x8ba1f109551bD432803012645Ac136ddd64DBA72")
|
|
23
|
+
* //_result:
|
|
24
|
+
*
|
|
25
|
+
* // Valid ICAP address
|
|
26
|
+
* isAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36")
|
|
27
|
+
* //_result:
|
|
28
|
+
*
|
|
29
|
+
* // Invalid checksum
|
|
30
|
+
* isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBa72")
|
|
31
|
+
* //_result:
|
|
32
|
+
*
|
|
33
|
+
* // Invalid ICAP checksum
|
|
34
|
+
* isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72")
|
|
35
|
+
* //_result:
|
|
36
|
+
*
|
|
37
|
+
* // Not an address (an ENS name requires a provided and an
|
|
38
|
+
* // asynchronous API to access)
|
|
39
|
+
* isAddress("ricmoo.eth")
|
|
40
|
+
* //_result:
|
|
41
|
+
*/
|
|
42
|
+
export declare function isAddress(value: any): value is string;
|
|
43
|
+
/**
|
|
44
|
+
* Resolves to an address for the %%target%%, which may be any
|
|
45
|
+
* supported address type, an [[Addressable]] or a Promise which
|
|
46
|
+
* resolves to an address.
|
|
47
|
+
*
|
|
48
|
+
* If an ENS name is provided, but that name has not been correctly
|
|
49
|
+
* configured a [[UnconfiguredNameError]] is thrown.
|
|
50
|
+
*
|
|
51
|
+
* @example:
|
|
52
|
+
* addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
|
|
53
|
+
*
|
|
54
|
+
* // Addresses are return synchronously
|
|
55
|
+
* resolveAddress(addr, provider)
|
|
56
|
+
* //_result:
|
|
57
|
+
*
|
|
58
|
+
* // Address promises are resolved asynchronously
|
|
59
|
+
* resolveAddress(Promise.resolve(addr))
|
|
60
|
+
* //_result:
|
|
61
|
+
*
|
|
62
|
+
* // ENS names are resolved asynchronously
|
|
63
|
+
* resolveAddress("dai.tokens.ethers.eth", provider)
|
|
64
|
+
* //_result:
|
|
65
|
+
*
|
|
66
|
+
* // Addressable objects are resolved asynchronously
|
|
67
|
+
* contract = new Contract(addr, [ ])
|
|
68
|
+
* resolveAddress(contract, provider)
|
|
69
|
+
* //_result:
|
|
70
|
+
*
|
|
71
|
+
* // Unconfigured ENS names reject
|
|
72
|
+
* resolveAddress("nothing-here.ricmoo.eth", provider)
|
|
73
|
+
* //_error:
|
|
74
|
+
*
|
|
75
|
+
* // ENS names require a NameResolver object passed in
|
|
76
|
+
* // (notice the provider was omitted)
|
|
77
|
+
* resolveAddress("nothing-here.ricmoo.eth")
|
|
78
|
+
* //_error:
|
|
79
|
+
*/
|
|
80
|
+
export declare function resolveAddress(target: AddressLike, resolver?: null | NameResolver): string | Promise<string>;
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
import { assert, assertArgument } from "../utils/index.js";
|
|
8
|
+
import { getAddress } from "./address.js";
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if %%value%% is an object which implements the
|
|
11
|
+
* [[Addressable]] interface.
|
|
12
|
+
*
|
|
13
|
+
* @example:
|
|
14
|
+
* // Wallets and AbstractSigner sub-classes
|
|
15
|
+
* isAddressable(Wallet.createRandom())
|
|
16
|
+
* //_result:
|
|
17
|
+
*
|
|
18
|
+
* // Contracts
|
|
19
|
+
* contract = new Contract("dai.tokens.ethers.eth", [ ], provider)
|
|
20
|
+
* isAddressable(contract)
|
|
21
|
+
* //_result:
|
|
22
|
+
*/
|
|
23
|
+
export function isAddressable(value) {
|
|
24
|
+
return (value && typeof (value.getAddress) === "function");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if %%value%% is a valid address.
|
|
28
|
+
*
|
|
29
|
+
* @example:
|
|
30
|
+
* // Valid address
|
|
31
|
+
* isAddress("0x8ba1f109551bD432803012645Ac136ddd64DBA72")
|
|
32
|
+
* //_result:
|
|
33
|
+
*
|
|
34
|
+
* // Valid ICAP address
|
|
35
|
+
* isAddress("XE65GB6LDNXYOFTX0NSV3FUWKOWIXAMJK36")
|
|
36
|
+
* //_result:
|
|
37
|
+
*
|
|
38
|
+
* // Invalid checksum
|
|
39
|
+
* isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBa72")
|
|
40
|
+
* //_result:
|
|
41
|
+
*
|
|
42
|
+
* // Invalid ICAP checksum
|
|
43
|
+
* isAddress("0x8Ba1f109551bD432803012645Ac136ddd64DBA72")
|
|
44
|
+
* //_result:
|
|
45
|
+
*
|
|
46
|
+
* // Not an address (an ENS name requires a provided and an
|
|
47
|
+
* // asynchronous API to access)
|
|
48
|
+
* isAddress("ricmoo.eth")
|
|
49
|
+
* //_result:
|
|
50
|
+
*/
|
|
51
|
+
export function isAddress(value) {
|
|
52
|
+
try {
|
|
53
|
+
getAddress(value);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
catch (error) { }
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
async function checkAddress(target, promise) {
|
|
60
|
+
const result = await promise;
|
|
61
|
+
if (result == null || result === "0x0000000000000000000000000000000000000000") {
|
|
62
|
+
assert(typeof (target) !== "string", "unconfigured name", "UNCONFIGURED_NAME", { value: target });
|
|
63
|
+
assertArgument(false, "invalid AddressLike value; did not resolve to a value address", "target", target);
|
|
64
|
+
}
|
|
65
|
+
return getAddress(result);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resolves to an address for the %%target%%, which may be any
|
|
69
|
+
* supported address type, an [[Addressable]] or a Promise which
|
|
70
|
+
* resolves to an address.
|
|
71
|
+
*
|
|
72
|
+
* If an ENS name is provided, but that name has not been correctly
|
|
73
|
+
* configured a [[UnconfiguredNameError]] is thrown.
|
|
74
|
+
*
|
|
75
|
+
* @example:
|
|
76
|
+
* addr = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
|
|
77
|
+
*
|
|
78
|
+
* // Addresses are return synchronously
|
|
79
|
+
* resolveAddress(addr, provider)
|
|
80
|
+
* //_result:
|
|
81
|
+
*
|
|
82
|
+
* // Address promises are resolved asynchronously
|
|
83
|
+
* resolveAddress(Promise.resolve(addr))
|
|
84
|
+
* //_result:
|
|
85
|
+
*
|
|
86
|
+
* // ENS names are resolved asynchronously
|
|
87
|
+
* resolveAddress("dai.tokens.ethers.eth", provider)
|
|
88
|
+
* //_result:
|
|
89
|
+
*
|
|
90
|
+
* // Addressable objects are resolved asynchronously
|
|
91
|
+
* contract = new Contract(addr, [ ])
|
|
92
|
+
* resolveAddress(contract, provider)
|
|
93
|
+
* //_result:
|
|
94
|
+
*
|
|
95
|
+
* // Unconfigured ENS names reject
|
|
96
|
+
* resolveAddress("nothing-here.ricmoo.eth", provider)
|
|
97
|
+
* //_error:
|
|
98
|
+
*
|
|
99
|
+
* // ENS names require a NameResolver object passed in
|
|
100
|
+
* // (notice the provider was omitted)
|
|
101
|
+
* resolveAddress("nothing-here.ricmoo.eth")
|
|
102
|
+
* //_error:
|
|
103
|
+
*/
|
|
104
|
+
export function resolveAddress(target, resolver) {
|
|
105
|
+
if (typeof (target) === "string") {
|
|
106
|
+
if (target.match(/^0x[0-9a-f]{40}$/i)) {
|
|
107
|
+
return getAddress(target);
|
|
108
|
+
}
|
|
109
|
+
assert(resolver != null, "ENS resolution requires a provider", "UNSUPPORTED_OPERATION", { operation: "resolveName" });
|
|
110
|
+
return checkAddress(target, resolver.resolveName(target));
|
|
111
|
+
}
|
|
112
|
+
else if (isAddressable(target)) {
|
|
113
|
+
return checkAddress(target, target.getAddress());
|
|
114
|
+
}
|
|
115
|
+
else if (target && typeof (target.then) === "function") {
|
|
116
|
+
return checkAddress(target, target);
|
|
117
|
+
}
|
|
118
|
+
assertArgument(false, "unsupported addressable value", "target", target);
|
|
119
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { BigNumberish, BytesLike } from "../utils/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the address that would result from a ``CREATE`` for %%tx%%.
|
|
4
|
+
*
|
|
5
|
+
* This can be used to compute the address a contract will be
|
|
6
|
+
* deployed to by an EOA when sending a deployment transaction (i.e.
|
|
7
|
+
* when the ``to`` address is ``null``).
|
|
8
|
+
*
|
|
9
|
+
* This can also be used to compute the address a contract will be
|
|
10
|
+
* deployed to by a contract, by using the contract's address as the
|
|
11
|
+
* ``to`` and the contract's nonce.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72";
|
|
15
|
+
* nonce = 5;
|
|
16
|
+
*
|
|
17
|
+
* getCreateAddress({ from, nonce });
|
|
18
|
+
* //_result:
|
|
19
|
+
*/
|
|
20
|
+
export declare function getCreateAddress(tx: {
|
|
21
|
+
from: string;
|
|
22
|
+
nonce: BigNumberish;
|
|
23
|
+
}): string;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the address that would result from a ``CREATE2`` operation
|
|
26
|
+
* with the given %%from%%, %%salt%% and %%initCodeHash%%.
|
|
27
|
+
*
|
|
28
|
+
* To compute the %%initCodeHash%% from a contract's init code, use
|
|
29
|
+
* the [[keccak256]] function.
|
|
30
|
+
*
|
|
31
|
+
* For a quick overview and example of ``CREATE2``, see [[link-ricmoo-wisps]].
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // The address of the contract
|
|
35
|
+
* from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72"
|
|
36
|
+
*
|
|
37
|
+
* // The salt
|
|
38
|
+
* salt = id("HelloWorld")
|
|
39
|
+
*
|
|
40
|
+
* // The hash of the initCode
|
|
41
|
+
* initCode = "0x6394198df16000526103ff60206004601c335afa6040516060f3";
|
|
42
|
+
* initCodeHash = keccak256(initCode)
|
|
43
|
+
*
|
|
44
|
+
* getCreate2Address(from, salt, initCodeHash)
|
|
45
|
+
* //_result:
|
|
46
|
+
*/
|
|
47
|
+
export declare function getCreate2Address(_from: string, _salt: BytesLike, _initCodeHash: BytesLike): string;
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
import { concat, dataSlice, getBigInt, getBytes, encodeRlp, assertArgument, keccak256 } from "../utils/index.js";
|
|
8
|
+
import { getAddress } from "./address.js";
|
|
9
|
+
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
|
10
|
+
/**
|
|
11
|
+
* Returns the address that would result from a ``CREATE`` for %%tx%%.
|
|
12
|
+
*
|
|
13
|
+
* This can be used to compute the address a contract will be
|
|
14
|
+
* deployed to by an EOA when sending a deployment transaction (i.e.
|
|
15
|
+
* when the ``to`` address is ``null``).
|
|
16
|
+
*
|
|
17
|
+
* This can also be used to compute the address a contract will be
|
|
18
|
+
* deployed to by a contract, by using the contract's address as the
|
|
19
|
+
* ``to`` and the contract's nonce.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72";
|
|
23
|
+
* nonce = 5;
|
|
24
|
+
*
|
|
25
|
+
* getCreateAddress({ from, nonce });
|
|
26
|
+
* //_result:
|
|
27
|
+
*/
|
|
28
|
+
export function getCreateAddress(tx) {
|
|
29
|
+
const from = getAddress(tx.from);
|
|
30
|
+
const nonce = getBigInt(tx.nonce, "tx.nonce");
|
|
31
|
+
let nonceHex = nonce.toString(16);
|
|
32
|
+
if (nonceHex === "0") {
|
|
33
|
+
nonceHex = "0x";
|
|
34
|
+
}
|
|
35
|
+
else if (nonceHex.length % 2) {
|
|
36
|
+
nonceHex = "0x0" + nonceHex;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
nonceHex = "0x" + nonceHex;
|
|
40
|
+
}
|
|
41
|
+
return getAddress(dataSlice(keccak256(encodeRlp([from, nonceHex])), 12));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the address that would result from a ``CREATE2`` operation
|
|
45
|
+
* with the given %%from%%, %%salt%% and %%initCodeHash%%.
|
|
46
|
+
*
|
|
47
|
+
* To compute the %%initCodeHash%% from a contract's init code, use
|
|
48
|
+
* the [[keccak256]] function.
|
|
49
|
+
*
|
|
50
|
+
* For a quick overview and example of ``CREATE2``, see [[link-ricmoo-wisps]].
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // The address of the contract
|
|
54
|
+
* from = "0x8ba1f109551bD432803012645Ac136ddd64DBA72"
|
|
55
|
+
*
|
|
56
|
+
* // The salt
|
|
57
|
+
* salt = id("HelloWorld")
|
|
58
|
+
*
|
|
59
|
+
* // The hash of the initCode
|
|
60
|
+
* initCode = "0x6394198df16000526103ff60206004601c335afa6040516060f3";
|
|
61
|
+
* initCodeHash = keccak256(initCode)
|
|
62
|
+
*
|
|
63
|
+
* getCreate2Address(from, salt, initCodeHash)
|
|
64
|
+
* //_result:
|
|
65
|
+
*/
|
|
66
|
+
export function getCreate2Address(_from, _salt, _initCodeHash) {
|
|
67
|
+
const from = getAddress(_from);
|
|
68
|
+
const salt = getBytes(_salt, "salt");
|
|
69
|
+
const initCodeHash = getBytes(_initCodeHash, "initCodeHash");
|
|
70
|
+
assertArgument(salt.length === 32, "salt must be 32 bytes", "salt", _salt);
|
|
71
|
+
assertArgument(initCodeHash.length === 32, "initCodeHash must be 32 bytes", "initCodeHash", _initCodeHash);
|
|
72
|
+
return getAddress(dataSlice(keccak256(concat(["0xff", from, salt, initCodeHash])), 12));
|
|
73
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Addresses are a fundamental part of interacting with Ethereum. They
|
|
3
|
+
* represent the gloabal identity of Externally Owned Accounts (accounts
|
|
4
|
+
* backed by a private key) and contracts.
|
|
5
|
+
*
|
|
6
|
+
* The Ethereum Naming Service (ENS) provides an interconnected ecosystem
|
|
7
|
+
* of contracts, standards and libraries which enable looking up an
|
|
8
|
+
* address for an ENS name.
|
|
9
|
+
*
|
|
10
|
+
* These functions help convert between various formats, validate
|
|
11
|
+
* addresses and safely resolve ENS names.
|
|
12
|
+
*
|
|
13
|
+
* @_section: api/address:Addresses [about-addresses]
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* An interface for objects which have an address, and can
|
|
17
|
+
* resolve it asyncronously.
|
|
18
|
+
*
|
|
19
|
+
* This allows objects such as [[Signer]] or [[Contract]] to
|
|
20
|
+
* be used most places an address can be, for example getting
|
|
21
|
+
* the [balance](Provider-getBalance).
|
|
22
|
+
*/
|
|
23
|
+
export interface Addressable {
|
|
24
|
+
/**
|
|
25
|
+
* Get the object address.
|
|
26
|
+
*/
|
|
27
|
+
getAddress(): Promise<string>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Anything that can be used to return or resolve an address.
|
|
31
|
+
*/
|
|
32
|
+
export declare type AddressLike = string | Promise<string> | Addressable;
|
|
33
|
+
/**
|
|
34
|
+
* An interface for any object which can resolve an ENS name.
|
|
35
|
+
*/
|
|
36
|
+
export interface NameResolver {
|
|
37
|
+
/**
|
|
38
|
+
* Resolve to the address for the ENS %%name%%.
|
|
39
|
+
*
|
|
40
|
+
* Resolves to ``null`` if the name is unconfigued. Use
|
|
41
|
+
* [[resolveAddress]] (passing this object as %%resolver%%) to
|
|
42
|
+
* throw for names that are unconfigured.
|
|
43
|
+
*/
|
|
44
|
+
resolveName(name: string): Promise<null | string>;
|
|
45
|
+
}
|
|
46
|
+
export { getAddress, getIcapAddress } from "./address.js";
|
|
47
|
+
export { getCreateAddress, getCreate2Address } from "./contract-address.js";
|
|
48
|
+
export { isAddressable, isAddress, resolveAddress } from "./checks.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* Addresses are a fundamental part of interacting with Ethereum. They
|
|
9
|
+
* represent the gloabal identity of Externally Owned Accounts (accounts
|
|
10
|
+
* backed by a private key) and contracts.
|
|
11
|
+
*
|
|
12
|
+
* The Ethereum Naming Service (ENS) provides an interconnected ecosystem
|
|
13
|
+
* of contracts, standards and libraries which enable looking up an
|
|
14
|
+
* address for an ENS name.
|
|
15
|
+
*
|
|
16
|
+
* These functions help convert between various formats, validate
|
|
17
|
+
* addresses and safely resolve ENS names.
|
|
18
|
+
*
|
|
19
|
+
* @_section: api/address:Addresses [about-addresses]
|
|
20
|
+
*/
|
|
21
|
+
null;
|
|
22
|
+
export { getAddress, getIcapAddress } from "./address.js";
|
|
23
|
+
export { getCreateAddress, getCreate2Address } from "./contract-address.js";
|
|
24
|
+
export { isAddressable, isAddress, resolveAddress } from "./checks.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* About bytes32 strings...
|
|
3
|
+
*
|
|
4
|
+
* @_docloc: api/utils:Bytes32 Strings
|
|
5
|
+
*/
|
|
6
|
+
import type { BytesLike } from "./utils/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Encodes %%text%% as a Bytes32 string.
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodeBytes32String(text: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Encodes the Bytes32-encoded %%bytes%% into a string.
|
|
13
|
+
*/
|
|
14
|
+
export declare function decodeBytes32String(_bytes: BytesLike): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
* About bytes32 strings...
|
|
9
|
+
*
|
|
10
|
+
* @_docloc: api/utils:Bytes32 Strings
|
|
11
|
+
*/
|
|
12
|
+
import { getBytes, toUtf8Bytes, toUtf8String, zeroPadBytes } from "./utils/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Encodes %%text%% as a Bytes32 string.
|
|
15
|
+
*/
|
|
16
|
+
export function encodeBytes32String(text) {
|
|
17
|
+
// Get the bytes
|
|
18
|
+
const bytes = toUtf8Bytes(text);
|
|
19
|
+
// Check we have room for null-termination
|
|
20
|
+
if (bytes.length > 31) {
|
|
21
|
+
throw new Error("bytes32 string must be less than 32 bytes");
|
|
22
|
+
}
|
|
23
|
+
// Zero-pad (implicitly null-terminates)
|
|
24
|
+
return zeroPadBytes(bytes, 32);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Encodes the Bytes32-encoded %%bytes%% into a string.
|
|
28
|
+
*/
|
|
29
|
+
export function decodeBytes32String(_bytes) {
|
|
30
|
+
const data = getBytes(_bytes, "bytes");
|
|
31
|
+
// Must be 32 bytes with a null-termination
|
|
32
|
+
if (data.length !== 32) {
|
|
33
|
+
throw new Error("invalid bytes32 - not 32 bytes long");
|
|
34
|
+
}
|
|
35
|
+
if (data[31] !== 0) {
|
|
36
|
+
throw new Error("invalid bytes32 string - no null terminator");
|
|
37
|
+
}
|
|
38
|
+
// Find the null termination
|
|
39
|
+
let length = 31;
|
|
40
|
+
while (data[length - 1] === 0) {
|
|
41
|
+
length--;
|
|
42
|
+
}
|
|
43
|
+
// Determine the string value
|
|
44
|
+
return toUtf8String(data.slice(0, length));
|
|
45
|
+
}
|