@0xsequence/provider 1.1.1 → 1.1.3

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/src/client.ts CHANGED
@@ -1,10 +1,23 @@
1
- import { JsonRpcRequest, JsonRpcResponse, NetworkConfig } from "@0xsequence/network"
2
- import { ConnectDetails, ConnectOptions, ItemStore, MuxMessageProvider, MuxTransportTemplate, OpenWalletIntent, OptionalChainId, OptionalEIP6492, ProviderTransport, WalletEventTypes, WalletSession, isMuxTransportTemplate, isProviderTransport } from "."
3
- import { commons } from "@0xsequence/core"
4
- import { TypedData } from "@0xsequence/utils"
5
- import { toExtended } from "./extended"
6
- import { ethers } from "ethers"
7
-
1
+ import { JsonRpcRequest, JsonRpcResponse, NetworkConfig } from '@0xsequence/network'
2
+ import {
3
+ ConnectDetails,
4
+ ConnectOptions,
5
+ ItemStore,
6
+ MuxMessageProvider,
7
+ MuxTransportTemplate,
8
+ OpenWalletIntent,
9
+ OptionalChainId,
10
+ OptionalEIP6492,
11
+ ProviderTransport,
12
+ WalletEventTypes,
13
+ WalletSession,
14
+ isMuxTransportTemplate,
15
+ isProviderTransport
16
+ } from '.'
17
+ import { commons } from '@0xsequence/core'
18
+ import { TypedData } from '@0xsequence/utils'
19
+ import { toExtended } from './extended'
20
+ import { ethers } from 'ethers'
8
21
 
9
22
  /**
10
23
  * This session class is meant to persist the state of the wallet connection
@@ -14,19 +27,12 @@ import { ethers } from "ethers"
14
27
  export class SequenceClientSession {
15
28
  static readonly SESSION_LOCALSTORE_KEY = '@sequence.session'
16
29
 
17
- constructor (
18
- private store: ItemStore
19
- ) {}
30
+ constructor(private store: ItemStore) {}
20
31
 
21
32
  connectedSession(): Required<WalletSession> {
22
33
  const session = this.getSession()
23
34
 
24
- if (
25
- session &&
26
- session.accountAddress &&
27
- session.walletContext &&
28
- session.networks
29
- ) {
35
+ if (session && session.accountAddress && session.walletContext && session.networks) {
30
36
  return {
31
37
  accountAddress: session.accountAddress!,
32
38
  walletContext: session.walletContext!,
@@ -41,7 +47,7 @@ export class SequenceClientSession {
41
47
  return this.getSession()?.accountAddress !== undefined
42
48
  }
43
49
 
44
- setSession(session: WalletSession) {
50
+ setSession(session: WalletSession) {
45
51
  return this.store.setItem(SequenceClientSession.SESSION_LOCALSTORE_KEY, JSON.stringify(session))
46
52
  }
47
53
 
@@ -109,21 +115,17 @@ export class DefaultChainIdTracker {
109
115
  /**
110
116
  * This is a wallet client for sequence wallet-webapp. It connects using *some* transport
111
117
  * and it allows to perform all sequence specific (or write) operations related to the wallet.
112
- *
118
+ *
113
119
  * It doesn't implement a full ethereum Provider, it doesn't include read-only methods.
114
120
  */
115
- export class SequenceClient {
121
+ export class SequenceClient {
116
122
  private readonly session: SequenceClientSession
117
123
  private readonly defaultChainId: DefaultChainIdTracker
118
124
  private readonly callbacks: { [K in keyof WalletEventTypes]?: WalletEventTypes[K][] } = {}
119
125
 
120
126
  public readonly transport: ProviderTransport
121
127
 
122
- constructor (
123
- transport: ProviderTransport | MuxTransportTemplate,
124
- store: ItemStore,
125
- defaultChainId?: number
126
- ) {
128
+ constructor(transport: ProviderTransport | MuxTransportTemplate, store: ItemStore, defaultChainId?: number) {
127
129
  if (isMuxTransportTemplate(transport)) {
128
130
  this.transport = MuxMessageProvider.new(transport)
129
131
  } else if (isProviderTransport(transport)) {
@@ -144,39 +146,41 @@ export class SequenceClient {
144
146
  })
145
147
 
146
148
  this.transport.on('connect', (response: ConnectDetails) => {
147
- const chainIdHex = ethers.BigNumber.from(this.getChainId()).toHexString()
148
- this.callbacks.connect?.forEach(cb => cb({
149
- ...response,
150
- // Ignore the full connect response
151
- // use the chainId defined locally
152
- chainId: chainIdHex
153
- }))
149
+ const chainIdHex = ethers.utils.hexValue(this.getChainId())
150
+ this.callbacks.connect?.forEach(cb =>
151
+ cb({
152
+ ...response,
153
+ // Ignore the full connect response
154
+ // use the chainId defined locally
155
+ chainId: chainIdHex
156
+ })
157
+ )
154
158
  })
155
159
 
156
- this.transport.on('disconnect', (error) => {
160
+ this.transport.on('disconnect', error => {
157
161
  this.callbacks.disconnect?.forEach(cb => cb(error))
158
162
  })
159
163
 
160
- this.transport.on('networks', (networks) => {
164
+ this.transport.on('networks', networks => {
161
165
  this.callbacks.networks?.forEach(cb => cb(networks))
162
166
  })
163
167
 
164
- this.transport.on('walletContext', (context) => {
168
+ this.transport.on('walletContext', context => {
165
169
  this.callbacks.walletContext?.forEach(cb => cb(context))
166
170
  })
167
171
 
168
- this.transport.on('open', (info) => {
172
+ this.transport.on('open', info => {
169
173
  this.callbacks.open?.forEach(cb => cb(info))
170
174
  })
171
175
 
172
176
  this.transport.on('close', () => {
173
177
  this.callbacks.close?.forEach(cb => cb())
174
178
  })
175
-
179
+
176
180
  // We don't listen for the transport chainChanged event
177
181
  // instead we handle it locally, so we listen for changes in the store
178
182
  this.defaultChainId.onDefaultChainIdChanged((chainId: number) => {
179
- const chainIdHex = ethers.BigNumber.from(chainId).toHexString()
183
+ const chainIdHex = ethers.utils.hexValue(chainId)
180
184
  this.callbacks.chainChanged?.forEach(cb => cb(chainIdHex))
181
185
  })
182
186
  }
@@ -187,9 +191,9 @@ export class SequenceClient {
187
191
  if (!this.callbacks[eventName]) {
188
192
  this.callbacks[eventName] = []
189
193
  }
190
-
194
+
191
195
  this.callbacks[eventName]!.push(callback)
192
-
196
+
193
197
  return () => {
194
198
  this.callbacks[eventName] = this.callbacks[eventName]!.filter(c => c !== callback) as any
195
199
  }
@@ -212,7 +216,7 @@ export class SequenceClient {
212
216
  onDisconnect(callback: WalletEventTypes['disconnect']) {
213
217
  return this.registerCallback('disconnect', callback)
214
218
  }
215
-
219
+
216
220
  onNetworks(callback: WalletEventTypes['networks']) {
217
221
  return this.registerCallback('networks', callback)
218
222
  }
@@ -310,7 +314,7 @@ export class SequenceClient {
310
314
  if (!connectDetails.session) {
311
315
  throw new Error('impossible state, connect response is missing session')
312
316
  }
313
-
317
+
314
318
  this.session.setSession(connectDetails.session)
315
319
  }
316
320
 
@@ -331,19 +335,23 @@ export class SequenceClient {
331
335
  // but transport uses it instead of send, so we wrap it
332
336
  send(request: JsonRpcRequest, chainId?: number): Promise<any> {
333
337
  return new Promise((resolve, reject) => {
334
- this.transport.sendAsync(request, (error, response) => {
335
- if (error) {
336
- reject(error)
337
- } else if (response === undefined) {
338
- reject(new Error(`Got undefined response for request: ${request}`))
339
- } else if (typeof response === 'object' && response.error) {
340
- reject(response.error)
341
- } else if (typeof response === 'object' && response.result) {
342
- resolve(response.result)
343
- } else {
344
- reject(new Error(`Got invalid response for request: ${request}`))
345
- }
346
- }, chainId || this.getChainId())
338
+ this.transport.sendAsync(
339
+ request,
340
+ (error, response) => {
341
+ if (error) {
342
+ reject(error)
343
+ } else if (response === undefined) {
344
+ reject(new Error(`Got undefined response for request: ${request}`))
345
+ } else if (typeof response === 'object' && response.error) {
346
+ reject(response.error)
347
+ } else if (typeof response === 'object' && response.result) {
348
+ resolve(response.result)
349
+ } else {
350
+ reject(new Error(`Got invalid response for request: ${request}`))
351
+ }
352
+ },
353
+ chainId || this.getChainId()
354
+ )
347
355
  })
348
356
  }
349
357
 
@@ -358,52 +366,41 @@ export class SequenceClient {
358
366
  return connectedSession.networks
359
367
  }
360
368
 
361
- async signMessage(
362
- message: ethers.BytesLike,
363
- options?: OptionalEIP6492 & OptionalChainId
364
- ): Promise<string> {
369
+ async signMessage(message: ethers.BytesLike, options?: OptionalEIP6492 & OptionalChainId): Promise<string> {
365
370
  const method = options?.eip6492 ? 'sequence_sign' : 'personal_sign'
366
371
 
367
372
  // Address is ignored by the wallet webapp
368
373
  return this.send({ method, params: [message, this.getAddress()] }, options?.chainId)
369
374
  }
370
375
 
371
- async signTypedData(
372
- typedData: TypedData,
373
- options?: OptionalEIP6492 & OptionalChainId
374
- ): Promise<string> {
376
+ async signTypedData(typedData: TypedData, options?: OptionalEIP6492 & OptionalChainId): Promise<string> {
375
377
  const method = options?.eip6492 ? 'sequence_signTypedData_v4' : 'eth_signTypedData_v4'
376
378
 
377
379
  // TODO: Stop using ethers for this, this is the only place where we use it
378
380
  // and it makes the client depend on ethers.
379
- const encoded = ethers.utils._TypedDataEncoder.getPayload(typedData.domain, typedData.types, typedData.message)
381
+ const encoded = ethers.utils._TypedDataEncoder.getPayload(typedData.domain, typedData.types, typedData.message)
380
382
 
381
383
  // The sign typed data will use one of the following chainIds, in order:
382
384
  // - The one provided in the options
383
385
  // - The one provided in the typedData.domain.chainId
384
386
  // - The default chainId
385
387
 
386
- return this.send({ method, params: [this.getAddress(), encoded] }, (
388
+ return this.send(
389
+ { method, params: [this.getAddress(), encoded] },
387
390
  options?.chainId ||
388
- (
389
- typedData.domain.chainId &&
390
- ethers.BigNumber.from(typedData.domain.chainId).toNumber()
391
- ) ||
392
- this.getChainId()
393
- ))
391
+ (typedData.domain.chainId && ethers.BigNumber.from(typedData.domain.chainId).toNumber()) ||
392
+ this.getChainId()
393
+ )
394
394
  }
395
395
 
396
396
  async sendTransaction(
397
- tx: (
398
- ethers.providers.TransactionRequest[] |
399
- ethers.providers.TransactionRequest
400
- ),
397
+ tx: ethers.providers.TransactionRequest[] | ethers.providers.TransactionRequest,
401
398
  options?: OptionalChainId
402
399
  ): Promise<string> {
403
400
  const sequenceTxs = Array.isArray(tx) ? tx : [tx]
404
401
  const extendedTxs = toExtended(sequenceTxs)
405
402
 
406
- return this.send({ method: 'eth_sendTransaction', params: [extendedTxs] }, options?.chainId )
403
+ return this.send({ method: 'eth_sendTransaction', params: [extendedTxs] }, options?.chainId)
407
404
  }
408
405
 
409
406
  async getWalletContext(): Promise<commons.context.VersionedContext> {
@@ -412,7 +409,10 @@ export class SequenceClient {
412
409
 
413
410
  async getOnchainWalletConfig(options?: OptionalChainId): Promise<commons.config.Config> {
414
411
  // NOTICE: sequence_getWalletConfig sends the chainId as a param
415
- const res = await this.send({ method: 'sequence_getWalletConfig', params: [options?.chainId || this.getChainId()] }, options?.chainId)
412
+ const res = await this.send(
413
+ { method: 'sequence_getWalletConfig', params: [options?.chainId || this.getChainId()] },
414
+ options?.chainId
415
+ )
416
416
  return Array.isArray(res) ? res[0] : res
417
417
  }
418
418
 
package/src/extended.ts CHANGED
@@ -1,5 +1,4 @@
1
-
2
- import { ethers } from "ethers"
1
+ import { ethers } from 'ethers'
3
2
 
4
3
  export type ExtendedTransactionRequest = ethers.providers.TransactionRequest & {
5
4
  auxiliary?: ethers.providers.TransactionRequest[]
@@ -7,14 +6,14 @@ export type ExtendedTransactionRequest = ethers.providers.TransactionRequest & {
7
6
 
8
7
  export function toExtended(transactions: ethers.providers.TransactionRequest[]): ExtendedTransactionRequest {
9
8
  if (transactions.length === 0) {
10
- throw new Error("No transaction provided")
9
+ throw new Error('No transaction provided')
11
10
  }
12
11
 
13
12
  const [first, ...rest] = transactions
14
13
 
15
14
  return {
16
15
  ...first,
17
- auxiliary: rest,
16
+ auxiliary: rest
18
17
  }
19
18
  }
20
19
 
package/src/init.ts CHANGED
@@ -1,10 +1,19 @@
1
- import { CachedProvider, ChainIdLike, JsonRpcRouter, JsonRpcSender, NetworkConfig, allNetworks, exceptionProviderMiddleware, findNetworkConfig, loggingProviderMiddleware } from "@0xsequence/network"
2
- import { MuxTransportTemplate } from "./transports"
3
- import { ItemStore, useBestStore } from "./utils"
4
- import { ethers } from "ethers"
5
- import { SequenceClient } from "./client"
6
- import { SequenceProvider } from "./provider"
7
-
1
+ import {
2
+ CachedProvider,
3
+ ChainIdLike,
4
+ JsonRpcRouter,
5
+ JsonRpcSender,
6
+ NetworkConfig,
7
+ allNetworks,
8
+ exceptionProviderMiddleware,
9
+ findNetworkConfig,
10
+ loggingProviderMiddleware
11
+ } from '@0xsequence/network'
12
+ import { MuxTransportTemplate } from './transports'
13
+ import { ItemStore, useBestStore } from './utils'
14
+ import { ethers } from 'ethers'
15
+ import { SequenceClient } from './client'
16
+ import { SequenceProvider } from './provider'
8
17
 
9
18
  export interface ProviderConfig {
10
19
  // The local storage dependency for the wallet provider, defaults to window.localStorage.
@@ -37,14 +46,12 @@ export const DefaultProviderConfig = {
37
46
  proxyTransport: { enabled: false }
38
47
  },
39
48
 
40
- defaultNetwork: 1,
49
+ defaultNetwork: 1
41
50
  }
42
51
 
43
52
  let sequenceWalletProvider: SequenceProvider | undefined
44
53
 
45
- export const initWallet = (
46
- partialConfig?: Partial<ProviderConfig>
47
- ) => {
54
+ export const initWallet = (partialConfig?: Partial<ProviderConfig>) => {
48
55
  if (sequenceWalletProvider) {
49
56
  return sequenceWalletProvider
50
57
  }
@@ -55,7 +62,7 @@ export const initWallet = (
55
62
  ...partialConfig,
56
63
  transports: {
57
64
  ...DefaultProviderConfig.transports,
58
- ...partialConfig?.transports,
65
+ ...partialConfig?.transports
59
66
  }
60
67
  }
61
68
 
@@ -63,37 +70,33 @@ export const initWallet = (
63
70
 
64
71
  // Find any new networks that aren't already defined in sequence.js
65
72
  // and add them to the list of networks, (they must have a rpcUrl and chainId)
66
- const newNetworks = (config.networks?.filter((n) => {
67
- n.rpcUrl !== undefined &&
68
- n.chainId !== undefined &&
69
- !allNetworks.find((an) => an.chainId === n.chainId)
73
+ const newNetworks = (config.networks?.filter(n => {
74
+ n.rpcUrl !== undefined && n.chainId !== undefined && !allNetworks.find(an => an.chainId === n.chainId)
70
75
  }) ?? []) as NetworkConfig[]
71
76
 
72
77
  // Override any information about the networks using the config
73
- const combinedNetworks = allNetworks.map((n) => {
74
- const network = config.networks?.find((cn) => cn.chainId === n.chainId)
75
- return network ? { ...n, ...network } : n
76
- }).concat(newNetworks)
78
+ const combinedNetworks = allNetworks
79
+ .map(n => {
80
+ const network = config.networks?.find(cn => cn.chainId === n.chainId)
81
+ return network ? { ...n, ...network } : n
82
+ })
83
+ .concat(newNetworks)
77
84
 
78
85
  // This build a "public rpc" on demand, we build them on demand because we don't want to
79
86
  // generate a bunch of providers for networks that aren't used.
80
87
  const providerForChainId = (chainId: number) => {
81
88
  if (!rpcProviders[chainId]) {
82
- const rpcUrl = combinedNetworks.find((n) => n.chainId === chainId)?.rpcUrl
89
+ const rpcUrl = combinedNetworks.find(n => n.chainId === chainId)?.rpcUrl
83
90
  if (!rpcUrl) {
84
91
  throw new Error(`no rpcUrl found for chainId: ${chainId}`)
85
92
  }
86
93
 
87
94
  const baseProvider = new ethers.providers.JsonRpcProvider(rpcUrl)
88
95
  const router = new JsonRpcRouter(
89
- [
90
- loggingProviderMiddleware,
91
- exceptionProviderMiddleware,
92
- new CachedProvider()
93
- ],
96
+ [loggingProviderMiddleware, exceptionProviderMiddleware, new CachedProvider()],
94
97
  new JsonRpcSender(baseProvider)
95
98
  )
96
-
99
+
97
100
  rpcProviders[chainId] = new ethers.providers.Web3Provider(router, chainId)
98
101
  }
99
102
 
package/src/provider.ts CHANGED
@@ -1,11 +1,10 @@
1
-
2
- import { ethers } from "ethers"
3
- import { SequenceClient } from "./client"
4
- import { ChainIdLike, NetworkConfig, allNetworks, findNetworkConfig } from "@0xsequence/network"
5
- import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from "./types"
6
- import { commons } from "@0xsequence/core"
7
- import { WalletUtils } from "./utils/index"
8
- import { SequenceSigner, SingleNetworkSequenceSigner } from "./signer"
1
+ import { ethers } from 'ethers'
2
+ import { SequenceClient } from './client'
3
+ import { ChainIdLike, NetworkConfig, allNetworks, findNetworkConfig } from '@0xsequence/network'
4
+ import { ConnectDetails, ConnectOptions, EIP1193Provider, OpenWalletIntent, OptionalChainIdLike, WalletSession } from './types'
5
+ import { commons } from '@0xsequence/core'
6
+ import { WalletUtils } from './utils/index'
7
+ import { SequenceSigner, SingleNetworkSequenceSigner } from './signer'
9
8
 
10
9
  export interface ISequenceProvider {
11
10
  readonly _isSequenceProvider: true
@@ -55,7 +54,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
55
54
 
56
55
  readonly signer: SequenceSigner
57
56
 
58
- constructor (
57
+ constructor(
59
58
  public readonly client: SequenceClient,
60
59
  private readonly providerFor: (networkId: number) => ethers.providers.JsonRpcProvider,
61
60
  public readonly networks: NetworkConfig[] = allNetworks
@@ -65,19 +64,19 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
65
64
  super(client.getChainId())
66
65
 
67
66
  // Emit events as defined by EIP-1193
68
- client.onConnect((details) => {
67
+ client.onConnect(details => {
69
68
  this.emit('connect', details)
70
69
  })
71
70
 
72
- client.onDisconnect((error) => {
71
+ client.onDisconnect(error => {
73
72
  this.emit('disconnect', error)
74
73
  })
75
74
 
76
- client.onDefaultChainIdChanged((chainId) => {
75
+ client.onDefaultChainIdChanged(chainId => {
77
76
  this.emit('chainChanged', chainId)
78
77
  })
79
78
 
80
- client.onAccountsChanged((accounts) => {
79
+ client.onAccountsChanged(accounts => {
81
80
  this.emit('accountsChanged', accounts)
82
81
  })
83
82
 
@@ -164,10 +163,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
164
163
  return this.client.connect({ ...options, authorize: true })
165
164
  }
166
165
 
167
- async openWallet(
168
- path?: string,
169
- intent?: OpenWalletIntent
170
- ) {
166
+ async openWallet(path?: string, intent?: OpenWalletIntent) {
171
167
  await this.client.openWallet(path, intent)
172
168
  return true
173
169
  }
@@ -179,13 +175,13 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
179
175
  if (chainId === undefined) {
180
176
  return undefined
181
177
  }
182
-
178
+
183
179
  const resolved = findNetworkConfig(this.networks, chainId as ChainIdLike)
184
-
180
+
185
181
  if (!resolved) {
186
182
  throw new Error(`Unsupported network ${chainId}`)
187
183
  }
188
-
184
+
189
185
  return resolved.chainId
190
186
  }
191
187
 
@@ -216,11 +212,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
216
212
  const useChainId = this.toChainId(chainId)
217
213
 
218
214
  if (!this.singleNetworkProviders[useChainId]) {
219
- this.singleNetworkProviders[useChainId] = new SingleNetworkSequenceProvider(
220
- this.client,
221
- this.providerFor,
222
- useChainId
223
- )
215
+ this.singleNetworkProviders[useChainId] = new SingleNetworkSequenceProvider(this.client, this.providerFor, useChainId)
224
216
  }
225
217
 
226
218
  return this.singleNetworkProviders[useChainId]
@@ -247,7 +239,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
247
239
  async perform(method: string, params: any): Promise<any> {
248
240
  // First we check if the method should be handled by the client
249
241
  if (method === 'eth_chainId') {
250
- return this.useChainId()
242
+ return ethers.utils.hexValue(await this.useChainId())
251
243
  }
252
244
 
253
245
  if (method === 'eth_accounts') {
@@ -282,15 +274,15 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
282
274
  // Forward call to the corresponding provider
283
275
  // we use the provided chainId, or the default one provided by the client
284
276
  const provider = await this._getSubprovider()
285
- const prepared = provider.prepareRequest(method, params) ?? [method, params]
277
+ const prepared = provider.prepareRequest(method, params) ?? [method, params]
286
278
  return provider.send(prepared[0], prepared[1])
287
279
  }
288
280
 
289
- send (method: string, params: any): Promise<any> {
281
+ send(method: string, params: any): Promise<any> {
290
282
  return this.perform(method, params)
291
283
  }
292
284
 
293
- request (request: { method: string; params?: any[] | undefined }) {
285
+ request(request: { method: string; params?: any[] | undefined }) {
294
286
  return this.perform(request.method, request.params)
295
287
  }
296
288
 
@@ -312,14 +304,9 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
312
304
  // but this would make the code harder to read, and it's not worth it
313
305
  // since we only have a few methods to override.
314
306
 
315
- async waitForTransaction(
316
- transactionHash: string,
317
- confirmations?: number,
318
- timeout?: number,
319
- optionals?: OptionalChainIdLike
320
- ) {
307
+ async waitForTransaction(transactionHash: string, confirmations?: number, timeout?: number, optionals?: OptionalChainIdLike) {
321
308
  const provider = await this._getSubprovider(optionals?.chainId)
322
- return provider.waitForTransaction(transactionHash, confirmations, timeout)
309
+ return provider.waitForTransaction(transactionHash, confirmations, timeout)
323
310
  }
324
311
 
325
312
  async getBlockNumber(optionals?: OptionalChainIdLike) {
@@ -378,10 +365,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
378
365
  return provider.call(transaction, blockTag)
379
366
  }
380
367
 
381
- async estimateGas(
382
- transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>,
383
- optionals?: OptionalChainIdLike
384
- ) {
368
+ async estimateGas(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>, optionals?: OptionalChainIdLike) {
385
369
  const provider = await this._getSubprovider(optionals?.chainId)
386
370
  return provider.estimateGas(transaction)
387
371
  }
@@ -394,18 +378,12 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
394
378
  return provider.getBlock(blockHashOrBlockTag)
395
379
  }
396
380
 
397
- async getTransaction(
398
- transactionHash: string | Promise<string>,
399
- optionals?: OptionalChainIdLike
400
- ) {
381
+ async getTransaction(transactionHash: string | Promise<string>, optionals?: OptionalChainIdLike) {
401
382
  const provider = await this._getSubprovider(optionals?.chainId)
402
383
  return provider.getTransaction(transactionHash)
403
384
  }
404
385
 
405
- async getLogs(
406
- filter: ethers.providers.Filter | Promise<ethers.providers.Filter>,
407
- optionals?: OptionalChainIdLike
408
- ) {
386
+ async getLogs(filter: ethers.providers.Filter | Promise<ethers.providers.Filter>, optionals?: OptionalChainIdLike) {
409
387
  const provider = await this._getSubprovider(optionals?.chainId)
410
388
  return provider.getLogs(filter)
411
389
  }
@@ -418,7 +396,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
418
396
  }
419
397
 
420
398
  async getResolver(name: string) {
421
- if (!await this.supportsENS()) {
399
+ if (!(await this.supportsENS())) {
422
400
  return null
423
401
  }
424
402
 
@@ -432,7 +410,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
432
410
  return name
433
411
  }
434
412
 
435
- if (!await this.supportsENS()) {
413
+ if (!(await this.supportsENS())) {
436
414
  return null
437
415
  }
438
416
 
@@ -442,7 +420,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
442
420
  }
443
421
 
444
422
  async lookupAddress(address: string | Promise<string>) {
445
- if (!await this.supportsENS()) {
423
+ if (!(await this.supportsENS())) {
446
424
  return null
447
425
  }
448
426
 
@@ -452,7 +430,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
452
430
  }
453
431
 
454
432
  async getAvatar(nameOrAddress: string) {
455
- if (!await this.supportsENS()) {
433
+ if (!(await this.supportsENS())) {
456
434
  return null
457
435
  }
458
436
 
@@ -461,11 +439,7 @@ export class SequenceProvider extends ethers.providers.BaseProvider implements I
461
439
  }
462
440
 
463
441
  static is = (provider: any): provider is SequenceProvider => {
464
- return (
465
- provider &&
466
- typeof provider === 'object' &&
467
- provider._isSequenceProvider === true
468
- )
442
+ return provider && typeof provider === 'object' && provider._isSequenceProvider === true
469
443
  }
470
444
  }
471
445
 
@@ -477,10 +451,10 @@ function normalizeChainId(chainId: string | number | bigint | { chainId: string
477
451
  /**
478
452
  * This is the same provider, but it only allows a single network at a time.
479
453
  * the network defined by the constructor is the only one that can be used.
480
- *
454
+ *
481
455
  * Attempting to call any method with a different network will throw an error.
482
456
  * Attempting to change the network of this provider will throw an error.
483
- *
457
+ *
484
458
  * NOTICE: These networks won't support ENS unless they are the mainnet.
485
459
  */
486
460
  export class SingleNetworkSequenceProvider extends SequenceProvider {
@@ -532,7 +506,7 @@ export class SingleNetworkSequenceProvider extends SequenceProvider {
532
506
  if (this._useChainId(chainId) !== this.chainId) {
533
507
  throw new Error(`Unreachable code`)
534
508
  }
535
-
509
+
536
510
  return this
537
511
  }
538
512
 
@@ -543,12 +517,8 @@ export class SingleNetworkSequenceProvider extends SequenceProvider {
543
517
  setDefaultChainId(_chainId: ChainIdLike): void {
544
518
  throw new Error(`This provider only supports the network ${this.chainId}; use the parent provider to switch networks.`)
545
519
  }
546
-
520
+
547
521
  static is(cand: any): cand is SingleNetworkSequenceProvider {
548
- return (
549
- cand &&
550
- typeof cand === 'object' &&
551
- cand._isSingleNetworkSequenceProvider === true
552
- )
522
+ return cand && typeof cand === 'object' && cand._isSingleNetworkSequenceProvider === true
553
523
  }
554
524
  }