Skip to content

Commit cc94ac3

Browse files
committed
remove getProvider(chainId) and replace it with a simpler getProvider() which only looks for JSON_RPC_URL in the env vars - this makes the library more flexible when working with new / other chains
1 parent 3b44a3b commit cc94ac3

File tree

6 files changed

+38
-38
lines changed

6 files changed

+38
-38
lines changed

.envrc.example

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
export MAINNET_RPC_URL=''
2-
export OPTIMISM_MAINNET_RPC_URL=''
3-
export BASE_MAINNET_RPC_URL=''
4-
export ARBITRUM_MAINNET_RPC_URL=''
5-
6-
export SEPOLIA_RPC_URL=''
7-
export OPTIMISM_SEPOLIA_RPC_URL=''
8-
export BASE_SEPOLIA_RPC_URL=''
9-
export ARBITRUM_SEPOLIA_RPC_URL=''
1+
export JSON_RPC_URL=''

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
/temp
99
node_modules
1010
oclif.manifest.json
11-
.envrc
1211
.DS_STORE
1312
.history
1413
.yalc
1514
yalc.lock
1615
prizes
17-
vaultAccounts
16+
vaultAccounts
17+
.envrc*
18+
!.envrc.example

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ npx @generationsoftware/pt-v5-cli help utils vaultAccounts
1717
npx @generationsoftware/pt-v5-cli help utils concatWinners
1818
```
1919

20+
### Setup
21+
22+
Set up your environment variables using `dotenv`:
23+
24+
#### ENV
25+
26+
Copy `.envrc.example` and input the env vars needed to run this project:
27+
28+
```sh
29+
cp .envrc.example .envrc
30+
```
31+
32+
Once your env variables are setup, load them with:
33+
34+
```sh
35+
direnv allow
36+
```
37+
38+
#### LIST OF ENVIRONMENT VARIABLES
39+
40+
```sh
41+
JSON_RPC_URI: Your Infura/Alchemy/etc JSON RPC URI
42+
```
43+
2044
# ⌨️ CLI Installation
2145

2246
<!-- usage -->

src/commands/utils/concatWinners.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class ConcatWinners extends Command {
5757
const { flags } = await this.parse(ConcatWinners);
5858
const { chainId, prizePool, outDir } = flags;
5959

60-
const readProvider = getProvider(chainId);
60+
const readProvider = getProvider();
6161

6262
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
6363

@@ -82,7 +82,7 @@ export default class ConcatWinners extends Command {
8282
`Running "utils:concatWinners" on chainId: ${chainId} for prizePool: ${prizePool.toLowerCase()} using latest drawID`
8383
);
8484

85-
const readProvider = getProvider(chainId);
85+
const readProvider = getProvider();
8686
const contracts = await downloadContractsBlob(Number(chainId));
8787
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
8888
const prizePoolInfo: PrizePoolInfo = await getPrizePoolInfo(readProvider, contracts);

src/commands/utils/vaultAccounts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class VaultAccounts extends Command {
5656
const { flags } = await this.parse(VaultAccounts);
5757
const { chainId, prizePool, outDir } = flags;
5858

59-
const readProvider = getProvider(chainId);
59+
const readProvider = getProvider();
6060

6161
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
6262

@@ -81,7 +81,7 @@ export default class VaultAccounts extends Command {
8181
`Running "utils:vaultAccounts" on chainId: ${chainId} for prizePool: ${prizePool.toLowerCase()} using latest drawID`
8282
);
8383

84-
const readProvider = getProvider(chainId);
84+
const readProvider = getProvider();
8585
const prizePoolContract = await getPrizePoolByAddress(Number(chainId), prizePool, readProvider);
8686
const drawId = await prizePoolContract?.getLastAwardedDrawId();
8787
console.log(`DrawID: #${drawId.toString()}`);

src/lib/utils/getProvider.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
import { JsonRpcProvider } from "@ethersproject/providers";
22

3-
type Providers = { [k: string]: JsonRpcProvider };
4-
5-
// eg.
6-
// https://mainnet.infura.io/v3/<YOUR-API-KEY>
7-
const providers: Providers = {
8-
// mainnets
9-
1: new JsonRpcProvider(process.env.ETHEREUM_MAINNET_RPC_URL),
10-
10: new JsonRpcProvider(process.env.OPTIMISM_MAINNET_RPC_URL),
11-
8453: new JsonRpcProvider(process.env.BASE_MAINNET_RPC_URL),
12-
42161: new JsonRpcProvider(process.env.ARBITRUM_MAINNET_RPC_URL),
13-
// testnets
14-
84532: new JsonRpcProvider(process.env.BASE_SEPOLIA_RPC_URL),
15-
421614: new JsonRpcProvider(process.env.ARBITRUM_SEPOLIA_RPC_URL),
16-
11155111: new JsonRpcProvider(process.env.SEPOLIA_RPC_URL),
17-
11155420: new JsonRpcProvider(process.env.OPTIMISM_SEPOLIA_RPC_URL),
18-
};
19-
20-
export const getProvider = (chainId: string): JsonRpcProvider => {
21-
const provider = providers[chainId];
22-
23-
if (!provider) {
24-
throw new Error(`No provider for chainId ${chainId}`);
3+
export const getProvider = (): JsonRpcProvider => {
4+
if (!process.env.JSON_RPC_URL) {
5+
throw new Error(
6+
`No provider available - likely missing 'process.env.JSON_RPC_URL', see README about proper installation`
7+
);
258
}
269

27-
return provider;
10+
return new JsonRpcProvider(process.env.JSON_RPC_URL);
2811
};

0 commit comments

Comments
 (0)