@atomiqlabs/chain-evm 1.0.0-dev.42 → 1.0.0-dev.44

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.
@@ -0,0 +1,15 @@
1
+ import { JsonRpcProvider, JsonRpcApiProviderOptions } from "ethers";
2
+ import type { Networkish, FetchRequest } from "ethers";
3
+ export declare class JsonRpcProviderWithRetries extends JsonRpcProvider {
4
+ readonly retryPolicy?: {
5
+ maxRetries?: number;
6
+ delay?: number;
7
+ exponential?: boolean;
8
+ };
9
+ constructor(url?: string | FetchRequest, network?: Networkish, options?: JsonRpcApiProviderOptions & {
10
+ maxRetries?: number;
11
+ delay?: number;
12
+ exponential?: boolean;
13
+ });
14
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
15
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonRpcProviderWithRetries = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const Utils_1 = require("../utils/Utils");
6
+ class JsonRpcProviderWithRetries extends ethers_1.JsonRpcProvider {
7
+ constructor(url, network, options) {
8
+ super(url, network, options);
9
+ this.retryPolicy = options;
10
+ }
11
+ send(method, params) {
12
+ return (0, Utils_1.tryWithRetries)(() => super.send(method, params), this.retryPolicy, e => {
13
+ if (e?.error?.code != null)
14
+ return false; //Error returned by the RPC
15
+ return true;
16
+ });
17
+ }
18
+ }
19
+ exports.JsonRpcProviderWithRetries = JsonRpcProviderWithRetries;
@@ -198,7 +198,7 @@ class EVMTransactions extends EVMModule_1.EVMModule {
198
198
  this.root.config.safeBlockTag === "latest" ? Promise.resolve(null) : this.provider.getBlock(this.root.config.safeBlockTag).then(res => res.number),
199
199
  this.provider.getTransactionReceipt(txId)
200
200
  ]);
201
- if (txReceipt == null || (safeBlockNumber != null && txReceipt.blockNumber < safeBlockNumber))
201
+ if (txReceipt == null || (safeBlockNumber != null && txReceipt.blockNumber > safeBlockNumber))
202
202
  return "pending";
203
203
  if (txReceipt.status === 0)
204
204
  return "reverted";
package/dist/index.d.ts CHANGED
@@ -38,3 +38,4 @@ export * from "./chains/citrea/CitreaChainType";
38
38
  export * from "./chains/citrea/CitreaFees";
39
39
  export * from "./chains/botanix/BotanixInitializer";
40
40
  export * from "./chains/botanix/BotanixChainType";
41
+ export * from "./evm/JsonRpcProviderWithRetries";
package/dist/index.js CHANGED
@@ -54,3 +54,4 @@ __exportStar(require("./chains/citrea/CitreaChainType"), exports);
54
54
  __exportStar(require("./chains/citrea/CitreaFees"), exports);
55
55
  __exportStar(require("./chains/botanix/BotanixInitializer"), exports);
56
56
  __exportStar(require("./chains/botanix/BotanixChainType"), exports);
57
+ __exportStar(require("./evm/JsonRpcProviderWithRetries"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-evm",
3
- "version": "1.0.0-dev.42",
3
+ "version": "1.0.0-dev.44",
4
4
  "description": "EVM specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -0,0 +1,26 @@
1
+ import {JsonRpcProvider, JsonRpcApiProviderOptions} from "ethers";
2
+ import type {Networkish, FetchRequest} from "ethers";
3
+ import {tryWithRetries} from "../utils/Utils";
4
+
5
+
6
+ export class JsonRpcProviderWithRetries extends JsonRpcProvider {
7
+
8
+ readonly retryPolicy?: {
9
+ maxRetries?: number, delay?: number, exponential?: boolean
10
+ };
11
+
12
+ constructor(url?: string | FetchRequest, network?: Networkish, options?: JsonRpcApiProviderOptions & {
13
+ maxRetries?: number, delay?: number, exponential?: boolean
14
+ }) {
15
+ super(url, network, options);
16
+ this.retryPolicy = options;
17
+ }
18
+
19
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any> {
20
+ return tryWithRetries(() => super.send(method, params), this.retryPolicy, e => {
21
+ if(e?.error?.code!=null) return false; //Error returned by the RPC
22
+ return true;
23
+ });
24
+ }
25
+
26
+ }
@@ -222,7 +222,7 @@ export class EVMTransactions extends EVMModule<any> {
222
222
  this.provider.getTransactionReceipt(txId)
223
223
  ]);
224
224
 
225
- if(txReceipt==null || (safeBlockNumber!=null && txReceipt.blockNumber < safeBlockNumber)) return "pending";
225
+ if(txReceipt==null || (safeBlockNumber!=null && txReceipt.blockNumber > safeBlockNumber)) return "pending";
226
226
  if(txReceipt.status===0) return "reverted";
227
227
  return "success";
228
228
  }
package/src/index.ts CHANGED
@@ -46,3 +46,5 @@ export * from "./chains/citrea/CitreaFees";
46
46
 
47
47
  export * from "./chains/botanix/BotanixInitializer";
48
48
  export * from "./chains/botanix/BotanixChainType";
49
+
50
+ export * from "./evm/JsonRpcProviderWithRetries";