essential-eth 0.9.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 -307
- package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
- package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
- 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.d.ts +1 -1
- 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.d.ts +8 -2
- package/dist/cjs/classes/utils/fetchers.js +52 -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.d.ts +21 -22
- package/dist/cjs/index.js +56 -26
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +23 -79
- 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 +511 -882
- package/dist/cjs/providers/FallthroughProvider.js +46 -123
- package/dist/cjs/providers/JsonRpcProvider.js +28 -93
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +152 -0
- package/dist/cjs/providers/test/mock-of.js +6 -8
- package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
- package/dist/cjs/providers/test/rpc-urls.js +23 -14
- package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
- package/dist/cjs/providers/utils/chains-info.js +16 -1345
- package/dist/cjs/shared/tiny-big/helpers.js +42 -93
- package/dist/cjs/shared/tiny-big/tiny-big.js +72 -161
- package/dist/cjs/shared/validate-type.d.ts +1 -1
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.d.ts +3 -3
- package/dist/cjs/types/Block.types.js +2 -1
- package/dist/cjs/types/Contract.types.d.ts +4 -4
- 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.d.ts +5 -5
- package/dist/cjs/types/Transaction.types.js +2 -1
- package/dist/cjs/utils/bytes.d.ts +4 -4
- 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/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/esm/classes/utils/fetchers.d.ts +8 -2
- package/dist/esm/classes/utils/fetchers.js +6 -3
- package/dist/esm/index.d.ts +21 -22
- package/dist/esm/index.js +16 -17
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/FallthroughProvider.js +3 -3
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
- package/dist/esm/providers/test/rpc-urls.js +7 -4
- package/dist/esm/providers/utils/chains-info.d.ts +5 -448
- package/dist/esm/providers/utils/chains-info.js +13 -1344
- package/dist/esm/shared/validate-type.d.ts +1 -1
- package/dist/esm/types/Block.types.d.ts +3 -3
- package/dist/esm/types/Contract.types.d.ts +4 -4
- package/dist/esm/types/Transaction.types.d.ts +5 -5
- package/dist/esm/utils/bytes.d.ts +4 -4
- package/package.json +23 -51
- package/readme.md +15 -38
- package/dist/cjs/classes/test/Contract/crv.test.js +0 -690
- package/dist/cjs/classes/test/Contract/ens.test.js +0 -217
- 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 -387
- 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 -276
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -436
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -288
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -261
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -159
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -477
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -311
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -212
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -164
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -274
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -301
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -307
- 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 -40
- package/dist/cjs/utils/tests/bytes/concat.test.js +0 -15
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -63
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -49
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -52
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -58
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -85
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -62
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -62
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -69
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -33
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -88
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -57
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -80
- package/dist/cjs/utils/tests/compute-address.test.js +0 -27
- package/dist/cjs/utils/tests/compute-public-key.test.js +0 -15
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -44
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
- package/dist/cjs/utils/tests/hash-message.test.js +0 -21
- package/dist/cjs/utils/tests/is-address.test.js +0 -55
- package/dist/cjs/utils/tests/keccak256.test.js +0 -97
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -310
- package/dist/cjs/utils/tests/split-signature.test.js +0 -25
- package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -42
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -14
- package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -51
|
@@ -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 _arrayWithHoles(arr) {
|
|
17
|
-
if (Array.isArray(arr)) return arr;
|
|
18
|
-
}
|
|
19
|
-
function _arrayWithoutHoles(arr) {
|
|
20
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
21
|
-
}
|
|
22
|
-
function _iterableToArray(iter) {
|
|
23
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
24
|
-
}
|
|
25
|
-
function _iterableToArrayLimit(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 _nonIterableRest() {
|
|
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 _nonIterableSpread() {
|
|
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 _slicedToArray(arr, i) {
|
|
56
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
57
|
-
}
|
|
58
|
-
function _toConsumableArray(arr) {
|
|
59
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
60
|
-
}
|
|
61
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
62
|
-
if (!o) return;
|
|
63
|
-
if (typeof o === "string") return _arrayLikeToArray(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 _arrayLikeToArray(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(_toConsumableArray(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,180 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
return self;
|
|
6
|
-
}
|
|
7
|
-
function _classCallCheck(instance, Constructor) {
|
|
8
|
-
if (!(instance instanceof Constructor)) {
|
|
9
|
-
throw new TypeError("Cannot call a class as a function");
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function _get(target, property, receiver) {
|
|
13
|
-
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
14
|
-
_get = Reflect.get;
|
|
15
|
-
} else {
|
|
16
|
-
_get = function _get(target, property, receiver) {
|
|
17
|
-
var base = _superPropBase(target, property);
|
|
18
|
-
if (!base) return;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
20
|
-
if (desc.get) {
|
|
21
|
-
return desc.get.call(receiver);
|
|
22
|
-
}
|
|
23
|
-
return desc.value;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return _get(target, property, receiver || target);
|
|
27
|
-
}
|
|
28
|
-
function _getPrototypeOf(o) {
|
|
29
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
30
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
31
|
-
};
|
|
32
|
-
return _getPrototypeOf(o);
|
|
33
|
-
}
|
|
34
|
-
function _inherits(subClass, superClass) {
|
|
35
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
36
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
37
|
-
}
|
|
38
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
39
|
-
constructor: {
|
|
40
|
-
value: subClass,
|
|
41
|
-
writable: true,
|
|
42
|
-
configurable: true
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
46
|
-
}
|
|
47
|
-
function _possibleConstructorReturn(self, call) {
|
|
48
|
-
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
49
|
-
return call;
|
|
50
|
-
}
|
|
51
|
-
return _assertThisInitialized(self);
|
|
52
|
-
}
|
|
53
|
-
function _setPrototypeOf(o, p) {
|
|
54
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
55
|
-
o.__proto__ = p;
|
|
56
|
-
return o;
|
|
57
|
-
};
|
|
58
|
-
return _setPrototypeOf(o, p);
|
|
59
|
-
}
|
|
60
|
-
function _superPropBase(object, property) {
|
|
61
|
-
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
62
|
-
object = _getPrototypeOf(object);
|
|
63
|
-
if (object === null) break;
|
|
64
|
-
}
|
|
65
|
-
return object;
|
|
66
|
-
}
|
|
67
|
-
var _typeof = function(obj) {
|
|
68
|
-
"@swc/helpers - typeof";
|
|
69
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
70
4
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
77
|
-
return true;
|
|
78
|
-
} catch (e) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function _createSuper(Derived) {
|
|
83
|
-
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
84
|
-
return function _createSuperInternal() {
|
|
85
|
-
var Super = _getPrototypeOf(Derived), result;
|
|
86
|
-
if (hasNativeReflectConstruct) {
|
|
87
|
-
var NewTarget = _getPrototypeOf(this).constructor;
|
|
88
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
|
89
|
-
} else {
|
|
90
|
-
result = Super.apply(this, arguments);
|
|
91
|
-
}
|
|
92
|
-
return _possibleConstructorReturn(this, result);
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
import Big from "big.js";
|
|
96
|
-
import { hexToDecimal } from "../../classes/utils/hex-to-decimal";
|
|
97
|
-
import { scientificStrToDecimalStr } from "./helpers";
|
|
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");
|
|
98
10
|
/**
|
|
99
11
|
* A wrapper around [big.js](https://github.com/MikeMcl/big.js) which expands scientific notation and creates a "toHexString" function.
|
|
100
12
|
* This is the return type of every operation on ether, wei, etc.
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
_classCallCheck(this, TinyBig);
|
|
107
|
-
var _this;
|
|
108
|
-
if (typeof value === "string" && value.startsWith("0x")) {
|
|
109
|
-
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);
|
|
110
18
|
}
|
|
111
|
-
|
|
19
|
+
super(value);
|
|
112
20
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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);
|
|
131
40
|
};
|
|
132
|
-
return _this;
|
|
133
41
|
}
|
|
134
|
-
var _proto = TinyBig.prototype;
|
|
135
42
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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() {
|
|
156
64
|
if (this.toNumber() === 0) {
|
|
157
|
-
return
|
|
65
|
+
return '0';
|
|
158
66
|
}
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
67
|
+
return (0, helpers_1.scientificStrToDecimalStr)(super.toString());
|
|
68
|
+
}
|
|
69
|
+
toTwos(bitCount) {
|
|
70
|
+
let binaryStr;
|
|
163
71
|
if (this.gte(0)) {
|
|
164
|
-
|
|
165
|
-
binaryStr = this.padAndChop(twosComp,
|
|
166
|
-
}
|
|
72
|
+
const twosComp = this.toNumber().toString(2);
|
|
73
|
+
binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
167
76
|
binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
|
|
168
77
|
if (Number(binaryStr) < 0) {
|
|
169
|
-
throw new Error(
|
|
78
|
+
throw new Error('Cannot calculate twos complement');
|
|
170
79
|
}
|
|
171
80
|
}
|
|
172
|
-
|
|
173
|
-
|
|
81
|
+
const binary = `0b${binaryStr}`;
|
|
82
|
+
const decimal = Number(binary);
|
|
174
83
|
return tinyBig(decimal);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.TinyBig = TinyBig;
|
|
178
87
|
/**
|
|
179
88
|
* Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
|
|
180
89
|
*
|
|
@@ -185,6 +94,8 @@ import { scientificStrToDecimalStr } from "./helpers";
|
|
|
185
94
|
* tinyBig(10).times(3).toNumber()
|
|
186
95
|
* // 30
|
|
187
96
|
* ```
|
|
188
|
-
*/
|
|
97
|
+
*/
|
|
98
|
+
function tinyBig(value) {
|
|
189
99
|
return new TinyBig(value);
|
|
190
100
|
}
|
|
101
|
+
exports.tinyBig = tinyBig;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
type JSPrimitiveTypes = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
|
|
2
2
|
export declare const validateType: (value: unknown, allowedTypes: JSPrimitiveTypes[]) => void;
|
|
3
3
|
export {};
|
|
@@ -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" : _typeof(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,7 +1,7 @@
|
|
|
1
1
|
import type { TinyBig } from './../shared/tiny-big/tiny-big';
|
|
2
2
|
import type { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
|
|
3
|
-
|
|
4
|
-
export
|
|
3
|
+
type Modify<T, R> = Omit<T, keyof R> & R;
|
|
4
|
+
export type BlockResponse = Modify<RPCBlock, {
|
|
5
5
|
baseFeePerGas: TinyBig;
|
|
6
6
|
difficulty: TinyBig;
|
|
7
7
|
gasLimit: TinyBig;
|
|
@@ -36,5 +36,5 @@ export interface RPCBlock {
|
|
|
36
36
|
transactionsRoot: string;
|
|
37
37
|
uncles: Array<string>;
|
|
38
38
|
}
|
|
39
|
-
export
|
|
39
|
+
export type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
|
|
40
40
|
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export type ContractTypes = 'bool' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32' | 'bytes32[]' | 'address' | 'address payable' | 'address[4]' | 'address[100]' | 'uint256' | 'uint256[100]' | 'uint8' | 'uint32' | string;
|
|
2
|
+
export type ContractInterface = JSONABI;
|
|
3
|
+
export type ContractFunction<T = any> = (...args: Array<any>) => Promise<T>;
|
|
4
4
|
export interface JSONABIArgument {
|
|
5
5
|
anonymous?: false;
|
|
6
6
|
inputs: {
|
|
@@ -21,4 +21,4 @@ export interface JSONABIArgument {
|
|
|
21
21
|
constant?: boolean;
|
|
22
22
|
payable?: boolean;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export type JSONABI = JSONABIArgument[];
|
|
@@ -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,12 +1,12 @@
|
|
|
1
1
|
import type Big from 'big.js';
|
|
2
2
|
import type { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
3
3
|
import type { BytesLike } from './../utils/bytes';
|
|
4
|
-
|
|
4
|
+
type Modify<T, R> = Omit<T, keyof R> & R;
|
|
5
5
|
export interface RPCTransaction extends RPCBlockTransaction {
|
|
6
6
|
maxFeePerGas: string;
|
|
7
7
|
maxPriorityFeePerGas: string;
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type TransactionResponse = Modify<RPCTransaction, {
|
|
10
10
|
blockNumber: number;
|
|
11
11
|
chainId: number;
|
|
12
12
|
gas: TinyBig;
|
|
@@ -22,7 +22,7 @@ export declare type TransactionResponse = Modify<RPCTransaction, {
|
|
|
22
22
|
maxPriorityFeePerGas: TinyBig;
|
|
23
23
|
confirmations: number;
|
|
24
24
|
}>;
|
|
25
|
-
export
|
|
25
|
+
export type TransactionReceipt = Modify<RPCTransactionReceipt, {
|
|
26
26
|
blockNumber: number;
|
|
27
27
|
cumulativeGasUsed: TinyBig;
|
|
28
28
|
effectiveGasPrice: TinyBig;
|
|
@@ -59,12 +59,12 @@ export interface TransactionRequest {
|
|
|
59
59
|
maxPriorityFeePerGas?: TinyBig | string | Big | number;
|
|
60
60
|
maxFeePerGas?: TinyBig | string | Big | number;
|
|
61
61
|
}
|
|
62
|
-
export
|
|
62
|
+
export type Log = Modify<RPCLog, {
|
|
63
63
|
blockNumber: number;
|
|
64
64
|
logIndex: number;
|
|
65
65
|
transactionIndex: number;
|
|
66
66
|
}>;
|
|
67
|
-
export
|
|
67
|
+
export type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
|
|
68
68
|
export interface RPCBlockTransaction {
|
|
69
69
|
blockHash: string;
|
|
70
70
|
blockNumber: string;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export type Bytes = ArrayLike<number>;
|
|
2
|
+
export type BytesLike = Bytes | string;
|
|
3
|
+
export type BytesLikeWithNumber = BytesLike | number;
|
|
4
4
|
export interface DataOptions {
|
|
5
5
|
allowMissingPrefix?: boolean;
|
|
6
6
|
hexPad?: 'left' | 'right' | null;
|
|
@@ -8,7 +8,7 @@ export interface DataOptions {
|
|
|
8
8
|
export interface Hexable {
|
|
9
9
|
toHexString(): string;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export type SignatureLike = {
|
|
12
12
|
r: string;
|
|
13
13
|
s?: string;
|
|
14
14
|
_vs?: string;
|