Skip to content

Commit 323f68a

Browse files
Zalensnlordell
andauthored
Use DeFi Llama Chainlist (#1158)
We require that the chain appears on https://chainlist.org/, and previously, this meant that the chain was included in the ethereum-lists/chains repository. However, since that repository is no longer actively maintained, and since then DeFi Llama has added mechanisms for "additional chains" to their DeFiLlama/chainlist repository, which is the code behind https://chainlist.org/. This PR changes our scripts to use the Chainlist.org API for checking if a network is listed or not (instead of the ethereum-lists/chains repository). --------- Co-authored-by: Nicholas Rodrigues Lordello <nick@safe.global>
1 parent ded1c62 commit 323f68a

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Add new chain
22

3-
> Template to provide information about the new chain. Only add extra information in the bottom section. Ensure that the contracts are deployed on the chain, if not deploy with [safe-contracts](https://github.com/safe-global/safe-contracts). Only **one** chain ID, **one** Safe version and **one** deployment type per PR. The RPC will be taken from [ethereum-lists/chains](https://github.com/ethereum-lists/chains). This entire paragraph should be deleted.
3+
> Template to provide information about the new chain. Only add extra information in the bottom section. Ensure that the contracts are deployed on the chain, if not deploy with [safe-contracts](https://github.com/safe-global/safe-contracts). Only **one** chain ID, **one** Safe version and **one** deployment type per PR. The RPC will be taken from [DefiLlama's ChainList](https://chainlist.org/). This entire paragraph should be deleted.
44
55
Please fill the following form:
66

bin/github-review.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,23 @@ if [[ -z $chainid ]]; then
4545
echo "ERROR: Chain ID not specified as per the PR Template" 1>&2
4646
exit 1
4747
fi
48-
chainInfo="https://raw.githubusercontent.com/ethereum-lists/chains/refs/heads/master/_data/chains/eip155-$chainid.json"
49-
rpc="$(curl -sfL "$chainInfo" | jq -r '.rpc[0]')"
48+
49+
# Fetch RPC from DefiLlama's chainlist
50+
if ! chainlist_response="$(curl -sfL 'https://chainlist.org/rpcs.json')"; then
51+
echo "ERROR: Failed to fetch DeFiLlama ChainList" 1>&2
52+
exit 1
53+
fi
54+
55+
# Parse the chainlist response
56+
if ! chainlist=$(echo "$chainlist_response" | jq -e '.'); then
57+
echo "ERROR: DefiLlama's ChainList returned invalid JSON" 1>&2
58+
exit 1
59+
fi
60+
61+
# Extract RPC for the specified chain ID using jq
62+
rpc="$(echo "$chainlist" | jq --arg C "$chainid" -r '.[] | select((.chainId | tostring) == $C) | .rpc[0].url')"
5063
if [[ -z $rpc ]]; then
51-
echo "ERROR: RPC not fetched correctly from the ethereum-lists" 1>&2
64+
echo "ERROR: Chain is not listed on DefiLlama's ChainList" 1>&2
5265
exit 1
5366
fi
5467
version="$(gh pr diff $pr --name-only | sed -nE 's|^src/assets/v([0-9\.]*)/.*$|\1|p' | sort -u)"
@@ -89,4 +102,3 @@ git restore --ignore-unmerged -- src/assets
89102

90103
# NOTE/TODO
91104
# - We should still manually verify there is no removal of deployment types for a single chain.
92-
# - Getting the RPC from the Chainlist website instead of looking based on the provided RPC: https://github.com/safe-global/safe-deployments/pull/683#discussion_r1668555849

scripts/review/verifyDeployment.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,21 @@ async function main() {
4646
debug('Parsed options:');
4747
debug(options);
4848

49-
await fetch(`https://chainlist.org/chain/${options.chainId}`).then((response) => {
50-
if (!response.ok) {
51-
debug(response);
52-
throw new Error(`chain is not registered on Chainlist`);
53-
}
54-
});
55-
debug(`chain ${options.chainId} exists on Chainlist`);
49+
// Verify chain exists in DefiLlama's chainlist
50+
const response = await fetch('https://chainlist.org/rpcs.json');
51+
if (!response.ok) {
52+
debug(`fetching chain list failed with HTTP status ${response.status}`);
53+
throw new Error(`Failed to fetch chainlist from DefiLlama`);
54+
}
55+
const chainlist = (await response.json()) as Array<{ chainId: number; rpcs: string[] }>;
56+
if (!Array.isArray(chainlist)) {
57+
throw new Error('Invalid response format from DefiLlama chainlist');
58+
}
59+
const chainExists = chainlist.some((chain) => `${chain.chainId}` === options.chainId);
60+
if (!chainExists) {
61+
throw new Error(`Chain ${options.chainId} is not registered on DefiLlama's ChainList`);
62+
}
63+
debug(`chain ${options.chainId} exists on DefiLlama's ChainList`);
5664

5765
const provider = new ethers.JsonRpcProvider(options.rpc);
5866
const { chainId } = await provider.getNetwork();

0 commit comments

Comments
 (0)