-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create build script to gen TS code for chain metadata
- Loading branch information
Showing
8 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ yarn-error.log* | |
*.tsbuildinfo | ||
|
||
# build artifacts | ||
dist | ||
dist | ||
tmp |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* An enumeration of chains managed by the Hyperlane core team. | ||
* Hyperlane can be deployed permissionlessly to any chain but for | ||
* convenience the core team maintains some deployments. | ||
*/ | ||
export enum CoreChain { | ||
alfajores = 'alfajores', | ||
ancient8 = 'ancient8', | ||
arbitrum = 'arbitrum', | ||
avalanche = 'avalanche', | ||
base = 'base', | ||
bsc = 'bsc', | ||
bsctestnet = 'bsctestnet', | ||
celo = 'celo', | ||
chiado = 'chiado', | ||
ethereum = 'ethereum', | ||
fuji = 'fuji', | ||
gnosis = 'gnosis', | ||
inevm = 'inevm', | ||
injective = 'injective', | ||
mantapacific = 'mantapacific', | ||
moonbeam = 'moonbeam', | ||
nautilus = 'nautilus', | ||
neutron = 'neutron', | ||
optimism = 'optimism', | ||
plumetestnet = 'plumetestnet', | ||
polygon = 'polygon', | ||
polygonzkevm = 'polygonzkevm', | ||
proteustestnet = 'proteustestnet', | ||
scroll = 'scroll', | ||
scrollsepolia = 'scrollsepolia', | ||
sepolia = 'sepolia', | ||
solana = 'solana', | ||
solanadevnet = 'solanadevnet', | ||
solanatestnet = 'solanatestnet', | ||
eclipsetestnet = 'eclipsetestnet', | ||
viction = 'viction', | ||
} | ||
|
||
export type CoreChainName = keyof typeof CoreChain; | ||
|
||
export const CoreMainnets: Array<CoreChainName> = [ | ||
CoreChain.arbitrum, | ||
CoreChain.ancient8, | ||
CoreChain.avalanche, | ||
CoreChain.bsc, | ||
CoreChain.celo, | ||
CoreChain.ethereum, | ||
CoreChain.neutron, | ||
CoreChain.mantapacific, | ||
CoreChain.moonbeam, | ||
CoreChain.optimism, | ||
CoreChain.polygon, | ||
CoreChain.gnosis, | ||
CoreChain.base, | ||
CoreChain.scroll, | ||
CoreChain.polygonzkevm, | ||
CoreChain.injective, | ||
CoreChain.inevm, | ||
CoreChain.viction, | ||
// CoreChains.solana, | ||
]; | ||
|
||
export const CoreTestnets: Array<CoreChainName> = [ | ||
CoreChain.alfajores, | ||
CoreChain.bsctestnet, | ||
CoreChain.chiado, | ||
CoreChain.fuji, | ||
CoreChain.plumetestnet, | ||
CoreChain.scrollsepolia, | ||
CoreChain.sepolia, | ||
CoreChain.solanadevnet, | ||
CoreChain.solanatestnet, | ||
CoreChain.eclipsetestnet, | ||
]; | ||
|
||
export const CoreChains: Array<CoreChainName> = [ | ||
...CoreMainnets, | ||
...CoreTestnets, | ||
]; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { pick } from '@hyperlane-xyz/utils'; | ||
import fs from 'fs'; | ||
import { parse } from 'yaml'; | ||
import { CoreChains } from '../chains/core'; | ||
|
||
function genJsExport(data, exportName) { | ||
return `export const ${exportName} = ${JSON.stringify(data, null, 2)};`; | ||
} | ||
|
||
let chainMetadata = {}; | ||
let chainAddresses = {}; | ||
|
||
console.log('Parsing and copying chain data'); | ||
for (const file of fs.readdirSync('./chains')) { | ||
const inDirPath = `./chains/${file}`; | ||
const assetOutPath = `./dist/chains/${file}`; | ||
// generated ts files to to the tmp dir so they can be compiled along with other generated code | ||
const tsOutPath = `./tmp/chains/${file}`; | ||
const stat = fs.statSync(`${inDirPath}`); | ||
if (!stat.isDirectory()) continue; | ||
|
||
const metadata = parse(fs.readFileSync(`${inDirPath}/metadata.yaml`, 'utf8')); | ||
chainMetadata[metadata.name] = metadata; | ||
fs.mkdirSync(`${assetOutPath}`, { recursive: true }); | ||
fs.mkdirSync(`${tsOutPath}`, { recursive: true }); | ||
fs.copyFileSync(`${inDirPath}/metadata.yaml`, `${assetOutPath}/metadata.yaml`); | ||
fs.writeFileSync(`${assetOutPath}/metadata.json`, JSON.stringify(metadata, null, 2), 'utf8'); | ||
fs.writeFileSync(`${tsOutPath}/metadata.ts`, genJsExport(metadata, 'metadata'), 'utf8'); | ||
|
||
if (fs.existsSync(`${inDirPath}/addresses.yaml`)) { | ||
const addresses = parse(fs.readFileSync(`${inDirPath}/addresses.yaml`, 'utf8')); | ||
chainAddresses[metadata.name] = addresses; | ||
fs.copyFileSync(`${inDirPath}/addresses.yaml`, `${assetOutPath}/addresses.yaml`); | ||
fs.writeFileSync(`${assetOutPath}/addresses.json`, JSON.stringify(addresses, null, 2), 'utf8'); | ||
fs.writeFileSync(`${tsOutPath}/addresses.ts`, genJsExport(addresses, 'addresses'), 'utf8'); | ||
} | ||
|
||
fs.copyFileSync(`${inDirPath}/logo.svg`, `${assetOutPath}/logo.svg`); | ||
} | ||
|
||
console.log('Assembling typescript code'); | ||
fs.mkdirSync(`./tmp`, { recursive: true }); | ||
fs.copyFileSync(`./chains/core.ts`, `./tmp/index.ts`); | ||
fs.writeFileSync(`./tmp/chainMetadata.ts`, genJsExport(chainMetadata, 'chainMetadata'), 'utf8'); | ||
const coreChainMetadata = pick<any>(chainMetadata, CoreChains); | ||
fs.writeFileSync( | ||
`./tmp/coreChainMetadata.ts`, | ||
genJsExport(coreChainMetadata, 'coreChainMetadata'), | ||
'utf8', | ||
); | ||
fs.appendFileSync(`./tmp/index.ts`, `\nexport { chainMetadata } from './chainMetadata.js';\n`); | ||
fs.appendFileSync( | ||
`./tmp/index.ts`, | ||
`export { coreChainMetadata } from './coreChainMetadata.js';\n`, | ||
); | ||
for (const name of Object.keys(chainMetadata)) { | ||
fs.appendFileSync( | ||
`./tmp/index.ts`, | ||
`export { metadata as ${name} } from './chains/${name}/metadata.js';\n`, | ||
); | ||
if (chainAddresses[name]) { | ||
fs.appendFileSync( | ||
`./tmp/index.ts`, | ||
`export { addresses as ${name}Addresses } from './chains/${name}/addresses.js';\n`, | ||
); | ||
} | ||
} |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"declarationMap": false, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"incremental": false, | ||
"lib": [ | ||
"ES2015", "ES2016", "ES2017", "ES2018", | ||
"ES2019", "ES2020","ES2021", "DOM" | ||
], | ||
"module": "nodenext", | ||
"moduleResolution": "nodenext", | ||
"noEmitOnError": false, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"outDir": "./dist/", | ||
"preserveSymlinks": true, | ||
"preserveWatchOutput": true, | ||
"pretty": false, | ||
"resolveJsonModule": true, | ||
"rootDir": "./tmp", | ||
"skipLibCheck": true, | ||
"sourceMap": false, | ||
"strict": true, | ||
"target": "es2022", | ||
}, | ||
"include": ["./tmp/**/*.ts"] | ||
} |