Skip to content

Commit 5e281bf

Browse files
implements generic rpc service support
1 parent 2a56e56 commit 5e281bf

28 files changed

+199
-181
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=1337
2-
REACT_APP_ALCHEMY_API=$ALCHEMY_API
2+
REACT_APP_RPC_SERVICE_API=$RPC_SERVICE_API
3+
REACT_APP_RPC_SERVICE_NAME=$RPC_SERVICE_NAME
34
REACT_APP_MULTICALL_ADDRESS=$MULTICALL_ADDRESS
45
REACT_APP_DAPP_DEVELOPMENT_TESTNET_CONTRACTS=$DAPP_DEVELOPMENT_TESTNET_CONTRACTS
56

.env.production

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=$CHAIN_ID
2-
REACT_APP_ALCHEMY_API=$ALCHEMY_API
2+
REACT_APP_RPC_SERVICE_API=$RPC_SERVICE_API
3+
REACT_APP_RPC_SERVICE_NAME=$RPC_SERVICE_NAME
34
REACT_APP_DAPP_DEVELOPMENT_TESTNET_CONTRACTS=$DAPP_DEVELOPMENT_TESTNET_CONTRACTS
45

56
REACT_APP_FEATURE_FLAG_TBTC_V2=true

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=1337
22
REACT_APP_MULTICALL_ADDRESS=0xcA11bde05977b3631167028862bE2a173976CA11
3+
REACT_APP_RPC_SERVICE_NAME=alchemy
34
REACT_APP_TACO_DOMAIN=dashboard

.github/workflows/dashboard-ci.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ jobs:
8787
env:
8888
PUBLIC_URL: /${{ github.head_ref }}
8989
DEFAULT_PROVIDER_CHAIN_ID: 11155111
90-
ALCHEMY_API: ${{ secrets.ALCHEMY_API }}
90+
RPC_SERVICE_API: ${{ secrets.RPC_SERVICE_API }}
91+
RPC_SERVICE_NAME: ${{ secrets.RPC_SERVICE_NAME }}
9192
NODE_OPTIONS: --max_old_space_size=4096
9293
MAINNET_ELECTRUM_PROTOCOL: ${{ secrets.MAINNET_ELECTRUMX_PROTOCOL }}
9394
MAINNET_ELECTRUM_HOST: ${{ secrets.MAINNET_ELECTRUMX_HOST }}
@@ -124,7 +125,8 @@ jobs:
124125
gcpBucketPath: ${{ github.head_ref }}
125126
preview: true
126127
secrets:
127-
alchemyApi: ${{ secrets.ALCHEMY_API }}
128+
rpcServiceApi: ${{ secrets.RPC_SERVICE_API }}
129+
rpcServiceName: ${{ secrets.RPC_SERVICE_NAME }}
128130
gcpServiceKey: ${{ secrets.KEEP_TEST_CI_UPLOAD_DAPP_JSON_KEY_BASE64 }}
129131
electrumProtocol: ${{ secrets.TESTNET_ELECTRUMX_PROTOCOL }}
130132
electrumHost: ${{ secrets.TESTNET_ELECTRUMX_HOST }}
@@ -155,7 +157,8 @@ jobs:
155157
gcpBucketName: dashboard.test.threshold.network
156158
preview: false
157159
secrets:
158-
alchemyApi: ${{ secrets.ALCHEMY_API }}
160+
rpcServiceApi: ${{ secrets.RPC_SERVICE_API }}
161+
rpcServiceName: ${{ secrets.RPC_SERVICE_NAME }}
159162
gcpServiceKey: ${{ secrets.KEEP_TEST_CI_UPLOAD_DAPP_JSON_KEY_BASE64 }}
160163
electrumProtocol: ${{ secrets.TESTNET_ELECTRUMX_PROTOCOL }}
161164
electrumHost: ${{ secrets.TESTNET_ELECTRUMX_HOST }}
@@ -181,7 +184,8 @@ jobs:
181184
gcpBucketName: dashboard.test.threshold.network
182185
preview: false
183186
secrets:
184-
alchemyApi: ${{ secrets.ALCHEMY_API }}
187+
rpcServiceApi: ${{ secrets.RPC_SERVICE_API }}
188+
rpcServiceName: ${{ secrets.RPC_SERVICE_NAME }}
185189
gcpServiceKey: ${{ secrets.KEEP_TEST_CI_UPLOAD_DAPP_JSON_KEY_BASE64 }}
186190
electrumProtocol: ${{ secrets.TESTNET_ELECTRUMX_PROTOCOL }}
187191
electrumHost: ${{ secrets.TESTNET_ELECTRUMX_HOST }}

.github/workflows/dashboard-mainnet.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ jobs:
4949
env:
5050
PUBLIC_URL: /${{ github.ref_name }}
5151
DEFAULT_PROVIDER_CHAIN_ID: 1
52-
ALCHEMY_API: ${{ secrets.ALCHEMY_API }}
52+
RPC_SERVICE_API: ${{ secrets.RPC_SERVICE_API }}
53+
RPC_SERVICE_NAME: ${{ secrets.RPC_SERVICE_NAME }}
5354
NODE_OPTIONS: --max_old_space_size=4096
5455
MAINNET_ELECTRUM_PROTOCOL: ${{ secrets.MAINNET_ELECTRUMX_PROTOCOL }}
5556
MAINNET_ELECTRUM_HOST: ${{ secrets.MAINNET_ELECTRUMX_HOST }}
@@ -72,7 +73,8 @@ jobs:
7273
env:
7374
PUBLIC_URL: /
7475
DEFAULT_PROVIDER_CHAIN_ID: 1
75-
ALCHEMY_API: ${{ secrets.ALCHEMY_API }}
76+
RPC_SERVICE_API: ${{ secrets.RPC_SERVICE_API }}
77+
RPC_SERVICE_NAME: ${{ secrets.RPC_SERVICE_NAME }}
7678
NODE_OPTIONS: --max_old_space_size=4096
7779
POSTHOG_SUPPORT: true
7880
POSTHOG_API_KEY: ${{ secrets.MAINNET_POSTHOG_API_KEY }}

.github/workflows/reusable-build-and-publish.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ on:
4949
default: false
5050
type: boolean
5151
secrets:
52-
alchemyApi:
53-
description: The Alchemy API Key.
52+
rpcServiceApi:
53+
description: The RPC service API Key.
54+
required: true
55+
rpcServiceName:
56+
description: The RPC service name.
5457
required: true
5558
gcpServiceKey:
5659
description: JSON key for Google Cloud Platform service account.
@@ -162,7 +165,8 @@ jobs:
162165
env:
163166
PUBLIC_URL: /
164167
DEFAULT_PROVIDER_CHAIN_ID: ${{ env.NETWORK_ID }}
165-
ALCHEMY_API: ${{ secrets.alchemyApi }}
168+
RPC_SERVICE_API: ${{ secrets.rpcServiceApi }}
169+
RPC_SERVICE_NAME: ${{ secrets.rpcServiceName }}
166170
NODE_OPTIONS: --max_old_space_size=4096
167171
MAINNET_ELECTRUM_PROTOCOL: ${{ secrets.mainnetElectrumProtocol }}
168172
MAINNET_ELECTRUM_HOST: ${{ secrets.mainnetElectrumHost }}
@@ -183,7 +187,8 @@ jobs:
183187
env:
184188
PUBLIC_URL: /${{ inputs.gcpBucketPath }}
185189
DEFAULT_PROVIDER_CHAIN_ID: ${{ env.NETWORK_ID }}
186-
ALCHEMY_API: ${{ secrets.alchemyApi }}
190+
RPC_SERVICE_API: ${{ secrets.rpcServiceApi }}
191+
RPC_SERVICE_NAME: ${{ secrets.rpcServiceName }}
187192
NODE_OPTIONS: --max_old_space_size=4096
188193
MAINNET_ELECTRUM_PROTOCOL: ${{ secrets.mainnetElectrumProtocol }}
189194
MAINNET_ELECTRUM_HOST: ${{ secrets.mainnetElectrumHost }}

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
1212

1313
```
1414
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=11155111
15-
REACT_APP_ALCHEMY_API=<your Alchemy API key>
15+
REACT_APP_RPC_SERVICE_API=<your RPC service API key>
16+
REACT_APP_RPC_SERVICE_NAME=<the RPC service name - Expected in RpcServices enum format e.g. "alchemy" or "infura">
1617
// We can skip this env variable- the dapp uses the correct address
1718
// of Multicall contract for Sepolia under the hood.
1819
REACT_APP_MULTICALL_ADDRESS=$MULTICALL_ADDRESS
@@ -109,7 +110,8 @@ Update `.env` to contain:
109110

110111
```
111112
REACT_APP_DEFAULT_PROVIDER_CHAIN_ID=11155111
112-
REACT_APP_ALCHEMY_API=<your Alchemy API key here>
113+
REACT_APP_RPC_SERVICE_API=<your RPC service API key here>
114+
REACT_APP_RPC_SERVICE_NAME=<your RPC service name here>
113115
REACT_APP_MULTICALL_ADDRESS=$MULTICALL_ADDRESS
114116
115117
REACT_APP_FEATURE_FLAG_TBTC_V2=true

src/enums/env.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const envVariables = [
22
"DEFAULT_PROVIDER_CHAIN_ID",
3-
"ALCHEMY_API",
3+
"RPC_SERVICE_API",
4+
"RPC_SERVICE_NAME",
45
"TBTC_SUBGRAPH_API",
56
"FEATURE_FLAG_TBTC_V2",
67
"FEATURE_FLAG_TBTC_V2_REDEMPTION",
@@ -30,7 +31,7 @@ const envVariables = [
3031
export type EnvVariableKey = typeof envVariables[number]
3132

3233
// In order not to break the previous enum API, so using eg.
33-
// `EnvVariable.ALCHEMY_API` is still valid.
34+
// `EnvVariable.RPC_SERVICE_API` is still valid.
3435
export const EnvVariable: Record<EnvVariableKey, EnvVariableKey> =
3536
envVariables.reduce((reducer, envKey) => {
3637
reducer[envKey] = envKey

src/networks/README.md

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,25 @@ export enum SupportedChainIds {
3333
}
3434
```
3535

36-
AlchemyName: Identifies the API identifiers (Alchemy) associated with each network.
36+
AlchemyNetworkId: Identifies the API identifiers (Alchemy) associated with each network.
3737

3838
```
39-
export enum AlchemyName {
39+
export enum AlchemyNetworkId {
4040
Ethereum = "eth",
4141
Arbitrum = "arb",
4242
Base = "base",
4343
}
4444
```
4545

46+
InfuraNetworkId: Identifies the API identifiers (Infura) associated with each network.
47+
48+
```
49+
export enum InfuraNetworkId {
50+
Arbitrum = "arbitrum",
51+
Base = "base",
52+
}
53+
```
54+
4655
NetworkType: Classifies networks based on whether they are Mainnet or Testnet.
4756

4857
```
@@ -63,7 +72,7 @@ export enum Layer {
6372

6473
Network List Definition
6574

66-
The networks.ts file in utils defines an array of Network objects, where each network is described by its chain ID, name, layer, network type, and Alchemy identifier. This array serves as the central configuration point for supported networks.
75+
The networks.ts file in utils defines an array of Network objects, where each network is described by its chain ID, name, layer, network type, and RPC service identifier (Alchemy or Infura). This array serves as the central configuration point for supported networks.
6776

6877
Example Network Configuration
6978

@@ -73,67 +82,36 @@ Below is an example network configuration, which includes key properties for eac
7382
export const networks: Network[] = [
7483
{
7584
chainId: SupportedChainIds.Ethereum,
76-
name: "Ethereum",
77-
layer: Layer.L1,
78-
networkType: NetworkType.Mainnet,
79-
alchemyName: AlchemyName.Ethereum,
80-
},
81-
{
82-
chainId: SupportedChainIds.Sepolia,
83-
name: "Sepolia",
84-
layer: Layer.L1,
85-
networkType: NetworkType.Testnet,
86-
alchemyName: AlchemyName.Ethereum,
87-
},
88-
{
89-
chainId: SupportedChainIds.Localhost,
90-
name: "Localhost",
85+
name: SupportedNetworksName.Ethereum,
9186
layer: Layer.L1,
92-
networkType: NetworkType.Testnet,
93-
alchemyName: "",
94-
},
95-
{
96-
chainId: SupportedChainIds.Arbitrum,
97-
name: "Arbitrum",
98-
layer: Layer.L2,
9987
networkType: NetworkType.Mainnet,
100-
alchemyName: AlchemyName.Arbitrum,
101-
},
102-
{
103-
chainId: SupportedChainIds.ArbitrumSepolia,
104-
name: "ArbitrumSepolia",
105-
layer: Layer.L2,
106-
networkType: NetworkType.Testnet,
107-
alchemyName: AlchemyName.Arbitrum,
108-
},
109-
{
110-
chainId: SupportedChainIds.Base,
111-
name: "Base",
112-
layer: Layer.L2,
113-
networkType: NetworkType.Mainnet,
114-
alchemyName: AlchemyName.Base,
115-
},
116-
{
117-
chainId: SupportedChainIds.BaseSepolia,
118-
name: "BaseSepolia",
119-
layer: Layer.L2,
120-
networkType: NetworkType.Testnet,
121-
alchemyName: AlchemyName.Base,
122-
},
88+
chainParameters: {
89+
chainId: toHex(SupportedChainIds.Ethereum),
90+
chainName: "Ethereum Mainnet",
91+
nativeCurrency: {
92+
name: NativeCurrency.Ether,
93+
symbol: ETH_SYMBOL,
94+
decimals: DECIMALS,
95+
},
96+
rpcUrls: [PublicRpcUrls.Ethereum],
97+
blockExplorerUrls: [createExplorerPrefix(SupportedChainIds.Ethereum)],
98+
},
99+
}
100+
// ...
123101
]
124102
```
125103

126104
Adding a New Network
127105

128106
- Update the SupportedChainIds enum: Add the new chain ID with a unique identifier.
129107
- Add a corresponding entry in networks.ts: Create a new network object with the required properties such as name, layer, networkType, and alchemyName (if applicable).
130-
- Define the Alchemy name (if needed): If the new network is supported by Alchemy, add its API identifier to the AlchemyName enum.
108+
- Define the RPC network Id (if needed): If the new network is supported by Alchemy or Infura, add its API identifier to the AlchemyNetworkId or InfuraNetworkId.
131109

132110
Removing a Network
133111

134112
- Remove the chain ID from SupportedChainIds.
135113
- Delete the network entry from networks.ts.
136-
- Remove its corresponding entry from the AlchemyName enum if no longer needed.
114+
- Remove its corresponding entry from the AlchemyNetworkId or InfuraNetworkId enum if no longer needed.
137115

138116
Conclusion
139117

src/networks/constants/networks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export const DECIMALS = 18
22
export const ETH_SYMBOL = "ETH"
3+
export const MAIN_ALCHEMY_URL = "g.alchemy.com/v2/"
4+
export const MAIN_INFURA_URL = "infura.io/v3/"

0 commit comments

Comments
 (0)