Skip to content

Commit

Permalink
auto-add rpc providers from chainlist
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Mar 2, 2023
1 parent 1d23453 commit 9495479
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions patchAndPublish.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
git checkout master
git pull
ts-node src/util/updateProviderList.ts
npm run test
if [[ $? -ne 0 ]] ; then
echo "Unit test failed, fix it before publishing new version"
exit 1
fi
npm version patch
git push
rm -rf build
rm LICENSE
npm publish
git checkout master -- LICENSE
git checkout master -- src/providers.json
git push --tags
1 change: 1 addition & 0 deletions src/abi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ test("bsc multicall", async () => {
});

import largeMulticall from './largeMulticall'
jest.setTimeout(60 * 1000)
test("order is maintained in multicall", async () => {
const result = await multiCall(largeMulticall as any);
for (let i = 0; i < largeMulticall.calls.length; i++) {
Expand Down
30 changes: 30 additions & 0 deletions src/util/updateProviderList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import providerList from '../providers.json'
import fs from 'fs'
import fetch from "node-fetch";

function fetchJson(url: string) {
return fetch(url).then((res) => res.json());
}

async function main() {
let chainData = await fetchJson('https://chainid.network/chains.json')
const existingChainIds = new Set(Object.values(providerList).map(i => i.chainId))
const existingChainNames = new Set(Object.keys(providerList))
chainData = chainData
.filter((i: any) => i.rpc.length)
.filter((i: any) => !i.status || i.status === 'active')
.filter((i: any) => i.shortName)
.filter((i: any) => !existingChainIds.has(i.chainId))
.filter((i: any) => !existingChainNames.has(i.shortName))
const newList = {...providerList} as any
chainData.forEach((i: any) => {
newList[i.shortName.toLowerCase()] = {
rpc: i.rpc,
chainId: i.chainId
}
})
fs.writeFileSync(__dirname+'/../providers.json', JSON.stringify(newList))
}

main()

0 comments on commit 9495479

Please sign in to comment.