essential-eth 0.8.0 → 0.9.1-next.0
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 +38 -34
- package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
- package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
- package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
- package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
- package/dist/cjs/classes/utils/clean-block.js +4 -4
- package/dist/cjs/classes/utils/clean-log.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction.js +4 -4
- package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
- package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
- package/dist/cjs/classes/utils/fetchers.js +20 -12
- package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
- package/dist/cjs/index.d.ts +21 -21
- package/dist/cjs/index.js +21 -21
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -41
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -1
- package/dist/cjs/providers/AlchemyProvider.d.ts +4 -0
- package/dist/cjs/providers/AlchemyProvider.js +84 -0
- package/dist/cjs/providers/BaseProvider.js +471 -404
- package/dist/cjs/providers/FallthroughProvider.js +74 -38
- package/dist/cjs/providers/JsonRpcProvider.js +52 -31
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
- package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +27 -94
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -278
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +29 -64
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
- 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 +149 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
- package/dist/cjs/providers/test/mock-of.d.ts +2 -0
- package/dist/cjs/providers/test/mock-of.js +9 -0
- package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
- package/dist/cjs/providers/test/rpc-urls.js +12 -6
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +151 -0
- package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
- package/dist/cjs/providers/utils/chains-info.js +13 -1344
- package/dist/cjs/shared/tiny-big/helpers.js +18 -18
- package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
- package/dist/cjs/shared/validate-type.d.ts +1 -1
- package/dist/cjs/shared/validate-type.js +4 -4
- package/dist/cjs/types/Block.types.d.ts +3 -3
- package/dist/cjs/types/Contract.types.d.ts +4 -4
- package/dist/cjs/types/Transaction.types.d.ts +5 -5
- package/dist/cjs/utils/bytes.d.ts +4 -4
- package/dist/cjs/utils/bytes.js +3 -3
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
- package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
- package/dist/cjs/utils/tests/compute-address.test.js +42 -20
- package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
- package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
- package/dist/cjs/utils/tests/hash-message.test.js +26 -15
- package/dist/cjs/utils/tests/is-address.test.js +2 -9
- package/dist/cjs/utils/tests/keccak256.test.js +36 -12
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
- package/dist/cjs/utils/tests/split-signature.test.js +29 -8
- package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
- package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
- 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 -21
- package/dist/esm/index.js +16 -16
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
- package/dist/esm/providers/AlchemyProvider.js +7 -0
- package/dist/esm/providers/FallthroughProvider.js +15 -7
- 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/mock-of.d.ts +2 -0
- package/dist/esm/providers/test/mock-of.js +1 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
- package/dist/esm/providers/test/rpc-urls.js +14 -6
- 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 +16 -38
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
|
@@ -8,21 +8,21 @@
|
|
|
8
8
|
* stripTrailingZeros('0005280');
|
|
9
9
|
* // '5280'
|
|
10
10
|
* ```
|
|
11
|
-
*/ function
|
|
11
|
+
*/ function _array_like_to_array(arr, len) {
|
|
12
12
|
if (len == null || len > arr.length) len = arr.length;
|
|
13
13
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
14
14
|
return arr2;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function _array_with_holes(arr) {
|
|
17
17
|
if (Array.isArray(arr)) return arr;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
if (Array.isArray(arr)) return
|
|
19
|
+
function _array_without_holes(arr) {
|
|
20
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function _iterable_to_array(iter) {
|
|
23
23
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function _iterable_to_array_limit(arr, i) {
|
|
26
26
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
27
27
|
if (_i == null) return;
|
|
28
28
|
var _arr = [];
|
|
@@ -46,25 +46,25 @@ function _iterableToArrayLimit(arr, i) {
|
|
|
46
46
|
}
|
|
47
47
|
return _arr;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function _non_iterable_rest() {
|
|
50
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
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function _non_iterable_spread() {
|
|
53
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
54
|
}
|
|
55
|
-
function
|
|
56
|
-
return
|
|
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
57
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
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
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
62
62
|
if (!o) return;
|
|
63
|
-
if (typeof o === "string") return
|
|
63
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
64
64
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
65
65
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
66
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
|
|
67
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
68
68
|
}
|
|
69
69
|
function stripTrailingZeroes(numberString) {
|
|
70
70
|
var isNegative = numberString.startsWith("-");
|
|
@@ -102,12 +102,12 @@ function stripTrailingZeroes(numberString) {
|
|
|
102
102
|
return stripTrailingZeroes(scientificString);
|
|
103
103
|
}
|
|
104
104
|
// eslint-disable-next-line prefer-const
|
|
105
|
-
var _scientificString_split =
|
|
105
|
+
var _scientificString_split = _sliced_to_array(scientificString.split(/e/i /* lowercase and uppercase E */ ), 2), base = _scientificString_split[0], power = _scientificString_split[1];
|
|
106
106
|
// remove the leading "-" if negative
|
|
107
107
|
var isNegative = Number(base) < 0;
|
|
108
108
|
base = base.replace("-", "");
|
|
109
109
|
base = stripTrailingZeroes(base);
|
|
110
|
-
var _base_split =
|
|
110
|
+
var _base_split = _sliced_to_array(base.split("."), 2), wholeNumber = _base_split[0], tmp = _base_split[1], fraction /* move decimal this many places */ = tmp === void 0 ? "" : tmp;
|
|
111
111
|
if (Number(power) === 0) {
|
|
112
112
|
return "".concat(isNegative ? "-" : "").concat(stripTrailingZeroes(base));
|
|
113
113
|
} else {
|
|
@@ -128,7 +128,7 @@ function stripTrailingZeroes(numberString) {
|
|
|
128
128
|
// starts with zeroes
|
|
129
129
|
splitPaddedNumber = [
|
|
130
130
|
"."
|
|
131
|
-
].concat(
|
|
131
|
+
].concat(_to_consumable_array(splitPaddedNumber));
|
|
132
132
|
} else {
|
|
133
133
|
splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, ".");
|
|
134
134
|
}
|
|
@@ -1,35 +1,62 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
2
|
if (self === void 0) {
|
|
3
3
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
4
|
}
|
|
5
5
|
return self;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function _class_call_check(instance, Constructor) {
|
|
8
8
|
if (!(instance instanceof Constructor)) {
|
|
9
9
|
throw new TypeError("Cannot call a class as a function");
|
|
10
10
|
}
|
|
11
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
|
+
}
|
|
12
39
|
function _get(target, property, receiver) {
|
|
13
40
|
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
14
41
|
_get = Reflect.get;
|
|
15
42
|
} else {
|
|
16
|
-
_get = function
|
|
17
|
-
var base =
|
|
43
|
+
_get = function get(target, property, receiver) {
|
|
44
|
+
var base = _super_prop_base(target, property);
|
|
18
45
|
if (!base) return;
|
|
19
46
|
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
20
47
|
if (desc.get) {
|
|
21
|
-
return desc.get.call(receiver);
|
|
48
|
+
return desc.get.call(receiver || target);
|
|
22
49
|
}
|
|
23
50
|
return desc.value;
|
|
24
51
|
};
|
|
25
52
|
}
|
|
26
53
|
return _get(target, property, receiver || target);
|
|
27
54
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
55
|
+
function _get_prototype_of(o) {
|
|
56
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
30
57
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
31
58
|
};
|
|
32
|
-
return
|
|
59
|
+
return _get_prototype_of(o);
|
|
33
60
|
}
|
|
34
61
|
function _inherits(subClass, superClass) {
|
|
35
62
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
@@ -42,33 +69,33 @@ function _inherits(subClass, superClass) {
|
|
|
42
69
|
configurable: true
|
|
43
70
|
}
|
|
44
71
|
});
|
|
45
|
-
if (superClass)
|
|
72
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
46
73
|
}
|
|
47
|
-
function
|
|
48
|
-
if (call && (
|
|
74
|
+
function _possible_constructor_return(self, call) {
|
|
75
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
49
76
|
return call;
|
|
50
77
|
}
|
|
51
|
-
return
|
|
78
|
+
return _assert_this_initialized(self);
|
|
52
79
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
80
|
+
function _set_prototype_of(o, p) {
|
|
81
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
55
82
|
o.__proto__ = p;
|
|
56
83
|
return o;
|
|
57
84
|
};
|
|
58
|
-
return
|
|
85
|
+
return _set_prototype_of(o, p);
|
|
59
86
|
}
|
|
60
|
-
function
|
|
87
|
+
function _super_prop_base(object, property) {
|
|
61
88
|
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
62
|
-
object =
|
|
89
|
+
object = _get_prototype_of(object);
|
|
63
90
|
if (object === null) break;
|
|
64
91
|
}
|
|
65
92
|
return object;
|
|
66
93
|
}
|
|
67
|
-
|
|
94
|
+
function _type_of(obj) {
|
|
68
95
|
"@swc/helpers - typeof";
|
|
69
96
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
70
|
-
}
|
|
71
|
-
function
|
|
97
|
+
}
|
|
98
|
+
function _is_native_reflect_construct() {
|
|
72
99
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
73
100
|
if (Reflect.construct.sham) return false;
|
|
74
101
|
if (typeof Proxy === "function") return true;
|
|
@@ -79,17 +106,17 @@ function _isNativeReflectConstruct() {
|
|
|
79
106
|
return false;
|
|
80
107
|
}
|
|
81
108
|
}
|
|
82
|
-
function
|
|
83
|
-
var hasNativeReflectConstruct =
|
|
109
|
+
function _create_super(Derived) {
|
|
110
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
84
111
|
return function _createSuperInternal() {
|
|
85
|
-
var Super =
|
|
112
|
+
var Super = _get_prototype_of(Derived), result;
|
|
86
113
|
if (hasNativeReflectConstruct) {
|
|
87
|
-
var NewTarget =
|
|
114
|
+
var NewTarget = _get_prototype_of(this).constructor;
|
|
88
115
|
result = Reflect.construct(Super, arguments, NewTarget);
|
|
89
116
|
} else {
|
|
90
117
|
result = Super.apply(this, arguments);
|
|
91
118
|
}
|
|
92
|
-
return
|
|
119
|
+
return _possible_constructor_return(this, result);
|
|
93
120
|
};
|
|
94
121
|
}
|
|
95
122
|
import Big from "big.js";
|
|
@@ -101,9 +128,9 @@ import { scientificStrToDecimalStr } from "./helpers";
|
|
|
101
128
|
*/ export var TinyBig = /*#__PURE__*/ function(Big) {
|
|
102
129
|
"use strict";
|
|
103
130
|
_inherits(TinyBig, Big);
|
|
104
|
-
var _super =
|
|
131
|
+
var _super = _create_super(TinyBig);
|
|
105
132
|
function TinyBig(value) {
|
|
106
|
-
|
|
133
|
+
_class_call_check(this, TinyBig);
|
|
107
134
|
var _this;
|
|
108
135
|
if (typeof value === "string" && value.startsWith("0x")) {
|
|
109
136
|
value = hexToDecimal(value);
|
|
@@ -126,13 +153,14 @@ import { scientificStrToDecimalStr } from "./helpers";
|
|
|
126
153
|
* padAndChop('essential-eth', 'A', 20);
|
|
127
154
|
* // 'AAAAAAAessential-eth'
|
|
128
155
|
* ```
|
|
129
|
-
*/ _this
|
|
156
|
+
*/ _define_property(_assert_this_initialized(_this), "padAndChop", function(str, padChar, length) {
|
|
130
157
|
return (Array(length).fill(padChar).join("") + str).slice(length * -1);
|
|
131
|
-
};
|
|
158
|
+
});
|
|
132
159
|
return _this;
|
|
133
160
|
}
|
|
134
|
-
|
|
135
|
-
|
|
161
|
+
_create_class(TinyBig, [
|
|
162
|
+
{
|
|
163
|
+
/**
|
|
136
164
|
* Used anytime you're passing in "value" to ethers or web3
|
|
137
165
|
* For now, TypeScript will complain that `TinyBig` is not a `BigNumberish`. You can // @ts-ignore or call this
|
|
138
166
|
*
|
|
@@ -146,33 +174,45 @@ import { scientificStrToDecimalStr } from "./helpers";
|
|
|
146
174
|
* ```javascript
|
|
147
175
|
* tinyBig(681365874).toHexString();
|
|
148
176
|
* // '0x289cd172'
|
|
149
|
-
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
*/ key: "toHexString",
|
|
178
|
+
value: function toHexString() {
|
|
179
|
+
return "0x".concat(BigInt(this.toString()).toString(16));
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
key: "toNumber",
|
|
184
|
+
value: function toNumber() {
|
|
185
|
+
return Number(scientificStrToDecimalStr(_get(_get_prototype_of(TinyBig.prototype), "toString", this).call(this)));
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: "toString",
|
|
190
|
+
value: function toString() {
|
|
191
|
+
if (this.toNumber() === 0) {
|
|
192
|
+
return "0";
|
|
193
|
+
}
|
|
194
|
+
return scientificStrToDecimalStr(_get(_get_prototype_of(TinyBig.prototype), "toString", this).call(this));
|
|
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);
|
|
170
213
|
}
|
|
171
214
|
}
|
|
172
|
-
|
|
173
|
-
var decimal = Number(binary);
|
|
174
|
-
return tinyBig(decimal);
|
|
175
|
-
};
|
|
215
|
+
]);
|
|
176
216
|
return TinyBig;
|
|
177
217
|
}(Big);
|
|
178
218
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BN from "bn.js";
|
|
2
2
|
import { tinyBig } from "./tiny-big";
|
|
3
3
|
describe("tiny-big", function() {
|
|
4
4
|
it("allows hex string input", function() {
|
|
@@ -28,7 +28,7 @@ describe("tiny-big", function() {
|
|
|
28
28
|
];
|
|
29
29
|
inputs.forEach(function(param) {
|
|
30
30
|
var num = param.num, bitCount = param.bitCount;
|
|
31
|
-
expect(tinyBig(num).toTwos(bitCount).toString()).toBe(
|
|
31
|
+
expect(tinyBig(num).toTwos(bitCount).toString()).toBe(new BN(num).toTwos(bitCount).toString());
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
});
|
|
@@ -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
|
-
|
|
1
|
+
function _type_of(obj) {
|
|
2
2
|
"@swc/helpers - typeof";
|
|
3
3
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
-
}
|
|
4
|
+
}
|
|
5
5
|
export var validateType = function(value, allowedTypes) {
|
|
6
|
-
if (!allowedTypes.includes(typeof value === "undefined" ? "undefined" :
|
|
7
|
-
throw new Error("".concat(allowedTypes.join(" or "), " required. Received ").concat(typeof value === "undefined" ? "undefined" :
|
|
6
|
+
if (!allowedTypes.includes(typeof value === "undefined" ? "undefined" : _type_of(value))) {
|
|
7
|
+
throw new Error("".concat(allowedTypes.join(" or "), " required. Received ").concat(typeof value === "undefined" ? "undefined" : _type_of(value)));
|
|
8
8
|
}
|
|
9
9
|
};
|
|
@@ -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,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,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,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;
|
package/dist/cjs/utils/bytes.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// primarily duplicate code from https://github.com/ethers-io/ethers.js/blob/f599d6f23dad0d0acaa3828d6b7acaab2d5e455b/packages/bytes/src.ts/index.ts
|
|
2
|
-
|
|
2
|
+
function _type_of(obj) {
|
|
3
3
|
"@swc/helpers - typeof";
|
|
4
4
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
5
|
-
}
|
|
5
|
+
}
|
|
6
6
|
import { logger } from "../logger/logger";
|
|
7
7
|
/**
|
|
8
8
|
* Check if a value can be converted to a hex string
|
|
@@ -310,7 +310,7 @@ var HexCharacters = "0123456789abcdef";
|
|
|
310
310
|
}
|
|
311
311
|
return "0x00";
|
|
312
312
|
}
|
|
313
|
-
if ((typeof value === "undefined" ? "undefined" :
|
|
313
|
+
if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "bigint") {
|
|
314
314
|
value = value.toString(16);
|
|
315
315
|
if (value.length % 2) {
|
|
316
316
|
return "0x0" + value;
|
|
@@ -1,40 +1,64 @@
|
|
|
1
|
-
import * as ethers from "ethers";
|
|
2
1
|
import { arrayify, tinyBig } from "../../..";
|
|
3
2
|
describe("arrayify", function() {
|
|
4
|
-
it("
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
it("should correctly arrayify - values", function() {
|
|
4
|
+
var testCases = [
|
|
5
|
+
{
|
|
6
|
+
input: 0,
|
|
7
|
+
expected: new Uint8Array([
|
|
8
|
+
0
|
|
9
|
+
])
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
input: 1,
|
|
13
|
+
expected: new Uint8Array([
|
|
14
|
+
1
|
|
15
|
+
])
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
input: "0x1234",
|
|
19
|
+
expected: new Uint8Array([
|
|
20
|
+
18,
|
|
21
|
+
52
|
|
22
|
+
])
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
input: new Uint8Array(2),
|
|
26
|
+
expected: new Uint8Array(2)
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
input: tinyBig(17),
|
|
30
|
+
expected: new Uint8Array([
|
|
31
|
+
17
|
|
32
|
+
])
|
|
33
|
+
}
|
|
11
34
|
];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
expect(arrayify(input)).toStrictEqual(ethers.utils.arrayify(input));
|
|
35
|
+
testCases.forEach(function(testCase) {
|
|
36
|
+
expect(arrayify(testCase.input)).toStrictEqual(testCase.expected);
|
|
15
37
|
});
|
|
38
|
+
});
|
|
39
|
+
it("should correctly arrayify - values with options", function() {
|
|
16
40
|
expect(arrayify("12", {
|
|
17
41
|
allowMissingPrefix: true
|
|
18
|
-
})).toStrictEqual(
|
|
19
|
-
|
|
20
|
-
|
|
42
|
+
})).toStrictEqual(new Uint8Array([
|
|
43
|
+
18
|
|
44
|
+
]));
|
|
21
45
|
expect(arrayify("0x1", {
|
|
22
46
|
hexPad: "left"
|
|
23
|
-
})).toStrictEqual(
|
|
24
|
-
|
|
25
|
-
|
|
47
|
+
})).toStrictEqual(new Uint8Array([
|
|
48
|
+
1
|
|
49
|
+
]));
|
|
26
50
|
expect(arrayify("0x1", {
|
|
27
51
|
hexPad: "right"
|
|
28
|
-
})).toStrictEqual(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
52
|
+
})).toStrictEqual(new Uint8Array([
|
|
53
|
+
16
|
|
54
|
+
]));
|
|
55
|
+
});
|
|
56
|
+
it("should throw for invalid values", function() {
|
|
32
57
|
expect(function() {
|
|
33
58
|
return arrayify(tinyBig(15));
|
|
34
|
-
}).toThrow();
|
|
35
|
-
// invalid arrayify value
|
|
59
|
+
}).toThrow(); // hex data is odd-length
|
|
36
60
|
expect(function() {
|
|
37
61
|
return arrayify(false);
|
|
38
|
-
}).toThrow();
|
|
62
|
+
}).toThrow(); // invalid arrayify value
|
|
39
63
|
});
|
|
40
64
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as ethers from "ethers";
|
|
2
1
|
import { concat } from "../../..";
|
|
3
2
|
describe("concat", function() {
|
|
4
|
-
it("matches
|
|
3
|
+
it("matches expected result", function() {
|
|
5
4
|
var inputs = [
|
|
6
5
|
[
|
|
7
6
|
0,
|
|
@@ -9,7 +8,10 @@ describe("concat", function() {
|
|
|
9
8
|
]
|
|
10
9
|
];
|
|
11
10
|
inputs.forEach(function(input) {
|
|
12
|
-
expect(concat(input)).toStrictEqual(
|
|
11
|
+
expect(concat(input)).toStrictEqual(new Uint8Array([
|
|
12
|
+
0,
|
|
13
|
+
1
|
|
14
|
+
]));
|
|
13
15
|
});
|
|
14
16
|
});
|
|
15
17
|
});
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
import { utils as ethers } from "ethers";
|
|
2
1
|
import { hexConcat } from "../../bytes";
|
|
3
2
|
describe("utils.hexConcat", function() {
|
|
4
|
-
it("should
|
|
3
|
+
it("should correctly concatenate - hex values", function() {
|
|
5
4
|
var values = [
|
|
6
5
|
"0x2048",
|
|
7
6
|
"0x6917",
|
|
8
7
|
"0x85616379"
|
|
9
8
|
];
|
|
10
|
-
|
|
9
|
+
var expected = "0x2048691785616379";
|
|
10
|
+
expect(hexConcat(values)).toBe(expected);
|
|
11
11
|
});
|
|
12
|
-
it("should
|
|
12
|
+
it("should correctly concatenate - UInt8Array values", function() {
|
|
13
13
|
var values = [
|
|
14
|
-
[
|
|
14
|
+
new Uint8Array([
|
|
15
15
|
5,
|
|
16
16
|
10,
|
|
17
17
|
247,
|
|
18
18
|
22
|
|
19
|
-
],
|
|
20
|
-
[
|
|
19
|
+
]),
|
|
20
|
+
new Uint8Array([
|
|
21
21
|
50,
|
|
22
22
|
255,
|
|
23
23
|
3
|
|
24
|
-
],
|
|
25
|
-
[
|
|
24
|
+
]),
|
|
25
|
+
new Uint8Array([
|
|
26
26
|
59,
|
|
27
27
|
36,
|
|
28
28
|
18,
|
|
29
29
|
46,
|
|
30
30
|
198,
|
|
31
31
|
234
|
|
32
|
-
]
|
|
32
|
+
])
|
|
33
33
|
];
|
|
34
|
-
|
|
34
|
+
var expected = "0x050af71632ff033b24122ec6ea";
|
|
35
|
+
expect(hexConcat(values)).toStrictEqual(expected);
|
|
35
36
|
});
|
|
36
|
-
it("should
|
|
37
|
+
it("should correctly concatenate - hex & UInt8Array values", function() {
|
|
37
38
|
var values = [
|
|
38
39
|
"0x2048",
|
|
39
40
|
[
|
|
@@ -58,6 +59,7 @@ describe("utils.hexConcat", function() {
|
|
|
58
59
|
234
|
|
59
60
|
]
|
|
60
61
|
];
|
|
61
|
-
|
|
62
|
+
var expected = "0x2048050af716691732ff03856163793b24122ec6ea";
|
|
63
|
+
expect(hexConcat(values)).toStrictEqual(expected);
|
|
62
64
|
});
|
|
63
65
|
});
|