ethers-rpc-pool 1.0.0 → 1.0.2
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/README.md +1 -0
- package/dist/index.cjs +178 -17371
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -66
- package/dist/index.d.ts +75 -66
- package/dist/index.js +175 -17354
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,44 +1,69 @@
|
|
|
1
|
-
import { JsonRpcProvider
|
|
2
|
-
|
|
3
|
-
declare class Semaphore {
|
|
4
|
-
private readonly max;
|
|
5
|
-
private inUse;
|
|
6
|
-
private queue;
|
|
7
|
-
constructor(max: number);
|
|
8
|
-
acquire(): Promise<() => void>;
|
|
9
|
-
private release;
|
|
10
|
-
}
|
|
1
|
+
import { JsonRpcProvider } from 'ethers';
|
|
11
2
|
|
|
12
3
|
interface RpcStatsSnapshot {
|
|
13
4
|
total: number;
|
|
14
5
|
inFlight: number;
|
|
15
|
-
|
|
6
|
+
perMethodTotal: Record<string, number>;
|
|
16
7
|
rateLimitedTotal: number;
|
|
17
|
-
|
|
8
|
+
perProviderRateLimited: Record<string, number>;
|
|
18
9
|
timeoutTotal: number;
|
|
19
|
-
|
|
10
|
+
perProviderTimeout: Record<string, number>;
|
|
20
11
|
perProviderTotal: Record<string, number>;
|
|
21
|
-
perProviderTimeouts: Record<string, number>;
|
|
22
12
|
providerCooldownUntil: Record<string, number>;
|
|
13
|
+
perProviderInFlight: Record<string, number>;
|
|
23
14
|
}
|
|
24
|
-
declare class
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
declare class Stats {
|
|
16
|
+
private _total;
|
|
17
|
+
private _inFlight;
|
|
18
|
+
private _perMethod;
|
|
19
|
+
private _rateLimitedTotal;
|
|
20
|
+
private _timeoutTotal;
|
|
21
|
+
private _perProviderInFlight;
|
|
22
|
+
private _perProviderTotal;
|
|
23
|
+
private _perProviderTimeout;
|
|
24
|
+
private _perProviderRateLimited;
|
|
25
|
+
private _providerCooldownUntil;
|
|
26
|
+
private _bump;
|
|
27
|
+
private _decrease;
|
|
28
|
+
private _bumpTotal;
|
|
29
|
+
private _bumpInFlight;
|
|
30
|
+
private _bumpRateLimitedTotal;
|
|
31
|
+
private _bumpTimeoutTotal;
|
|
32
|
+
bumpInFlightPerProvider(id: string): void;
|
|
33
|
+
decreaseInFlightPerProvider(id: string): void;
|
|
34
|
+
decreaseInFlight(): void;
|
|
35
|
+
bumpPerMethod(method: string): void;
|
|
36
|
+
bumpRateLimitedPerProvider(id: string): void;
|
|
37
|
+
bumpTimeoutPerProvider(id: string): void;
|
|
36
38
|
bumpProviderTotal(id: string): void;
|
|
37
|
-
bumpProviderTimeout(id: string): void;
|
|
38
39
|
timeoutRatio(id: string): number;
|
|
39
40
|
isInCooldown(id: string): boolean;
|
|
40
41
|
setCooldown(id: string, ms: number): void;
|
|
41
|
-
snapshot(): RpcStatsSnapshot
|
|
42
|
+
snapshot(): Readonly<RpcStatsSnapshot>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class Semaphore {
|
|
46
|
+
private readonly max;
|
|
47
|
+
private inUse;
|
|
48
|
+
private queue;
|
|
49
|
+
constructor(max: number);
|
|
50
|
+
acquire(): Promise<() => void>;
|
|
51
|
+
private release;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Instrumented StaticJsonRpcProvider.
|
|
56
|
+
* Tracks requests, inFlight count, rate limits, and per-method / per-provider metrics.
|
|
57
|
+
*/
|
|
58
|
+
declare class InstrumentedStaticJsonRpcProvider extends JsonRpcProvider {
|
|
59
|
+
private readonly stats;
|
|
60
|
+
private readonly limiter;
|
|
61
|
+
private readonly onEvent?;
|
|
62
|
+
readonly providerId: string;
|
|
63
|
+
readonly chainId: number;
|
|
64
|
+
constructor(url: string, chainId: number, providerId: string, stats: Stats, limiter: Semaphore, onEvent?: ((e: RpcEvent) => void) | undefined);
|
|
65
|
+
send(method: string, params: any): Promise<any>;
|
|
66
|
+
private _sendInstrumented;
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
interface Endpoint {
|
|
@@ -75,52 +100,36 @@ type RpcEvent = {
|
|
|
75
100
|
code?: string;
|
|
76
101
|
message: string;
|
|
77
102
|
};
|
|
78
|
-
declare function getHttpStatus(e: any): number | undefined;
|
|
79
|
-
declare function isRateLimitError(e: any): boolean;
|
|
80
|
-
declare function getRetryAfterMs(e: any): number | null;
|
|
81
|
-
declare function isTimeoutError(e: any): boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Wraps a promise with a timeout (useful when an RPC hangs without emitting TIMEOUT).
|
|
84
|
-
* Important: this does not cancel the network request, but you get a controlled error
|
|
85
|
-
* and FallbackProvider can switch to another RPC.
|
|
86
|
-
*/
|
|
87
|
-
declare function withTimeout<T>(p: Promise<T>, ms: number, meta?: {
|
|
88
|
-
chainId?: number;
|
|
89
|
-
providerId?: string;
|
|
90
|
-
method?: string;
|
|
91
|
-
}): Promise<T>;
|
|
92
|
-
declare function shouldFailover(e: any): boolean;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Instrumented StaticJsonRpcProvider.
|
|
96
|
-
* Tracks requests, inFlight count, rate limits, and per-method / per-provider metrics.
|
|
97
|
-
*/
|
|
98
|
-
declare class InstrumentedStaticJsonRpcProvider extends JsonRpcProvider {
|
|
99
|
-
private readonly stats;
|
|
100
|
-
private readonly limiter;
|
|
101
|
-
private readonly onEvent?;
|
|
102
|
-
readonly providerId: string;
|
|
103
|
-
readonly chainId: number;
|
|
104
|
-
constructor(url: string, chainId: number, providerId: string, stats: RPCStats, limiter: Semaphore, onEvent?: ((e: RpcEvent) => void) | undefined);
|
|
105
|
-
send(method: string, params: any): Promise<any>;
|
|
106
|
-
private _sendInstrumented;
|
|
107
|
-
}
|
|
108
103
|
|
|
109
|
-
declare class
|
|
104
|
+
declare class Router {
|
|
110
105
|
private readonly endpoints;
|
|
111
106
|
private readonly stats;
|
|
112
107
|
private rr;
|
|
113
|
-
constructor(endpoints: Endpoint[], stats:
|
|
108
|
+
constructor(endpoints: Endpoint[], stats: Stats);
|
|
114
109
|
size(): number;
|
|
115
110
|
pick(): Endpoint;
|
|
116
111
|
}
|
|
117
112
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
interface RPCPoolProviderParams {
|
|
114
|
+
chainId: number;
|
|
115
|
+
urls: string[];
|
|
116
|
+
perUrl: {
|
|
117
|
+
inFlight: number;
|
|
118
|
+
};
|
|
119
|
+
retry: {
|
|
120
|
+
attempts: number;
|
|
121
|
+
};
|
|
122
|
+
hooks?: {
|
|
123
|
+
onEvent(e: RpcEvent): void;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
declare class RPCPoolProvider extends JsonRpcProvider {
|
|
127
|
+
readonly router: Router;
|
|
128
|
+
readonly params: RPCPoolProviderParams;
|
|
129
|
+
readonly stats: Stats;
|
|
130
|
+
constructor(params: RPCPoolProviderParams);
|
|
123
131
|
send(method: string, params: any): Promise<any>;
|
|
132
|
+
getStats(): Stats;
|
|
124
133
|
}
|
|
125
134
|
|
|
126
|
-
export {
|
|
135
|
+
export { RPCPoolProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,44 +1,69 @@
|
|
|
1
|
-
import { JsonRpcProvider
|
|
2
|
-
|
|
3
|
-
declare class Semaphore {
|
|
4
|
-
private readonly max;
|
|
5
|
-
private inUse;
|
|
6
|
-
private queue;
|
|
7
|
-
constructor(max: number);
|
|
8
|
-
acquire(): Promise<() => void>;
|
|
9
|
-
private release;
|
|
10
|
-
}
|
|
1
|
+
import { JsonRpcProvider } from 'ethers';
|
|
11
2
|
|
|
12
3
|
interface RpcStatsSnapshot {
|
|
13
4
|
total: number;
|
|
14
5
|
inFlight: number;
|
|
15
|
-
|
|
6
|
+
perMethodTotal: Record<string, number>;
|
|
16
7
|
rateLimitedTotal: number;
|
|
17
|
-
|
|
8
|
+
perProviderRateLimited: Record<string, number>;
|
|
18
9
|
timeoutTotal: number;
|
|
19
|
-
|
|
10
|
+
perProviderTimeout: Record<string, number>;
|
|
20
11
|
perProviderTotal: Record<string, number>;
|
|
21
|
-
perProviderTimeouts: Record<string, number>;
|
|
22
12
|
providerCooldownUntil: Record<string, number>;
|
|
13
|
+
perProviderInFlight: Record<string, number>;
|
|
23
14
|
}
|
|
24
|
-
declare class
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
15
|
+
declare class Stats {
|
|
16
|
+
private _total;
|
|
17
|
+
private _inFlight;
|
|
18
|
+
private _perMethod;
|
|
19
|
+
private _rateLimitedTotal;
|
|
20
|
+
private _timeoutTotal;
|
|
21
|
+
private _perProviderInFlight;
|
|
22
|
+
private _perProviderTotal;
|
|
23
|
+
private _perProviderTimeout;
|
|
24
|
+
private _perProviderRateLimited;
|
|
25
|
+
private _providerCooldownUntil;
|
|
26
|
+
private _bump;
|
|
27
|
+
private _decrease;
|
|
28
|
+
private _bumpTotal;
|
|
29
|
+
private _bumpInFlight;
|
|
30
|
+
private _bumpRateLimitedTotal;
|
|
31
|
+
private _bumpTimeoutTotal;
|
|
32
|
+
bumpInFlightPerProvider(id: string): void;
|
|
33
|
+
decreaseInFlightPerProvider(id: string): void;
|
|
34
|
+
decreaseInFlight(): void;
|
|
35
|
+
bumpPerMethod(method: string): void;
|
|
36
|
+
bumpRateLimitedPerProvider(id: string): void;
|
|
37
|
+
bumpTimeoutPerProvider(id: string): void;
|
|
36
38
|
bumpProviderTotal(id: string): void;
|
|
37
|
-
bumpProviderTimeout(id: string): void;
|
|
38
39
|
timeoutRatio(id: string): number;
|
|
39
40
|
isInCooldown(id: string): boolean;
|
|
40
41
|
setCooldown(id: string, ms: number): void;
|
|
41
|
-
snapshot(): RpcStatsSnapshot
|
|
42
|
+
snapshot(): Readonly<RpcStatsSnapshot>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class Semaphore {
|
|
46
|
+
private readonly max;
|
|
47
|
+
private inUse;
|
|
48
|
+
private queue;
|
|
49
|
+
constructor(max: number);
|
|
50
|
+
acquire(): Promise<() => void>;
|
|
51
|
+
private release;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Instrumented StaticJsonRpcProvider.
|
|
56
|
+
* Tracks requests, inFlight count, rate limits, and per-method / per-provider metrics.
|
|
57
|
+
*/
|
|
58
|
+
declare class InstrumentedStaticJsonRpcProvider extends JsonRpcProvider {
|
|
59
|
+
private readonly stats;
|
|
60
|
+
private readonly limiter;
|
|
61
|
+
private readonly onEvent?;
|
|
62
|
+
readonly providerId: string;
|
|
63
|
+
readonly chainId: number;
|
|
64
|
+
constructor(url: string, chainId: number, providerId: string, stats: Stats, limiter: Semaphore, onEvent?: ((e: RpcEvent) => void) | undefined);
|
|
65
|
+
send(method: string, params: any): Promise<any>;
|
|
66
|
+
private _sendInstrumented;
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
interface Endpoint {
|
|
@@ -75,52 +100,36 @@ type RpcEvent = {
|
|
|
75
100
|
code?: string;
|
|
76
101
|
message: string;
|
|
77
102
|
};
|
|
78
|
-
declare function getHttpStatus(e: any): number | undefined;
|
|
79
|
-
declare function isRateLimitError(e: any): boolean;
|
|
80
|
-
declare function getRetryAfterMs(e: any): number | null;
|
|
81
|
-
declare function isTimeoutError(e: any): boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Wraps a promise with a timeout (useful when an RPC hangs without emitting TIMEOUT).
|
|
84
|
-
* Important: this does not cancel the network request, but you get a controlled error
|
|
85
|
-
* and FallbackProvider can switch to another RPC.
|
|
86
|
-
*/
|
|
87
|
-
declare function withTimeout<T>(p: Promise<T>, ms: number, meta?: {
|
|
88
|
-
chainId?: number;
|
|
89
|
-
providerId?: string;
|
|
90
|
-
method?: string;
|
|
91
|
-
}): Promise<T>;
|
|
92
|
-
declare function shouldFailover(e: any): boolean;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Instrumented StaticJsonRpcProvider.
|
|
96
|
-
* Tracks requests, inFlight count, rate limits, and per-method / per-provider metrics.
|
|
97
|
-
*/
|
|
98
|
-
declare class InstrumentedStaticJsonRpcProvider extends JsonRpcProvider {
|
|
99
|
-
private readonly stats;
|
|
100
|
-
private readonly limiter;
|
|
101
|
-
private readonly onEvent?;
|
|
102
|
-
readonly providerId: string;
|
|
103
|
-
readonly chainId: number;
|
|
104
|
-
constructor(url: string, chainId: number, providerId: string, stats: RPCStats, limiter: Semaphore, onEvent?: ((e: RpcEvent) => void) | undefined);
|
|
105
|
-
send(method: string, params: any): Promise<any>;
|
|
106
|
-
private _sendInstrumented;
|
|
107
|
-
}
|
|
108
103
|
|
|
109
|
-
declare class
|
|
104
|
+
declare class Router {
|
|
110
105
|
private readonly endpoints;
|
|
111
106
|
private readonly stats;
|
|
112
107
|
private rr;
|
|
113
|
-
constructor(endpoints: Endpoint[], stats:
|
|
108
|
+
constructor(endpoints: Endpoint[], stats: Stats);
|
|
114
109
|
size(): number;
|
|
115
110
|
pick(): Endpoint;
|
|
116
111
|
}
|
|
117
112
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
113
|
+
interface RPCPoolProviderParams {
|
|
114
|
+
chainId: number;
|
|
115
|
+
urls: string[];
|
|
116
|
+
perUrl: {
|
|
117
|
+
inFlight: number;
|
|
118
|
+
};
|
|
119
|
+
retry: {
|
|
120
|
+
attempts: number;
|
|
121
|
+
};
|
|
122
|
+
hooks?: {
|
|
123
|
+
onEvent(e: RpcEvent): void;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
declare class RPCPoolProvider extends JsonRpcProvider {
|
|
127
|
+
readonly router: Router;
|
|
128
|
+
readonly params: RPCPoolProviderParams;
|
|
129
|
+
readonly stats: Stats;
|
|
130
|
+
constructor(params: RPCPoolProviderParams);
|
|
123
131
|
send(method: string, params: any): Promise<any>;
|
|
132
|
+
getStats(): Stats;
|
|
124
133
|
}
|
|
125
134
|
|
|
126
|
-
export {
|
|
135
|
+
export { RPCPoolProvider };
|