Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge development into main #31

Merged
merged 139 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
11d7180
refactor: remove type duplication
EresDev Jun 13, 2024
70b6e4f
feat: add tracking & protocol config options
EresDev Jun 13, 2024
a5cef0b
refactor: remove duplication
EresDev Jun 13, 2024
7b52c8e
refactor: extract function to remove duplication
EresDev Jun 14, 2024
d99097f
refactor: extract function to remove duplication
EresDev Jun 14, 2024
837fd86
feat: use rpcs original object with extra info
EresDev Jun 14, 2024
a1c55c2
refactor: remove duplication
EresDev Jun 14, 2024
5ef09a0
fix: use correct types
EresDev Jun 14, 2024
0fd28dc
refactor: remove console logs
EresDev Jun 14, 2024
19cea2a
fix: use correct network rpcs
EresDev Jun 14, 2024
700d8dc
refactor: use class field instead of global
EresDev Jun 14, 2024
d83cf86
refactor: extract new types
EresDev Jun 14, 2024
fc493ae
feat: filter rpc by tracking info
EresDev Jun 14, 2024
42e2288
test: confirm each rpc url to be correctly filtered
EresDev Jun 15, 2024
28560c5
chore: improved types
Keyrxng Jun 15, 2024
e461f39
chore: add some explorers
Keyrxng Jun 15, 2024
a92c109
chore: apply manual to base types
Keyrxng Jun 15, 2024
5ebe24a
chore: add more explorers
Keyrxng Jun 15, 2024
73fe80a
chore: tests, no more build injection
Keyrxng Jun 15, 2024
176cfd4
chore: better data source
Keyrxng Jun 15, 2024
4f1bef3
chore: cspell, eslint
Keyrxng Jun 15, 2024
1a8b6e7
test: get correct rpcs for given tracking
EresDev Jun 15, 2024
4b02b1f
chore: create and use filtered base types
Keyrxng Jun 16, 2024
e3cd0f0
fix: remove protocol config options
EresDev Jun 16, 2024
4fbe2f1
fix: make tracking property optional
EresDev Jun 16, 2024
fb3c889
refactor: rename function & its access
EresDev Jun 16, 2024
2a8b4fa
chore: ChainId to NetworkId, use concurrently
Keyrxng Jun 18, 2024
a6acc3f
chore: split test commands
Keyrxng Jun 18, 2024
e46a217
chore: remove concurrently
Keyrxng Jun 18, 2024
f3d43f8
chore: fresh lockfile
Keyrxng Jun 20, 2024
dfa76ed
ci: build tests before jest
Keyrxng Jun 20, 2024
edd481c
ci: adjust test
Keyrxng Jun 20, 2024
30022f4
Merge pull request #28 from Keyrxng/improved-constants
0x4007 Jun 21, 2024
ac96ebc
refactor: rename networkRpcsOriginal to networkRpcs
EresDev Jun 21, 2024
aa0a2ea
Merge branch 'development' of https://github.com/ubiquity/rpc-handler…
EresDev Jun 22, 2024
ec9b91c
fix: update rpc type definition
EresDev Jun 22, 2024
e4c4f4e
refactor: remove duplicate code
EresDev Jun 22, 2024
2eb0f97
feat: add debug configuration for vscode
EresDev Jun 22, 2024
e81ad40
style: format using eslint
EresDev Jun 22, 2024
d0497fe
docs: add info about tracking
EresDev Jun 22, 2024
b406e09
docs: fix broken link to config
EresDev Jun 22, 2024
bb33963
refactor: remove dead code
EresDev Jun 22, 2024
b9cb44f
refactor: use RPCHanlder from source instead of build
EresDev Jun 22, 2024
242da74
refactor: rename RpcType to Rpc
EresDev Jun 22, 2024
855a5a1
refactor: move shared types & function to handler
EresDev Jun 22, 2024
2c24823
chore: remove vscode specific test config files
EresDev Jun 24, 2024
c5aba95
refactor: remove redundant constants & type
EresDev Jun 24, 2024
1f36682
refactor: import networkRpcs from source, not build
EresDev Jun 24, 2024
30eb11a
refactor: remove build step before tests
EresDev Jun 24, 2024
1d963bc
Merge pull request #26 from EresDevOrg/development
0x4007 Jun 27, 2024
04665f2
chore: return proxy
Keyrxng Jun 6, 2024
72135a0
chore: configurables and basic log
Keyrxng Jun 6, 2024
b39e047
chore: adopt pretty-logs from logger
Keyrxng Jun 6, 2024
abd2d4c
refactor: no enums and correct types
Keyrxng Jun 6, 2024
9834647
chore: use logger
Keyrxng Jun 6, 2024
2f1e901
chore: log tweaks and tests init
Keyrxng Jun 6, 2024
7faf6f3
chore: unref timeout
Keyrxng Jun 6, 2024
5a25b29
fix: log
Keyrxng Jun 6, 2024
7b31c5f
fix: attempting to close timeouts
Keyrxng Jun 6, 2024
57bb672
chore: tidy up call-handler testing
Keyrxng Jun 6, 2024
c50fd06
feat: proxy handler
Keyrxng Jun 6, 2024
103523b
refactor: remove unused mocks
Keyrxng Jun 6, 2024
4c34ef3
refactor: move services into /types
Keyrxng Jun 6, 2024
2997d89
chore: call handler log tests
Keyrxng Jun 6, 2024
4d77418
chore: readme and comments
Keyrxng Jun 7, 2024
5427159
fix: improved log tests
Keyrxng Jun 7, 2024
c517ce5
chore: improved logging
Keyrxng Jun 7, 2024
1a8eb87
fix: rethrow error, finish tests
Keyrxng Jun 7, 2024
a068543
fix: readme
Keyrxng Jun 9, 2024
a3bd1dd
ci: use old lockfile
Keyrxng Jun 18, 2024
d96a51b
ci: use old lockfile
Keyrxng Jun 18, 2024
96f95b5
ci: use old lockfile
Keyrxng Jun 18, 2024
817763f
chore: fix open test handles
Keyrxng Jun 20, 2024
26895d2
ci: improve test for env
Keyrxng Jun 20, 2024
23014e3
chore: updated foundry error res
Keyrxng Jun 20, 2024
9d00a58
chore: yarn build refactor
Keyrxng Jun 20, 2024
ad37f85
chore: yarn test refactor
Keyrxng Jun 20, 2024
99d14dd
chore: isolate module in tests
Keyrxng Jun 22, 2024
abe1432
ci: add test timeout, no import from other tests
Keyrxng Jun 22, 2024
9778fa4
ci: fix knip issues
rndquu Jun 24, 2024
b4947c9
chore: refactor tests
Keyrxng Jun 27, 2024
e377b3e
chore: gitignore dynamic.ts, move to root
Keyrxng Jun 27, 2024
4395ca4
chore: no pre-test build, remove dynamic.d.ts
Keyrxng Jun 27, 2024
5ae41ea
chore: format
Keyrxng Jun 27, 2024
5e5803a
chore: double test timeout for ci
Keyrxng Jun 27, 2024
6f2dd9b
Update publish-package.yml
0x4007 Jul 2, 2024
85dab3f
fix: removed comments from Jest testing and added Action comment dash…
gentlementlegen Jul 2, 2024
57e4f79
Merge pull request #29 from gentlementlegen/development
0x4007 Jul 2, 2024
f7cc47e
Merge branch 'development' into proxify
Keyrxng Jul 16, 2024
6b28065
chore: eslint, cspell, prettier
Keyrxng Jul 17, 2024
8ed1230
chore: gitignore test-dashboard
Keyrxng Jul 17, 2024
2a6103a
fix: built export fixes
Keyrxng Jul 17, 2024
983eb5e
Merge pull request #24 from Keyrxng/proxify
Keyrxng Jul 17, 2024
5b2f026
feat: removed bump script and added release-please
gentlementlegen Jul 8, 2024
5e0bb40
fix: increased timeout for tests
gentlementlegen Jul 27, 2024
38751c0
fix: increased timeout for tests
gentlementlegen Jul 27, 2024
4e1adb6
chore: logs for test
gentlementlegen Jul 27, 2024
c32cf54
chore: logs for test
gentlementlegen Jul 27, 2024
8175285
chore: logs for test
gentlementlegen Jul 27, 2024
6d1a6a1
chore: log tests
gentlementlegen Jul 27, 2024
99b7b86
chore: log tests
gentlementlegen Jul 27, 2024
f554375
chore: logs for test
gentlementlegen Jul 27, 2024
7d5a7d2
chore: logs for test
gentlementlegen Jul 27, 2024
01a5444
chore: logs for test
gentlementlegen Jul 27, 2024
7b7e4b6
chore: logs for test
gentlementlegen Jul 27, 2024
5a889a2
chore: logs for test
gentlementlegen Jul 27, 2024
2c506c7
chore: logs for test
gentlementlegen Jul 27, 2024
5fec954
chore: logs for test
gentlementlegen Jul 27, 2024
ca3f897
chore: logs for test
gentlementlegen Jul 27, 2024
dc0cf53
chore: logs for test
gentlementlegen Jul 27, 2024
51f3e3d
chore: logs for test
gentlementlegen Jul 27, 2024
726282d
chore: logs for test
gentlementlegen Jul 27, 2024
f197be9
chore: logs for test
gentlementlegen Jul 27, 2024
7f684df
chore: logs for test
gentlementlegen Jul 27, 2024
b0513f2
chore: logs for test
gentlementlegen Jul 27, 2024
2e289c6
chore: logs for test
gentlementlegen Jul 27, 2024
28932f4
chore: logs for test
gentlementlegen Jul 27, 2024
a5cb660
chore: removed logs
gentlementlegen Jul 27, 2024
3052bcd
chore: removed logs
gentlementlegen Jul 27, 2024
f2eb006
chore: removed logs
gentlementlegen Jul 27, 2024
7f71190
chore: removed comments
gentlementlegen Jul 27, 2024
e65c33f
chore: removed comments
gentlementlegen Jul 27, 2024
15b3a42
chore: fixed knip
gentlementlegen Jul 27, 2024
cb7ac53
chore: fixed finally
gentlementlegen Jul 27, 2024
e867b5b
chore: changed logic to remove the failing RPC
gentlementlegen Jul 29, 2024
afd4fdf
chore: mock axios
gentlementlegen Jul 30, 2024
1751974
chore: test rpc handler
gentlementlegen Jul 30, 2024
b2bf5d9
chore: test after each cleanup
gentlementlegen Jul 30, 2024
1408fe8
chore: setup for rpc
gentlementlegen Jul 30, 2024
e79fdbe
chore: test benchmark
gentlementlegen Jul 30, 2024
67e14a0
chore: test call handler
gentlementlegen Jul 30, 2024
fee1702
chore: clear call handler tests
gentlementlegen Jul 30, 2024
c2ab89a
chore: clear call handler tests
gentlementlegen Jul 30, 2024
bd2875f
chore: jest all tests
gentlementlegen Jul 30, 2024
4cd624a
chore: jest all tests
gentlementlegen Jul 30, 2024
2c8efc2
chore: added back tests with mods
gentlementlegen Jul 30, 2024
a8bafb5
chore: changed tests to use anvil
gentlementlegen Jul 30, 2024
eb5aae8
chore: changed tests to use anvil
gentlementlegen Jul 30, 2024
e50fa28
Merge pull request #33 from gentlementlegen/fix/tests
gentlementlegen Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "lib", "dist"],
"ignorePaths": ["**/*.json", "**/*.css", "node_modules", "**/*.log", "lib", "dist", "dynamic.ts"],
"useGitignore": true,
"language": "en",
"words": ["dataurl", "devpool", "outdir", "servedir"],
"dictionaries": ["typescript", "node", "software-terms"],
"import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"],
"ignoreRegExpList": ["[0-9a-fA-F]{6}"],
"ignoreWords": ["Rpcs", "ethersproject", "publicnode", "WXDAI", "XDAI", "chainlist", "Knip", "LOCALSTORAGE"]
"ignoreWords": ["Rpcs", "ethersproject", "publicnode", "WXDAI", "XDAI", "chainlist", "Knip", "LOCALSTORAGE", "sonarjs", "cronos", "Cronos", "gochain"]
}
10 changes: 10 additions & 0 deletions .github/cspell.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { exec } = require("child_process");

exec('cspell "**/*"', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
if (stdout) console.log(`stdout: ${stdout}`);
if (stderr) console.error(`stderr: ${stderr}`);
});
40 changes: 0 additions & 40 deletions .github/workflows/bump-version.yml

This file was deleted.

36 changes: 25 additions & 11 deletions .github/workflows/jest-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,33 @@ jobs:
with:
fetch-depth: 0

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install dependencies
run: yarn install

- name: Build & Run test suite
- name: Build
run: yarn build

- name: Start Anvil
run: yarn test:anvil &

- name: Wait for Anvil
run: |
yarn test | tee ./coverage.txt && exit ${PIPESTATUS[0]}

- name: Jest Coverage Comment
# Ensures this step is run even on previous step failure (e.g. test failed)
for i in {1..30}
do
if curl -s http://localhost:8545; then
break
fi
sleep 1
done || exit 1

- name: Jest With Coverage
run: yarn test

- name: Add Jest Report to Summary
if: always()
uses: MishaKav/jest-coverage-comment@main
with:
coverage-summary-path: coverage/coverage-summary.json
junitxml-path: junit.xml
junitxml-title: JUnit
coverage-path: ./coverage.txt
run: echo "$(cat test-dashboard.md)" >> $GITHUB_STEP_SUMMARY
2 changes: 1 addition & 1 deletion .github/workflows/knip-reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
jobs:
knip-reporter:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion != 'success' }}
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -24,7 +25,6 @@ jobs:
trim: true

- name: Report knip results to pull request
if: ${{ github.event.workflow_run.conclusion != 'success' }}
uses: gitcoindev/knip-reporter@main
with:
verbose: true
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ jobs:
publish-package:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
release-type: node
target-branch: main

- name: Checkout repository code
uses: actions/checkout@v4
with:
Expand All @@ -32,6 +38,7 @@ jobs:
yarn pack

- name: Publish
run: npm publish --access public
run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: ${{ steps.release.outputs.release_created }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ node_modules
dist

coverage
junit.xml
junit.xml
dynamic.ts
test-dashboard.md
27 changes: 14 additions & 13 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
nodeLinker: node-modules

supportedArchitectures:
os:
- "current"
- "darwin"
- "linux"
- "win32"
cpu:
- "current"
- "x64"
- "x86"
- "arm"
- "ia32"
- current
- x64
- x86
- arm
- ia32
libc:
- "current"
- "glibc"
- "musl"
- current
- glibc
- musl
os:
- current
- darwin
- linux
- win32
85 changes: 59 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# `@ubiquity-dao/rpc-handler`

This packages leverages [Chainlist's](https://github.com/DefiLlama/chainlist) network RPC list to return the lowest latency provider from the list for any given network ID.

## Features

- Returns the lowest latency provider for a given network ID
- Drops bad endpoints from the list and creates a runtime/local storage cache
- Can re-test the cached RPCs by calling `handler.getFastestRpcProvider()`
- Can be used in both the browser and Node.js
- Fully configurable and extendable
- Only uses endpoints which Chainlist report as tracking _no_ data (see [`extraRpcs.js`](https://github.com/DefiLlama/chainlist/blob/main/constants/extraRpcs.js))
## Why use this package?

- **No more slow RPCs**: No more slow RPCs, no more failed requests, no more headaches
- **Fastest RPCs**: Returns the fastest RPC for a given network ID
- **Fallback mechanism**: Retries failed method calls on the next fastest provider
- **Retries failed method calls**: Retries failed method calls on the next fastest provider
- **No more searching for RPCs**: No need to for an RPC URL again, just pass the network ID
- **Fully configurable**: Configure the number of retries, retry delay, log tier and more
- **Browser and Node.js support**: Can be used in both the browser and Node.js
- **Local storage cache**: Stores the fastest RPCs for a given network ID in the browser's local storage
- **Drop-in replacement**: No changes required to your existing codebase, just replace your current provider with the one returned by `RPCHandler.getFastestRpcProvider()`
- **No tracking or analytics**: No additional tracking, data collection or analytics performed by this package beyond the specific public endpoints that support those features

## Installation

Expand All @@ -26,13 +28,23 @@ import { RPCHandler, HandlerConstructorConfig } from "@ubiquity-dao/rpc-handler/

export function useHandler(networkId: number) {
const config: HandlerConstructorConfig = {
networkId: 1,
rpcTimeout: 1500,
autoStorage: false,
cacheRefreshCycles: 10,
networkName: null, // the name will be deduced from the networkId, unless using a custom network
networkRpcs: null, // same as networkName, but for injecting additional RPCs
runtimeRpcs: null, // same as networkRpcs, although these are considered error-free
networkId: 100, // your chosen networkId
networkName: null, // will default using the networkRpcs
networkRpcs: null, // e.g "https://mainnet.infura.io/..."
runtimeRpcs: null, // e.g "<networkId>__https://mainnet.infura.io/..." > "1__https://mainnet.infura.io/..."
autoStorage: true, // browser only, will store in localStorage
cacheRefreshCycles: 10, // bad RPCs are excluded if they fail, this is how many cycles before they're re-tested
rpcTimeout: 1500, // when the RPCs are tested they are raced, this is the max time to allow for a response
tracking: "yes", // accepted values: "yes" | "limited" | "none". This is the data tracking status of the RPC, not this package.
proxySettings: {
retryCount: 3, // how many times we'll loop the list of RPCs retrying the request before failing
retryDelay: 100, // (ms) how long we'll wait before moving to the next RPC, best to keep this low
logTier: "ok", // |"info"|"error"|"debug"|"fatal"|"verbose"; set to "none" for no logs, null will default to "error", "verbose" will log all
logger: null, // null will default to PrettyLogs
strictLogs: true, // true, only the specified logTier will be logged and false all wll be logged.
moduleName?: "[UBQ RPC Handler]", // Can be omitted. this is the prefix for the logs.
disabled?: false, // Can be omitted. this will disable the proxy, requiring you to handle retry logic etc yourself.
}
};
// No RPCs are tested at this point
return new RPCHandler(config);
Expand All @@ -51,22 +63,43 @@ app.provider = await handler.getFastestRpcProvider();

- The RPCs are not tested on instantiation, but are tested on each call to `handler.getFastestRpcProvider()` or `handler.testRpcPerformance()`

- See the full [config](src\handler.ts) object (optionally passed in the constructor) for more options
- See the full [config](types/handler.ts) object (optionally passed in the constructor) for more options

- Local storage is not enabled by default, but can be enabled by passing `autoStorage: true` in the config object
- LocalStorage is not enabled by default, but can be enabled by passing `autoStorage: true` in the config object

- The `cacheRefreshCycles` is the number of roundtrips made before clearing the cache and re-testing all RPCs again
- Use the returned `JsonRpcProvider` object as you would normally, internally, any call you pass through it will be retried on the next fastest provider if it fails. It should only ever really throw due to user error or a network issue.

## Testing

- Tests have a specific build in order to run `yarn test` will produce this build and run the tests.
- After testing, re-build using `yarn build` for the original build
1. Build the package:

```bash
yarn test
yarn build
```

- This below will only work after `yarn build` has been run and will fail under test conditions
2. In terminal A run the following command to start a local Anvil instance:

```bash
npx tsx tests/script-test.ts
```
yarn test:anvil
```

3. In terminal B run the following command to run the tests:

```bash
yarn test
```

## Say goodbye to slow RPCs

This packages leverages [Chainlist's](https://github.com/DefiLlama/chainlist) network RPC list to return the lowest latency provider from the list for any given network ID. Creating a runtime/local storage cache of the fastest RPCs, it can be used in both the browser and Node.js.

By default, it performs as an abstraction layer for the Web3 developer by having built-in failed method call retries,
bad endpoint exclusion and a cache of the fastest RPCs for a given network ID. It serves as a drop-in replacement for any `JsonRpcProvider` and can be extended to handle custom RPCs, chains and more.

By routing requests through this package, it ensures the lowest latency for your users, while also providing a fallback mechanism for when the fastest provider fails. As even the best of nodes can fail, it retries failed method calls on the next fastest provider and so on until it succeeds or until your custom breakpoints are reached. With the ability to configure the number of retries, retry delay, log tier, breakpoints and more, it can be tailored to your specific needs.

There is no additional tracking, data collection or analytics performed by this package beyond the specific public endpoints that support those features. These will be made filterable in the future. Calls are made directly to the RPCs and the only data stored is the `Record` of RPCs for a given network ID, which can be stored in the browser's local storage for faster retrieval.

No changes are required to your existing codebase, simply replace your current provider with the one returned by `RPCHandler.getFastestRpcProvider()` and you're good to go. While all attempts are made to ensure the fastest provider is always used, it's important to note that the fastest provider can change over time, so it's recommended to call `RPCHandler.getFastestRpcProvider()` at the start of your app or at regular intervals. Also, it is possible that all providers fail, in which case the package will throw an error.

No more slow RPCs, no more failed requests, no more headaches.
55 changes: 55 additions & 0 deletions build/dynamic-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { appendFile, writeFile } from "fs/promises";
import { BlockExplorer, NativeToken } from "../types/handler";
import { generateChainData } from "../lib/chainlist/utils/fetch";

/**
* This produces dynamic types and constants for:
* - CHAINS_IDS
* - NETWORKS
* - NETWORK_FAUCETS
* - NETWORK_EXPLORERS
* - NETWORK_CURRENCIES
* - EXTRA_RPCS
*/

export async function createDynamicTypes() {
const data = await generateChainData();
const idToNetwork: Record<string, string> = {};
const networkToId: Record<string, number> = {};
const idToRpc: Record<string, string[]> = {};
const idToFaucet: Record<string, string[]> = {};
const idToExplorers = {} as Record<string, BlockExplorer[]>;
const idToNativeCurrency: Record<string, NativeToken> = {};
const extraRpcs: Record<string, string[]> = {};

for (const chain of data) {
let { name, chainId, networkId, rpc, faucets, explorers, nativeCurrency } = chain;
name = name.toLowerCase().replace(/\s/g, "-");
idToNetwork[chainId] = name;
networkToId[name] = networkId;
idToRpc[chainId] = rpc;
idToFaucet[chainId] = faucets;

if (explorers && explorers.length > 0) {
idToExplorers[chainId] = explorers;
}

if (rpc && rpc.length > 0) {
extraRpcs[chainId] = rpc;
}

idToNativeCurrency[chainId] = nativeCurrency;
}

const filename = "dynamic.ts";

// Clear the file
await writeFile(filename, "/* eslint-disable sonarjs/no-duplicate-string */\n\n");

appendFile(filename, `\nexport const CHAINS_IDS = ${JSON.stringify(idToNetwork, null, 2)} as const;\n`);
appendFile(filename, `\nexport const NETWORKS = ${JSON.stringify(networkToId, null, 2)} as const;\n`);
appendFile(filename, `\nexport const NETWORK_FAUCETS = ${JSON.stringify(idToFaucet, null, 2)};\n`);
appendFile(filename, `\nexport const NETWORK_EXPLORERS = ${JSON.stringify(idToExplorers, null, 2)};\n`);
appendFile(filename, `\nexport const NETWORK_CURRENCIES = ${JSON.stringify(idToNativeCurrency, null, 2)};\n`);
appendFile(filename, `\nexport const EXTRA_RPCS = ${JSON.stringify(extraRpcs, null, 2)};\n`);
}
Loading
Loading