Skip to content

Commit 6b935e0

Browse files
committed
feat: allow chain id in contracts queries
1 parent 7da7dcd commit 6b935e0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/chains/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export const alchemyRPCs: Record<number, RPCGenerator> = {
1111
[viem.berachain.id]: (apiKey) => `https://berachain-mainnet.g.alchemy.com/v2/${apiKey}`,
1212
[viem.blast.id]: (apiKey) => `https://blast-mainnet.g.alchemy.com/v2/${apiKey}`,
1313
[viem.bsc.id]: (apiKey) => `https://bnb-mainnet.g.alchemy.com/v2/${apiKey}`,
14-
[viem.mainnet.id]: (apiKey) => `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`,
1514
[viem.gnosis.id]: (apiKey) => `https://gnosis-mainnet.g.alchemy.com/v2/${apiKey}`,
1615
[viem.linea.id]: (apiKey) => `https://linea-mainnet.g.alchemy.com/v2/${apiKey}`,
16+
[viem.mainnet.id]: (apiKey) => `https://eth-mainnet.g.alchemy.com/v2/${apiKey}`,
1717
[viem.optimism.id]: (apiKey) => `https://opt-mainnet.g.alchemy.com/v2/${apiKey}`,
1818
[viem.polygon.id]: (apiKey) => `https://polygon-mainnet.g.alchemy.com/v2/${apiKey}`,
1919
[viem.ronin.id]: (apiKey) => `https://ronin-mainnet.g.alchemy.com/v2/${apiKey}`,

src/contracts/queries.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ export const contractsQueries = {
4646
},
4747
/**
4848
* Get many contracts.
49-
* - no options ⇒ all
50-
* - {protocol} ⇒ all for that protocol
51-
* - {protocol, chainId} ⇒ filtered by chain
52-
* - {release} ⇒ all deployments of that release
53-
* - {release, chainId} ⇒ that slice of deployments
49+
* - no options ⇒ all
50+
* - { protocol } ⇒ all for that protocol
51+
* - { protocol, chainId } ⇒ filtered by chain
52+
* - { release } ⇒ all deployments of that release
53+
* - { release, chainId } ⇒ that slice of deployments
5454
*/
5555
getAll: (opts?: {
5656
chainId?: number;
@@ -84,6 +84,13 @@ export const contractsQueries = {
8484
return _.flatMap(deps, (d) => d.contracts);
8585
}
8686

87+
// by chain id
88+
if (chainId) {
89+
const deps = _.flatMap(releasesQueries.getAll(), (r) => r.deployments);
90+
const filtered = _.filter(deps, { chainId });
91+
return _.flatMap(filtered, (d) => d.contracts);
92+
}
93+
8794
// no filters → all
8895
return _.flatMap(releasesQueries.getAll(), (r) => r.deployments.flatMap((d) => d.contracts));
8996
},

0 commit comments

Comments
 (0)