essential-eth 0.9.1-next.0 → 0.9.1-next.1
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/dist/cjs/classes/Contract.js +66 -311
- package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
- package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
- package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
- package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
- package/dist/cjs/classes/utils/clean-block.js +30 -52
- package/dist/cjs/classes/utils/clean-log.js +20 -42
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
- package/dist/cjs/classes/utils/clean-transaction.js +30 -52
- package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
- package/dist/cjs/classes/utils/fetchers.js +44 -166
- package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
- package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
- package/dist/cjs/index.js +56 -25
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +29 -123
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +4 -1
- package/dist/cjs/providers/AlchemyProvider.js +9 -82
- package/dist/cjs/providers/BaseProvider.js +520 -958
- package/dist/cjs/providers/FallthroughProvider.js +47 -156
- package/dist/cjs/providers/JsonRpcProvider.js +28 -114
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
- package/dist/cjs/providers/test/mock-of.js +6 -3
- package/dist/cjs/providers/test/rpc-urls.js +23 -15
- package/dist/cjs/providers/utils/chains-info.js +3 -1
- package/dist/cjs/shared/tiny-big/helpers.js +42 -93
- package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +2 -1
- package/dist/cjs/types/Contract.types.js +2 -1
- package/dist/cjs/types/FeeData.types.js +2 -1
- package/dist/cjs/types/Filter.types.js +2 -1
- package/dist/cjs/types/Network.types.js +2 -3
- package/dist/cjs/types/Transaction.types.js +2 -1
- package/dist/cjs/utils/bytes.js +318 -286
- package/dist/cjs/utils/compute-address.js +15 -8
- package/dist/cjs/utils/compute-public-key.js +10 -5
- package/dist/cjs/utils/ether-to-gwei.js +11 -10
- package/dist/cjs/utils/ether-to-wei.js +11 -10
- package/dist/cjs/utils/gwei-to-ether.js +11 -10
- package/dist/cjs/utils/hash-message.js +16 -11
- package/dist/cjs/utils/is-address.js +12 -8
- package/dist/cjs/utils/keccak256.js +14 -8
- package/dist/cjs/utils/solidity-keccak256.js +60 -49
- package/dist/cjs/utils/split-signature.js +73 -55
- package/dist/cjs/utils/to-checksum-address.js +20 -15
- package/dist/cjs/utils/to-utf8-bytes.js +6 -1
- package/dist/cjs/utils/wei-to-ether.js +15 -13
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
- package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
- package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
- package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
- package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
- package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
- package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
- package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
- package/dist/cjs/utils/tests/compute-address.test.js +0 -49
- package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
- package/dist/cjs/utils/tests/hash-message.test.js +0 -32
- package/dist/cjs/utils/tests/is-address.test.js +0 -48
- package/dist/cjs/utils/tests/keccak256.test.js +0 -121
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
- package/dist/cjs/utils/tests/split-signature.test.js +0 -46
- package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
- package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.rpcUrls = exports.fakeUrls = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
exports.fakeUrls = {
|
|
9
|
+
notRPCButRealHttp: 'https://httpstat.us/200',
|
|
10
|
+
};
|
|
11
|
+
const RPC_ORIGIN = 'https://free-eth-node.com';
|
|
12
|
+
zod_1.default.string({
|
|
13
|
+
required_error: '"RPC_ORIGIN" required but not found',
|
|
14
|
+
})
|
|
15
|
+
.url('Expected url for "RPC_ORIGIN"')
|
|
16
|
+
.parse(RPC_ORIGIN);
|
|
17
|
+
exports.rpcUrls = {
|
|
18
|
+
mainnet: `${RPC_ORIGIN}/api/eth`,
|
|
19
|
+
oeth: `${RPC_ORIGIN}/api/oeth`,
|
|
20
|
+
matic: `${RPC_ORIGIN}/api/MATIC`,
|
|
21
|
+
gno: `${RPC_ORIGIN}/api/gno`,
|
|
22
|
+
bnb: `${RPC_ORIGIN}/api/bnb`,
|
|
23
|
+
arb1: `${RPC_ORIGIN}/api/arb1`,
|
|
24
|
+
gor: `${RPC_ORIGIN}/api/gor`,
|
|
17
25
|
};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scientificStrToDecimalStr = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Strips both leading and trailing zeroes from a number string
|
|
3
6
|
*
|
|
@@ -8,78 +11,21 @@
|
|
|
8
11
|
* stripTrailingZeros('0005280');
|
|
9
12
|
* // '5280'
|
|
10
13
|
* ```
|
|
11
|
-
*/
|
|
12
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
13
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
14
|
-
return arr2;
|
|
15
|
-
}
|
|
16
|
-
function _array_with_holes(arr) {
|
|
17
|
-
if (Array.isArray(arr)) return arr;
|
|
18
|
-
}
|
|
19
|
-
function _array_without_holes(arr) {
|
|
20
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
21
|
-
}
|
|
22
|
-
function _iterable_to_array(iter) {
|
|
23
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
24
|
-
}
|
|
25
|
-
function _iterable_to_array_limit(arr, i) {
|
|
26
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
27
|
-
if (_i == null) return;
|
|
28
|
-
var _arr = [];
|
|
29
|
-
var _n = true;
|
|
30
|
-
var _d = false;
|
|
31
|
-
var _s, _e;
|
|
32
|
-
try {
|
|
33
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
34
|
-
_arr.push(_s.value);
|
|
35
|
-
if (i && _arr.length === i) break;
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
_d = true;
|
|
39
|
-
_e = err;
|
|
40
|
-
} finally{
|
|
41
|
-
try {
|
|
42
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
43
|
-
} finally{
|
|
44
|
-
if (_d) throw _e;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return _arr;
|
|
48
|
-
}
|
|
49
|
-
function _non_iterable_rest() {
|
|
50
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
51
|
-
}
|
|
52
|
-
function _non_iterable_spread() {
|
|
53
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
54
|
-
}
|
|
55
|
-
function _sliced_to_array(arr, i) {
|
|
56
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
57
|
-
}
|
|
58
|
-
function _to_consumable_array(arr) {
|
|
59
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
60
|
-
}
|
|
61
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
62
|
-
if (!o) return;
|
|
63
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
64
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
65
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
66
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
67
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
68
|
-
}
|
|
14
|
+
*/
|
|
69
15
|
function stripTrailingZeroes(numberString) {
|
|
70
|
-
|
|
71
|
-
numberString = numberString.replace(
|
|
72
|
-
numberString = numberString.replace(/\.0*$/g,
|
|
73
|
-
numberString = numberString.replace(/^0+/,
|
|
16
|
+
const isNegative = numberString.startsWith('-');
|
|
17
|
+
numberString = numberString.replace('-', '');
|
|
18
|
+
numberString = numberString.replace(/\.0*$/g, '' /* for numbers like "1.0" -> "1" */);
|
|
19
|
+
numberString = numberString.replace(/^0+/, '');
|
|
74
20
|
// for numbers like "1.10" -> "1.1"
|
|
75
|
-
if (numberString.includes(
|
|
76
|
-
numberString = numberString.replace(/0+$/,
|
|
21
|
+
if (numberString.includes('.')) {
|
|
22
|
+
numberString = numberString.replace(/0+$/, '');
|
|
77
23
|
}
|
|
78
|
-
if (numberString.startsWith(
|
|
24
|
+
if (numberString.startsWith('.')) {
|
|
79
25
|
// so that ".1" returns as "0.1"
|
|
80
|
-
numberString =
|
|
26
|
+
numberString = `0${numberString}`;
|
|
81
27
|
}
|
|
82
|
-
return
|
|
28
|
+
return `${isNegative ? '-' : ''}${numberString}`;
|
|
83
29
|
}
|
|
84
30
|
/**
|
|
85
31
|
* Converts a string in scientific notation formatting to string in decimal format
|
|
@@ -96,53 +42,56 @@ function stripTrailingZeroes(numberString) {
|
|
|
96
42
|
* scientificStrToDecimalStr('2.3e+5');
|
|
97
43
|
* // '230000'
|
|
98
44
|
* ```
|
|
99
|
-
*/
|
|
45
|
+
*/
|
|
46
|
+
function scientificStrToDecimalStr(scientificString) {
|
|
100
47
|
// Does not contain "e" nor "E"
|
|
101
|
-
if (!scientificString.match(/e/i /* lowercase and uppercase E */
|
|
48
|
+
if (!scientificString.match(/e/i /* lowercase and uppercase E */)) {
|
|
102
49
|
return stripTrailingZeroes(scientificString);
|
|
103
50
|
}
|
|
104
51
|
// eslint-disable-next-line prefer-const
|
|
105
|
-
|
|
52
|
+
let [base, power] = scientificString.split(/e/i /* lowercase and uppercase E */);
|
|
106
53
|
// remove the leading "-" if negative
|
|
107
|
-
|
|
108
|
-
base = base.replace(
|
|
54
|
+
const isNegative = Number(base) < 0;
|
|
55
|
+
base = base.replace('-', '');
|
|
109
56
|
base = stripTrailingZeroes(base);
|
|
110
|
-
|
|
57
|
+
const [wholeNumber, fraction /* move decimal this many places */ = ''] = base.split('.');
|
|
111
58
|
if (Number(power) === 0) {
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
59
|
+
return `${isNegative ? '-' : ''}${stripTrailingZeroes(base)}`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const includesDecimal = base.includes('.');
|
|
115
63
|
if (!includesDecimal) {
|
|
116
|
-
base =
|
|
64
|
+
base = `${base}.`;
|
|
117
65
|
}
|
|
118
|
-
base = base.replace(
|
|
119
|
-
|
|
120
|
-
|
|
66
|
+
base = base.replace('.', '');
|
|
67
|
+
const baseLength = base.length;
|
|
68
|
+
let splitPaddedNumber;
|
|
121
69
|
if (Number(power) < 0) {
|
|
122
70
|
// move decimal left
|
|
123
71
|
if (wholeNumber.length < Math.abs(Number(power))) {
|
|
124
|
-
base = base.padStart(baseLength + Math.abs(Number(power)) - wholeNumber.length,
|
|
72
|
+
base = base.padStart(baseLength + Math.abs(Number(power)) - wholeNumber.length, '0');
|
|
125
73
|
}
|
|
126
|
-
splitPaddedNumber = base.split(
|
|
74
|
+
splitPaddedNumber = base.split('');
|
|
127
75
|
if (wholeNumber.length < Math.abs(Number(power))) {
|
|
128
76
|
// starts with zeroes
|
|
129
|
-
splitPaddedNumber = [
|
|
130
|
-
"."
|
|
131
|
-
].concat(_to_consumable_array(splitPaddedNumber));
|
|
132
|
-
} else {
|
|
133
|
-
splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, ".");
|
|
77
|
+
splitPaddedNumber = ['.', ...splitPaddedNumber];
|
|
134
78
|
}
|
|
135
|
-
|
|
79
|
+
else {
|
|
80
|
+
splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
136
84
|
// move decimal right
|
|
137
85
|
if (fraction.length < Math.abs(Number(power))) {
|
|
138
|
-
base = base.padEnd(baseLength + Math.abs(Number(power)) - fraction.length,
|
|
86
|
+
base = base.padEnd(baseLength + Math.abs(Number(power)) - fraction.length, '0');
|
|
139
87
|
}
|
|
140
|
-
splitPaddedNumber = base.split(
|
|
88
|
+
splitPaddedNumber = base.split('');
|
|
141
89
|
if (fraction.length > Math.abs(Number(power))) {
|
|
142
|
-
splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0,
|
|
90
|
+
splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
|
|
143
91
|
}
|
|
144
92
|
}
|
|
145
|
-
|
|
146
|
-
return
|
|
93
|
+
const toReturn = stripTrailingZeroes(splitPaddedNumber.join(''));
|
|
94
|
+
return `${isNegative ? '-' : ''}${toReturn}`;
|
|
147
95
|
}
|
|
148
96
|
}
|
|
97
|
+
exports.scientificStrToDecimalStr = scientificStrToDecimalStr;
|
|
@@ -1,220 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function _defineProperties(target, props) {
|
|
13
|
-
for(var i = 0; i < props.length; i++){
|
|
14
|
-
var descriptor = props[i];
|
|
15
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
-
descriptor.configurable = true;
|
|
17
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function _create_class(Constructor, protoProps, staticProps) {
|
|
22
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
23
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
24
|
-
return Constructor;
|
|
25
|
-
}
|
|
26
|
-
function _define_property(obj, key, value) {
|
|
27
|
-
if (key in obj) {
|
|
28
|
-
Object.defineProperty(obj, key, {
|
|
29
|
-
value: value,
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true
|
|
33
|
-
});
|
|
34
|
-
} else {
|
|
35
|
-
obj[key] = value;
|
|
36
|
-
}
|
|
37
|
-
return obj;
|
|
38
|
-
}
|
|
39
|
-
function _get(target, property, receiver) {
|
|
40
|
-
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
41
|
-
_get = Reflect.get;
|
|
42
|
-
} else {
|
|
43
|
-
_get = function get(target, property, receiver) {
|
|
44
|
-
var base = _super_prop_base(target, property);
|
|
45
|
-
if (!base) return;
|
|
46
|
-
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
47
|
-
if (desc.get) {
|
|
48
|
-
return desc.get.call(receiver || target);
|
|
49
|
-
}
|
|
50
|
-
return desc.value;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return _get(target, property, receiver || target);
|
|
54
|
-
}
|
|
55
|
-
function _get_prototype_of(o) {
|
|
56
|
-
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
57
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
58
|
-
};
|
|
59
|
-
return _get_prototype_of(o);
|
|
60
|
-
}
|
|
61
|
-
function _inherits(subClass, superClass) {
|
|
62
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
63
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
64
|
-
}
|
|
65
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
66
|
-
constructor: {
|
|
67
|
-
value: subClass,
|
|
68
|
-
writable: true,
|
|
69
|
-
configurable: true
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
if (superClass) _set_prototype_of(subClass, superClass);
|
|
73
|
-
}
|
|
74
|
-
function _possible_constructor_return(self, call) {
|
|
75
|
-
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
76
|
-
return call;
|
|
77
|
-
}
|
|
78
|
-
return _assert_this_initialized(self);
|
|
79
|
-
}
|
|
80
|
-
function _set_prototype_of(o, p) {
|
|
81
|
-
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
82
|
-
o.__proto__ = p;
|
|
83
|
-
return o;
|
|
84
|
-
};
|
|
85
|
-
return _set_prototype_of(o, p);
|
|
86
|
-
}
|
|
87
|
-
function _super_prop_base(object, property) {
|
|
88
|
-
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
89
|
-
object = _get_prototype_of(object);
|
|
90
|
-
if (object === null) break;
|
|
91
|
-
}
|
|
92
|
-
return object;
|
|
93
|
-
}
|
|
94
|
-
function _type_of(obj) {
|
|
95
|
-
"@swc/helpers - typeof";
|
|
96
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
97
|
-
}
|
|
98
|
-
function _is_native_reflect_construct() {
|
|
99
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
100
|
-
if (Reflect.construct.sham) return false;
|
|
101
|
-
if (typeof Proxy === "function") return true;
|
|
102
|
-
try {
|
|
103
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
104
|
-
return true;
|
|
105
|
-
} catch (e) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function _create_super(Derived) {
|
|
110
|
-
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
111
|
-
return function _createSuperInternal() {
|
|
112
|
-
var Super = _get_prototype_of(Derived), result;
|
|
113
|
-
if (hasNativeReflectConstruct) {
|
|
114
|
-
var NewTarget = _get_prototype_of(this).constructor;
|
|
115
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
|
116
|
-
} else {
|
|
117
|
-
result = Super.apply(this, arguments);
|
|
118
|
-
}
|
|
119
|
-
return _possible_constructor_return(this, result);
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
import Big from "big.js";
|
|
123
|
-
import { hexToDecimal } from "../../classes/utils/hex-to-decimal";
|
|
124
|
-
import { scientificStrToDecimalStr } from "./helpers";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.tinyBig = exports.TinyBig = void 0;
|
|
7
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
8
|
+
const hex_to_decimal_1 = require("../../classes/utils/hex-to-decimal");
|
|
9
|
+
const helpers_1 = require("./helpers");
|
|
125
10
|
/**
|
|
126
11
|
* A wrapper around [big.js](https://github.com/MikeMcl/big.js) which expands scientific notation and creates a "toHexString" function.
|
|
127
12
|
* This is the return type of every operation on ether, wei, etc.
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_class_call_check(this, TinyBig);
|
|
134
|
-
var _this;
|
|
135
|
-
if (typeof value === "string" && value.startsWith("0x")) {
|
|
136
|
-
value = hexToDecimal(value);
|
|
13
|
+
*/
|
|
14
|
+
class TinyBig extends big_js_1.default {
|
|
15
|
+
constructor(value) {
|
|
16
|
+
if (typeof value === 'string' && value.startsWith('0x')) {
|
|
17
|
+
value = (0, hex_to_decimal_1.hexToDecimal)(value);
|
|
137
18
|
}
|
|
138
|
-
|
|
19
|
+
super(value);
|
|
139
20
|
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
21
|
+
* Eithers pads or shortens a string to a specified length
|
|
22
|
+
*
|
|
23
|
+
* @param str the string to pad or chop
|
|
24
|
+
* @param padChar the character to pad the string with
|
|
25
|
+
* @param length the desired length of the given string
|
|
26
|
+
* @returns a string of the desired length, either padded with the specified padChar or with the beginning of the string chopped off
|
|
27
|
+
* @example
|
|
28
|
+
* ```javascript
|
|
29
|
+
* padAndChop('essential-eth', 'a', 8);
|
|
30
|
+
* // 'tial-eth'
|
|
31
|
+
* ```
|
|
32
|
+
* @example
|
|
33
|
+
* ```javascript
|
|
34
|
+
* padAndChop('essential-eth', 'A', 20);
|
|
35
|
+
* // 'AAAAAAAessential-eth'
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
this.padAndChop = (str, padChar, length) => {
|
|
39
|
+
return (Array(length).fill(padChar).join('') + str).slice(length * -1);
|
|
40
|
+
};
|
|
160
41
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
key: "toTwos",
|
|
199
|
-
value: function toTwos(bitCount) {
|
|
200
|
-
var binaryStr;
|
|
201
|
-
if (this.gte(0)) {
|
|
202
|
-
var twosComp = this.toNumber().toString(2);
|
|
203
|
-
binaryStr = this.padAndChop(twosComp, "0", bitCount || twosComp.length);
|
|
204
|
-
} else {
|
|
205
|
-
binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
|
|
206
|
-
if (Number(binaryStr) < 0) {
|
|
207
|
-
throw new Error("Cannot calculate twos complement");
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
var binary = "0b".concat(binaryStr);
|
|
211
|
-
var decimal = Number(binary);
|
|
212
|
-
return tinyBig(decimal);
|
|
42
|
+
/**
|
|
43
|
+
* Used anytime you're passing in "value" to ethers or web3
|
|
44
|
+
* For now, TypeScript will complain that `TinyBig` is not a `BigNumberish`. You can // @ts-ignore or call this
|
|
45
|
+
*
|
|
46
|
+
* @returns the TinyBig represented as a hex string
|
|
47
|
+
* @example
|
|
48
|
+
* ```javascript
|
|
49
|
+
* tinyBig(293).toHexString();
|
|
50
|
+
* // '0x125'
|
|
51
|
+
* ```
|
|
52
|
+
* @example
|
|
53
|
+
* ```javascript
|
|
54
|
+
* tinyBig(681365874).toHexString();
|
|
55
|
+
* // '0x289cd172'
|
|
56
|
+
*/
|
|
57
|
+
toHexString() {
|
|
58
|
+
return `0x${BigInt(this.toString()).toString(16)}`;
|
|
59
|
+
}
|
|
60
|
+
toNumber() {
|
|
61
|
+
return Number((0, helpers_1.scientificStrToDecimalStr)(super.toString()));
|
|
62
|
+
}
|
|
63
|
+
toString() {
|
|
64
|
+
if (this.toNumber() === 0) {
|
|
65
|
+
return '0';
|
|
66
|
+
}
|
|
67
|
+
return (0, helpers_1.scientificStrToDecimalStr)(super.toString());
|
|
68
|
+
}
|
|
69
|
+
toTwos(bitCount) {
|
|
70
|
+
let binaryStr;
|
|
71
|
+
if (this.gte(0)) {
|
|
72
|
+
const twosComp = this.toNumber().toString(2);
|
|
73
|
+
binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
|
|
77
|
+
if (Number(binaryStr) < 0) {
|
|
78
|
+
throw new Error('Cannot calculate twos complement');
|
|
213
79
|
}
|
|
214
80
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
81
|
+
const binary = `0b${binaryStr}`;
|
|
82
|
+
const decimal = Number(binary);
|
|
83
|
+
return tinyBig(decimal);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.TinyBig = TinyBig;
|
|
218
87
|
/**
|
|
219
88
|
* Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
|
|
220
89
|
*
|
|
@@ -225,6 +94,8 @@ import { scientificStrToDecimalStr } from "./helpers";
|
|
|
225
94
|
* tinyBig(10).times(3).toNumber()
|
|
226
95
|
* // 30
|
|
227
96
|
* ```
|
|
228
|
-
*/
|
|
97
|
+
*/
|
|
98
|
+
function tinyBig(value) {
|
|
229
99
|
return new TinyBig(value);
|
|
230
100
|
}
|
|
101
|
+
exports.tinyBig = tinyBig;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
throw new Error("".concat(allowedTypes.join(" or "), " required. Received ").concat(typeof value === "undefined" ? "undefined" : _type_of(value)));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateType = void 0;
|
|
4
|
+
const validateType = (value, allowedTypes) => {
|
|
5
|
+
if (!allowedTypes.includes(typeof value)) {
|
|
6
|
+
throw new Error(`${allowedTypes.join(' or ')} required. Received ${typeof value}`);
|
|
8
7
|
}
|
|
9
8
|
};
|
|
9
|
+
exports.validateType = validateType;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/ export { };
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|