Created
May 14, 2025 18:29
-
-
Save PaulRBerg/1fc300956c3bb052e2b43e2192da59f2 to your computer and use it in GitHub Desktop.
Prototype of a script that generates the networks by using the `extractContract` function from The Graph manifest code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { type Sablier, Version, getChainName, queries, releasesByProtocol } from "@sablier/deployments"; | |
import supportedChains from "@src/chains"; | |
import type { Config } from "@src/envio-config/types"; | |
import { extractContract } from "@src/graph-manifest/sources/creators"; | |
import { sanitizeName } from "@src/helpers"; | |
import type { ContractMap, IndexedProtocol } from "@src/types"; | |
import logger, { logAndThrow, thrower } from "@src/winston"; | |
import _ from "lodash"; | |
export function createNetworks2( | |
contractMap: ContractMap<Sablier.Version>, | |
protocol: IndexedProtocol, | |
): Config.Network[] { | |
const networks: Config.Network[] = []; | |
const foo: Record<number, Record<string, Config.NetworkContract>> = {}; | |
contractMap.flatMap(({ contractName, isTemplate, versions }) => | |
versions.flatMap((version) => { | |
const release = queries.releases.getByProtocolAndVersion(protocol, version); | |
if (!release) { | |
thrower.releaseNotFound(protocol, version); | |
} | |
supportedChains.flatMap((chain) => { | |
const contract = extractContract({ release, chainId: chain.id, contractName, isTemplate }); | |
if (!contract) return []; | |
_.set(foo, [chain.id, contractName], contract); | |
}); | |
}), | |
); | |
const mergedContracts: Record<number, Config.NetworkContract[]> = _.merge({}, ..._.values(foo)); | |
for (const chain of supportedChains) { | |
networks.push({ | |
id: chain.id, | |
start_block: 0, | |
contracts: mergedContracts[chain.id], | |
}); | |
} | |
return networks; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment