essential-eth 0.8.0 → 0.9.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.
@@ -1 +1 @@
1
- export declare const version = "0.8.0";
1
+ export declare const version = "0.9.0";
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export var version = "0.8.0";
2
+ export var version = "0.9.0";
@@ -0,0 +1,4 @@
1
+ import { JsonRpcProvider } from './JsonRpcProvider';
2
+ export declare class AlchemyProvider extends JsonRpcProvider {
3
+ constructor(apiKey: string, network?: string);
4
+ }
@@ -0,0 +1,84 @@
1
+ function _assertThisInitialized(self) {
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
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 _getPrototypeOf(o) {
13
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
14
+ return o.__proto__ || Object.getPrototypeOf(o);
15
+ };
16
+ return _getPrototypeOf(o);
17
+ }
18
+ function _inherits(subClass, superClass) {
19
+ if (typeof superClass !== "function" && superClass !== null) {
20
+ throw new TypeError("Super expression must either be null or a function");
21
+ }
22
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
23
+ constructor: {
24
+ value: subClass,
25
+ writable: true,
26
+ configurable: true
27
+ }
28
+ });
29
+ if (superClass) _setPrototypeOf(subClass, superClass);
30
+ }
31
+ function _possibleConstructorReturn(self, call) {
32
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
33
+ return call;
34
+ }
35
+ return _assertThisInitialized(self);
36
+ }
37
+ function _setPrototypeOf(o, p) {
38
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
39
+ o.__proto__ = p;
40
+ return o;
41
+ };
42
+ return _setPrototypeOf(o, p);
43
+ }
44
+ var _typeof = function(obj) {
45
+ "@swc/helpers - typeof";
46
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
47
+ };
48
+ function _isNativeReflectConstruct() {
49
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
50
+ if (Reflect.construct.sham) return false;
51
+ if (typeof Proxy === "function") return true;
52
+ try {
53
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
54
+ return true;
55
+ } catch (e) {
56
+ return false;
57
+ }
58
+ }
59
+ function _createSuper(Derived) {
60
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
61
+ return function _createSuperInternal() {
62
+ var Super = _getPrototypeOf(Derived), result;
63
+ if (hasNativeReflectConstruct) {
64
+ var NewTarget = _getPrototypeOf(this).constructor;
65
+ result = Reflect.construct(Super, arguments, NewTarget);
66
+ } else {
67
+ result = Super.apply(this, arguments);
68
+ }
69
+ return _possibleConstructorReturn(this, result);
70
+ };
71
+ }
72
+ import { JsonRpcProvider } from "./JsonRpcProvider";
73
+ export var AlchemyProvider = /*#__PURE__*/ function(JsonRpcProvider) {
74
+ "use strict";
75
+ _inherits(AlchemyProvider, JsonRpcProvider);
76
+ var _super = _createSuper(AlchemyProvider);
77
+ function AlchemyProvider(apiKey) {
78
+ var network = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "mainnet";
79
+ _classCallCheck(this, AlchemyProvider);
80
+ var alchemyUrl = "https://eth-".concat(network, ".alchemyapi.io/v2/").concat(apiKey);
81
+ return _super.call(this, alchemyUrl);
82
+ }
83
+ return AlchemyProvider;
84
+ }(JsonRpcProvider);
@@ -73,14 +73,18 @@ import { logger } from "../logger/logger";
73
73
  import { BaseProvider } from "./BaseProvider";
74
74
  // https://advancedweb.hu/how-to-add-timeout-to-a-promise-in-javascript/
75
75
  var promiseTimeout = function(prom, time) {
76
- return Promise.race([
77
- prom,
78
- new Promise(function(_r, reject) {
79
- return setTimeout(function() {
80
- return reject("Promise timed out");
81
- }, time);
82
- })
83
- ]);
76
+ return new Promise(function(resolve, reject) {
77
+ var timeout = setTimeout(function() {
78
+ return reject(new Error("Promise timed out"));
79
+ }, time);
80
+ prom.then(function(result) {
81
+ clearTimeout(timeout);
82
+ resolve(result);
83
+ }).catch(function(error) {
84
+ clearTimeout(timeout);
85
+ reject(error);
86
+ });
87
+ });
84
88
  };
85
89
  var DEFAULT_TIMEOUT_DURATION = 8000;
86
90
  /**
@@ -1,11 +1,3 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
2
  try {
11
3
  var info = gen[key](arg);
@@ -35,44 +27,6 @@ function _asyncToGenerator(fn) {
35
27
  });
36
28
  };
37
29
  }
38
- function _iterableToArrayLimit(arr, i) {
39
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
- if (_i == null) return;
41
- var _arr = [];
42
- var _n = true;
43
- var _d = false;
44
- var _s, _e;
45
- try {
46
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
47
- _arr.push(_s.value);
48
- if (i && _arr.length === i) break;
49
- }
50
- } catch (err) {
51
- _d = true;
52
- _e = err;
53
- } finally{
54
- try {
55
- if (!_n && _i["return"] != null) _i["return"]();
56
- } finally{
57
- if (_d) throw _e;
58
- }
59
- }
60
- return _arr;
61
- }
62
- function _nonIterableRest() {
63
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
- }
65
- function _slicedToArray(arr, i) {
66
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
67
- }
68
- function _unsupportedIterableToArray(o, minLen) {
69
- if (!o) return;
70
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
71
- var n = Object.prototype.toString.call(o).slice(8, -1);
72
- if (n === "Object" && o.constructor) n = o.constructor.name;
73
- if (n === "Map" || n === "Set") return Array.from(n);
74
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
75
- }
76
30
  var __generator = this && this.__generator || function(thisArg, body) {
77
31
  var f, y, t, g, _ = {
78
32
  label: 0,
@@ -168,59 +122,34 @@ var __generator = this && this.__generator || function(thisArg, body) {
168
122
  };
169
123
  }
170
124
  };
171
- import { StaticJsonRpcProvider } from "@ethersproject/providers";
172
- import Web3 from "web3";
125
+ import unfetch from "isomorphic-unfetch";
173
126
  import { JsonRpcProvider } from "../../../index";
174
- // RSK has 30 second block times so tests pass more often
175
- var rpcUrl = "https://public-node.rsk.co";
127
+ import { mockOf } from "../mock-of";
128
+ jest.mock("isomorphic-unfetch");
129
+ var mockPostResponse = JSON.stringify({
130
+ jsonrpc: "2.0",
131
+ id: 1,
132
+ result: "0xa"
133
+ });
176
134
  describe("provider.getBlockNumber", function() {
177
- it("should match ethers.js", /*#__PURE__*/ _asyncToGenerator(function() {
178
- var essentialEthProvider, ethersProvider, _ref, essentialEthBlockNumber, ethersBlockNumber;
135
+ it("should get number integer", /*#__PURE__*/ _asyncToGenerator(function() {
136
+ var essentialEthProvider, essentialEthBlockNumber;
179
137
  return __generator(this, function(_state) {
180
138
  switch(_state.label){
181
139
  case 0:
182
- essentialEthProvider = new JsonRpcProvider(rpcUrl);
183
- ethersProvider = new StaticJsonRpcProvider(rpcUrl);
140
+ essentialEthProvider = new JsonRpcProvider();
141
+ mockOf(unfetch).mockResolvedValueOnce({
142
+ text: function() {
143
+ return Promise.resolve(mockPostResponse);
144
+ }
145
+ });
184
146
  return [
185
147
  4,
186
- Promise.all([
187
- essentialEthProvider.getBlockNumber(),
188
- ethersProvider.getBlockNumber()
189
- ])
148
+ essentialEthProvider.getBlockNumber()
190
149
  ];
191
150
  case 1:
192
- _ref = _slicedToArray.apply(void 0, [
193
- _state.sent(),
194
- 2
195
- ]), essentialEthBlockNumber = _ref[0], ethersBlockNumber = _ref[1];
196
- // allow one-block flexibility because of timing of requests
197
- expect(Math.abs(essentialEthBlockNumber - ethersBlockNumber)).toBeLessThan(2);
198
- return [
199
- 2
200
- ];
201
- }
202
- });
203
- }));
204
- it("should match web3.js", /*#__PURE__*/ _asyncToGenerator(function() {
205
- var essentialEthProvider, web3Provider, _ref, essentialEthBlockNumber, web3BlockNumber;
206
- return __generator(this, function(_state) {
207
- switch(_state.label){
208
- case 0:
209
- essentialEthProvider = new JsonRpcProvider(rpcUrl);
210
- web3Provider = new Web3(rpcUrl);
211
- return [
212
- 4,
213
- Promise.all([
214
- essentialEthProvider.getBlockNumber(),
215
- web3Provider.eth.getBlockNumber()
216
- ])
217
- ];
218
- case 1:
219
- _ref = _slicedToArray.apply(void 0, [
220
- _state.sent(),
221
- 2
222
- ]), essentialEthBlockNumber = _ref[0], web3BlockNumber = _ref[1];
223
- expect(essentialEthBlockNumber).toStrictEqual(web3BlockNumber);
151
+ essentialEthBlockNumber = _state.sent();
152
+ expect(essentialEthBlockNumber).toBe(10);
224
153
  return [
225
154
  2
226
155
  ];
@@ -378,30 +378,6 @@ describe("provider.getBlock", function() {
378
378
  }
379
379
  });
380
380
  }));
381
- it("should match web3.js -- random block as decimal integer & transactions. (block #".concat(blockNumber, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
382
- var _ref, eeRandomBlock, web3RandomBlock;
383
- return __generator(this, function(_state) {
384
- switch(_state.label){
385
- case 0:
386
- return [
387
- 4,
388
- Promise.all([
389
- essentialEthProvider.getBlock(blockNumber, true),
390
- web3Provider.eth.getBlock(blockNumber, true)
391
- ])
392
- ];
393
- case 1:
394
- _ref = _slicedToArray.apply(void 0, [
395
- _state.sent(),
396
- 2
397
- ]), eeRandomBlock = _ref[0], web3RandomBlock = _ref[1];
398
- testBlockEquality(eeRandomBlock, web3RandomBlock);
399
- return [
400
- 2
401
- ];
402
- }
403
- });
404
- }));
405
381
  var blockHash = "0x4cbaa942e48a91108f38e2a250f6dbaff7fffe3027f5ebf76701929eed2b2970"; // Hash corresponds to block on RSK Mainnet
406
382
  it("should match ethers.js -- block by hash. (hash = ".concat(blockHash, ")"), /*#__PURE__*/ _asyncToGenerator(function() {
407
383
  var _ref, eeBlockByHash, ethersBlockByHash;
@@ -1,11 +1,3 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithHoles(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
2
  try {
11
3
  var info = gen[key](arg);
@@ -35,44 +27,6 @@ function _asyncToGenerator(fn) {
35
27
  });
36
28
  };
37
29
  }
38
- function _iterableToArrayLimit(arr, i) {
39
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
- if (_i == null) return;
41
- var _arr = [];
42
- var _n = true;
43
- var _d = false;
44
- var _s, _e;
45
- try {
46
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
47
- _arr.push(_s.value);
48
- if (i && _arr.length === i) break;
49
- }
50
- } catch (err) {
51
- _d = true;
52
- _e = err;
53
- } finally{
54
- try {
55
- if (!_n && _i["return"] != null) _i["return"]();
56
- } finally{
57
- if (_d) throw _e;
58
- }
59
- }
60
- return _arr;
61
- }
62
- function _nonIterableRest() {
63
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
- }
65
- function _slicedToArray(arr, i) {
66
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
67
- }
68
- function _unsupportedIterableToArray(o, minLen) {
69
- if (!o) return;
70
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
71
- var n = Object.prototype.toString.call(o).slice(8, -1);
72
- if (n === "Object" && o.constructor) n = o.constructor.name;
73
- if (n === "Map" || n === "Set") return Array.from(n);
74
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
75
- }
76
30
  var __generator = this && this.__generator || function(thisArg, body) {
77
31
  var f, y, t, g, _ = {
78
32
  label: 0,
@@ -168,31 +122,39 @@ var __generator = this && this.__generator || function(thisArg, body) {
168
122
  };
169
123
  }
170
124
  };
171
- import { ethers } from "ethers";
125
+ import unfetch from "isomorphic-unfetch";
126
+ import z from "zod";
172
127
  import { JsonRpcProvider } from "../../../index";
128
+ import { mockOf } from "../mock-of";
173
129
  import { rpcUrls } from "../rpc-urls";
130
+ import { TinyBig } from "./../../../shared/tiny-big/tiny-big";
131
+ jest.mock("isomorphic-unfetch");
132
+ var mockPostResponse = JSON.stringify({
133
+ jsonrpc: "2.0",
134
+ id: 1,
135
+ result: "0xa"
136
+ });
174
137
  var rpcUrl = rpcUrls.mainnet;
175
138
  describe("provider.getGasPrice", function() {
176
- it("should match ethers and essential-eth", /*#__PURE__*/ _asyncToGenerator(function() {
177
- var ethersProvider, essentialEthProvider, _ref, ethersGasPrice, essentialEthGasPrice;
139
+ it("should get TinyBig integer", /*#__PURE__*/ _asyncToGenerator(function() {
140
+ var provider, gasPrice;
178
141
  return __generator(this, function(_state) {
179
142
  switch(_state.label){
180
143
  case 0:
181
- ethersProvider = new ethers.providers.StaticJsonRpcProvider(rpcUrl);
182
- essentialEthProvider = new JsonRpcProvider(rpcUrl);
144
+ provider = new JsonRpcProvider(rpcUrl);
145
+ mockOf(unfetch).mockResolvedValueOnce({
146
+ text: function() {
147
+ return Promise.resolve(mockPostResponse);
148
+ }
149
+ });
183
150
  return [
184
151
  4,
185
- Promise.all([
186
- ethersProvider.getGasPrice(),
187
- essentialEthProvider.getGasPrice()
188
- ])
152
+ provider.getGasPrice()
189
153
  ];
190
154
  case 1:
191
- _ref = _slicedToArray.apply(void 0, [
192
- _state.sent(),
193
- 2
194
- ]), ethersGasPrice = _ref[0], essentialEthGasPrice = _ref[1];
195
- expect(ethersGasPrice.sub(essentialEthGasPrice.toString()).toNumber()).toBeLessThan(100);
155
+ gasPrice = _state.sent();
156
+ expect(z.instanceof(TinyBig).safeParse(gasPrice).success).toBe(true);
157
+ expect(gasPrice.toString()).toBe("10");
196
158
  return [
197
159
  2
198
160
  ];
@@ -0,0 +1,2 @@
1
+ /// <reference types="jest" />
2
+ export declare const mockOf: <FunctionParameters extends unknown[], FunctionReturnType>(fn: (...args: FunctionParameters) => FunctionReturnType) => jest.Mock<FunctionReturnType, FunctionParameters>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Helper function for mocking other functions.
3
+ *
4
+ * Import it using this:
5
+ * ```ts
6
+ * import { mockOf } from '@earnifi/shared/src/utils/testing/mock-of';
7
+ * ```
8
+ *
9
+ * @param fn
10
+ * @example mockOf(stripe.checkout.sessions.create).mockResolvedValue(mockSession);
11
+ * @see https://twitter.com/scastiel/status/1631354119192473601?s=20
12
+ */ export var mockOf = function(fn) {
13
+ return fn;
14
+ };
@@ -1,11 +1,16 @@
1
+ import z from "zod";
1
2
  export var fakeUrls = {
2
3
  notRPCButRealHttp: "https://httpstat.us/200"
3
4
  };
5
+ var RPC_ORIGIN = process.env.RPC_ORIGIN;
6
+ if (!z.string().url().safeParse(RPC_ORIGIN).success) {
7
+ throw new Error("RPC_ORIGIN is not defined or is invalid URL");
8
+ }
4
9
  export var rpcUrls = {
5
- mainnet: "".concat(process.env.RPC_ORIGIN, "/api/eth"),
6
- matic: "".concat(process.env.RPC_ORIGIN, "/api/MATIC"),
7
- gno: "".concat(process.env.RPC_ORIGIN, "/api/gno"),
8
- bnb: "".concat(process.env.RPC_ORIGIN, "/api/bnb"),
9
- arb1: "".concat(process.env.RPC_ORIGIN, "/api/arb1"),
10
- gor: "".concat(process.env.RPC_ORIGIN, "/api/gor")
10
+ mainnet: "".concat(RPC_ORIGIN, "/api/eth"),
11
+ matic: "".concat(RPC_ORIGIN, "/api/MATIC"),
12
+ gno: "".concat(RPC_ORIGIN, "/api/gno"),
13
+ bnb: "".concat(RPC_ORIGIN, "/api/bnb"),
14
+ arb1: "".concat(RPC_ORIGIN, "/api/arb1"),
15
+ gor: "".concat(RPC_ORIGIN, "/api/gor")
11
16
  };
@@ -0,0 +1,151 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import { z } from "zod";
126
+ import { AlchemyProvider, TinyBig } from "../../index";
127
+ var ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY;
128
+ if (!ALCHEMY_API_KEY) {
129
+ throw new Error("ALCHEMY_API_KEY is not defined in the environment variables.");
130
+ }
131
+ var provider = new AlchemyProvider(ALCHEMY_API_KEY);
132
+ describe("alchemyProvider.getGasPrice", function() {
133
+ it("should return the current gas price", /*#__PURE__*/ _asyncToGenerator(function() {
134
+ var gasPrice;
135
+ return __generator(this, function(_state) {
136
+ switch(_state.label){
137
+ case 0:
138
+ return [
139
+ 4,
140
+ provider.getGasPrice()
141
+ ];
142
+ case 1:
143
+ gasPrice = _state.sent();
144
+ expect(z.instanceof(TinyBig).safeParse(gasPrice).success).toBe(true);
145
+ return [
146
+ 2
147
+ ];
148
+ }
149
+ });
150
+ }));
151
+ });
@@ -1,4 +1,5 @@
1
1
  import { BaseContract, Contract } from './classes/Contract';
2
+ import { AlchemyProvider } from './providers/AlchemyProvider';
2
3
  import { ConstructorOptions, FallthroughProvider } from './providers/FallthroughProvider';
3
4
  import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
4
5
  import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
@@ -22,4 +23,4 @@ export * from './utils/bytes';
22
23
  export * from './utils/hash-message';
23
24
  export * from './utils/keccak256';
24
25
  export * from './utils/solidity-keccak256';
25
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, Filter, FilterByBlockHash, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
26
+ export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, AlchemyProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, Filter, FilterByBlockHash, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BaseContract, Contract } from './classes/Contract';
2
+ import { AlchemyProvider } from './providers/AlchemyProvider';
2
3
  import { FallthroughProvider, } from './providers/FallthroughProvider';
3
4
  import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
4
5
  import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
@@ -17,4 +18,4 @@ export * from './utils/bytes';
17
18
  export * from './utils/hash-message';
18
19
  export * from './utils/keccak256';
19
20
  export * from './utils/solidity-keccak256';
20
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, };
21
+ export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, AlchemyProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, };
@@ -1 +1 @@
1
- export declare const version = "0.8.0";
1
+ export declare const version = "0.9.0";
@@ -1 +1 @@
1
- export const version = '0.8.0';
1
+ export const version = '0.9.0';
@@ -0,0 +1,4 @@
1
+ import { JsonRpcProvider } from './JsonRpcProvider';
2
+ export declare class AlchemyProvider extends JsonRpcProvider {
3
+ constructor(apiKey: string, network?: string);
4
+ }
@@ -0,0 +1,7 @@
1
+ import { JsonRpcProvider } from './JsonRpcProvider';
2
+ export class AlchemyProvider extends JsonRpcProvider {
3
+ constructor(apiKey, network = 'mainnet') {
4
+ const alchemyUrl = `https://eth-${network}.alchemyapi.io/v2/${apiKey}`;
5
+ super(alchemyUrl);
6
+ }
7
+ }