-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathutil.ts
More file actions
38 lines (33 loc) · 1.05 KB
/
util.ts
File metadata and controls
38 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { JsonRpcProvider, Provider, Wallet } from 'ethers'
import { ethers as ethersv5 } from 'ethers-v5'
export type Unwrap<T> = T extends Promise<infer U> ? U : T
export function getEnv(name: string): string {
const value = process.env[name] || ''
if (value === '') {
throw new Error(`Environment variable ${name} is not defined`)
}
return value
}
export class DoubleProvider extends JsonRpcProvider {
public readonly v5: ethersv5.providers.JsonRpcProvider
constructor(public readonly url: string) {
super(url)
this.v5 = new ethersv5.providers.JsonRpcProvider(url)
}
}
export class DoubleWallet extends Wallet {
public readonly provider!: Provider
public readonly v5: ethersv5.Wallet & {
provider: ethersv5.providers.JsonRpcProvider
}
constructor(
privateKey: string,
public readonly doubleProvider: DoubleProvider
) {
super(privateKey, doubleProvider)
this.v5 = new ethersv5.Wallet(
privateKey,
doubleProvider.v5
) as ethersv5.Wallet & { provider: ethersv5.providers.JsonRpcProvider }
}
}