Skip to content

Commit

Permalink
Merge pull request #153 from lidofinance/feature/si-1101-split-env-pr…
Browse files Browse the repository at this point in the history
…efill_unsafe_el_rpc_urls-to-1-5-17000-chains

feat: split env PREFILL_UNSAFE_EL_RPC_URLS to 1, 5, 17000 chains
  • Loading branch information
itaven authored Nov 29, 2023
2 parents a4a9ea4 + e46a0e4 commit 04043a4
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ EL_RPC_URLS_5=
EL_RPC_URLS_17000=

# IPFS prefill RPC URLs - list of URLs delimited by commas
PREFILL_UNSAFE_EL_RPC_URLS=
PREFILL_UNSAFE_EL_RPC_URLS_1=
PREFILL_UNSAFE_EL_RPC_URLS_5=
PREFILL_UNSAFE_EL_RPC_URLS_17000=

# supported networks for connecting wallet
SUPPORTED_CHAINS=1,17000
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-ipfs-test-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
REWARDS_BACKEND_BASE_PATH: ${{ vars.REWARDS_BACKEND_BASE_PATH }}
WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }}
ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }}
PREFILL_UNSAFE_EL_RPC_URLS: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS }}
PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }}
WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}
- uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci-ipfs-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jobs:
REWARDS_BACKEND_BASE_PATH: ${{ vars.REWARDS_BACKEND_BASE_PATH }}
WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }}
ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }}
PREFILL_UNSAFE_EL_RPC_URLS: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS }}
PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }}
PREFILL_UNSAFE_EL_RPC_URLS_5: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_5 }}
PREFILL_UNSAFE_EL_RPC_URLS_17000: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_17000 }}
WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}
- uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-ipfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
REWARDS_BACKEND_BASE_PATH: ${{ vars.REWARDS_BACKEND_BASE_PATH }}
WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }}
ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }}
PREFILL_UNSAFE_EL_RPC_URLS: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS }}
PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }}
WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}
- uses: actions/upload-artifact@v3
with:
Expand Down
15 changes: 14 additions & 1 deletion config/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@ export const useGetRpcUrlByChainId = () => {

return useCallback(
(chainId: CHAINS) => {
// Needs this condition 'cause in 'providers/web3.tsx' we add `wagmiChains.polygonMumbai` to supportedChains
// so, here chainId = 80001 is arriving which to raises an invariant
// chainId = 1 we need anytime!
if (
chainId !== CHAINS.Mainnet &&
!clientConfig.supportedChainIds.includes(chainId)
) {
// Has no effect on functionality. Just a fix.
// Return empty string as stub
// (see: 'providers/web3.tsx' --> jsonRpcBatchProvider --> getStaticRpcBatchProvider)
return '';
}

if (dynamics.ipfsMode) {
const rpc =
clientConfig.savedClientConfig.rpcUrls[chainId] ||
clientConfig.prefillUnsafeElRpcUrls?.[0];
clientConfig.prefillUnsafeElRpcUrls[chainId]?.[0];

invariant(rpc, '[useGetRpcUrlByChainId] RPC is required!');
return rpc;
Expand Down
12 changes: 10 additions & 2 deletions config/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { CHAINS } from 'utils/chains';

export type EnvConfigRaw = {
defaultChain: string | number;
supportedChains: number[];
prefillUnsafeElRpcUrls: string[];
prefillUnsafeElRpcUrls1: string[];
prefillUnsafeElRpcUrls5: string[];
prefillUnsafeElRpcUrls17000: string[];
ipfsMode: boolean;
walletconnectProjectId: string;
};

export type EnvConfigParsed = {
defaultChain: number;
supportedChainIds: number[];
prefillUnsafeElRpcUrls: string[];
prefillUnsafeElRpcUrls: {
[CHAINS.Mainnet]: string[];
[CHAINS.Goerli]: string[];
[CHAINS.Holesky]: string[];
};
ipfsMode: boolean;
walletconnectProjectId: string;
};
8 changes: 7 additions & 1 deletion env-dynamics.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export const walletconnectProjectId = process.env.WALLETCONNECT_PROJECT_ID;
export const ipfsMode = toBoolean(process.env.IPFS_MODE);

/** @type string[] */
export const prefillUnsafeElRpcUrls = process.env.PREFILL_UNSAFE_EL_RPC_URLS?.split(',') ?? [];
export const prefillUnsafeElRpcUrls1 = process.env.PREFILL_UNSAFE_EL_RPC_URLS_1?.split(',') ?? [];

/** @type string[] */
export const prefillUnsafeElRpcUrls5 = process.env.PREFILL_UNSAFE_EL_RPC_URLS_5?.split(',') ?? [];

/** @type string[] */
export const prefillUnsafeElRpcUrls17000 = process.env.PREFILL_UNSAFE_EL_RPC_URLS_17000?.split(',') ?? [];

/** @type string */
export const widgetApiBasePathForIpfs = process.env.WIDGET_API_BASE_PATH_FOR_IPFS;
7 changes: 6 additions & 1 deletion utils/parse-env-config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { EnvConfigRaw, EnvConfigParsed } from 'config/types';
import { CHAINS } from 'utils/chains';

export const parseEnvConfig = (envConfig: EnvConfigRaw): EnvConfigParsed => {
return {
defaultChain: Number(envConfig.defaultChain),
supportedChainIds: envConfig.supportedChains,
prefillUnsafeElRpcUrls: envConfig.prefillUnsafeElRpcUrls,
prefillUnsafeElRpcUrls: {
[CHAINS.Mainnet]: envConfig.prefillUnsafeElRpcUrls1,
[CHAINS.Goerli]: envConfig.prefillUnsafeElRpcUrls5,
[CHAINS.Holesky]: envConfig.prefillUnsafeElRpcUrls17000,
},
ipfsMode: envConfig.ipfsMode,
walletconnectProjectId: envConfig.walletconnectProjectId,
};
Expand Down

0 comments on commit 04043a4

Please sign in to comment.