@@ -11,6 +11,7 @@ import { QuickNodeProvider } from "./provider-quicknode.js";
11
11
12
12
import { FallbackProvider } from "./provider-fallback.js" ;
13
13
import { JsonRpcProvider } from "./provider-jsonrpc.js" ;
14
+ import { Network } from "./network.js" ;
14
15
import { WebSocketProvider } from "./provider-websocket.js" ;
15
16
16
17
import type { AbstractProvider } from "./abstract-provider.js" ;
@@ -22,6 +23,8 @@ function isWebSocketLike(value: any): value is WebSocketLike {
22
23
typeof ( value . close ) === "function" ) ;
23
24
}
24
25
26
+ const Testnets = "goerli kovan sepolia classicKotti optimism-goerli arbitrum-goerli matic-mumbai bnbt" . split ( " " ) ;
27
+
25
28
export function getDefaultProvider ( network : string | Networkish | WebSocketLike , options ?: any ) : AbstractProvider {
26
29
if ( options == null ) { options = { } ; }
27
30
@@ -33,6 +36,13 @@ export function getDefaultProvider(network: string | Networkish | WebSocketLike,
33
36
return new WebSocketProvider ( network ) ;
34
37
}
35
38
39
+ // Get the network name, if possible
40
+ let name : null | string = null ;
41
+ try {
42
+ name = Network . from ( network ) . name ;
43
+ } catch ( error ) { }
44
+
45
+
36
46
const providers : Array < AbstractProvider > = [ ] ;
37
47
38
48
if ( options . alchemy !== "-" ) {
@@ -96,7 +106,19 @@ export function getDefaultProvider(network: string | Networkish | WebSocketLike,
96
106
operation : "getDefaultProvider"
97
107
} ) ;
98
108
109
+ // No need for a FallbackProvider
99
110
if ( providers . length === 1 ) { return providers [ 0 ] ; }
100
111
101
- return new FallbackProvider ( providers ) ;
112
+ // We use the floor because public third-party providers can be unreliable,
113
+ // so a low number of providers with a large quorum will fail too often
114
+ let quorum = Math . floor ( providers . length / 2 ) ;
115
+
116
+ // Testnets don't need as strong a security gaurantee and speed is
117
+ // more useful during testing
118
+ if ( name && Testnets . indexOf ( name ) !== - 1 ) { quorum = 1 ; }
119
+
120
+ // Provided override qorum takes priority
121
+ if ( options && options . quorum ) { quorum = options . quorum ; }
122
+
123
+ return new FallbackProvider ( providers , undefined , { quorum } ) ;
102
124
}
0 commit comments