Skip to content

Commit

Permalink
fix template according to lint rules. use path.join
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdiallam committed Jan 15, 2025
1 parent e26ee04 commit 2ed2d20
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 81 deletions.
8 changes: 5 additions & 3 deletions packages/viem/scripts/chaingen.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import toml from '@iarna/toml'
import { Eta } from 'eta'
import fs from 'fs'
import path from 'path'

import type { Address, PublicClient } from 'viem'
import { createPublicClient, erc20Abi, http } from 'viem'
import { mainnet, sepolia } from 'viem/chains'

// Hardcoded. Can take a more elaborate approach if needed.
const SUPERCHAIN_REGISTRY_PATH = '../../lib/superchain-registry'
const NETWORKS = ['mainnet', 'sepolia']
const SUPERCHAIN_REGISTRY_PATH = path.join('..', '..', 'lib', 'superchain-registry')

type ChainDefinition = {
chainName: string
Expand Down Expand Up @@ -56,7 +58,7 @@ async function nativeCurrency(

async function main() {
console.log('Running chain generation...')
const eta = new Eta({ views: './scripts/templates', debug: true })
const eta = new Eta({ views: './scripts/templates', debug: true, autoTrim: [false, false] })

const mainnetHttp = process.env.MAINNET_RPC_URL
? [process.env.MAINNET_RPC_URL]
Expand All @@ -78,7 +80,7 @@ async function main() {
console.log(`Generating ${network}`)
const client = network === 'mainnet' ? mainnetClient : sepoliaClient

const configPath = `${SUPERCHAIN_REGISTRY_PATH}/superchain/configs/${network}`
const configPath = path.join(SUPERCHAIN_REGISTRY_PATH, 'superchain', 'configs', network)
const entries = fs
.readdirSync(configPath)
.filter((entry) => !entry.includes('superchain'))
Expand Down
70 changes: 33 additions & 37 deletions packages/viem/scripts/templates/chains.eta
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,46 @@ import type { Chain } from 'viem'
import { defineChain } from 'viem'
import { chainConfig } from 'viem/op-stack'

<% it.chainDefs.forEach(function(chainDef){ %>
<%- it.chainDefs.forEach(function(chainDef){ %>
/**
* Chain Definition for <%= chainDef.chainName %>
* @type {Chain}
* Chain Definition for <%= chainDef.chainName %>
*/
export const <%= chainDef.exportName %>: Chain = defineChain({
...chainConfig,
name: '<%= chainDef.chainName %>',
id: <%= chainDef.chainId %>,
sourceId: <%= chainDef.sourceChainId %>,
nativeCurrency: {
name: '<%= chainDef.nativeCurrency.name %>',
symbol: '<%= chainDef.nativeCurrency.symbol %>',
decimals: <%= chainDef.nativeCurrency.decimals %>
...chainConfig,
name: '<%= chainDef.chainName %>',
id: <%= chainDef.chainId %>,
sourceId: <%= chainDef.sourceChainId %>,
nativeCurrency: {
name: '<%= chainDef.nativeCurrency.name %>',
symbol: '<%= chainDef.nativeCurrency.symbol %>',
decimals: <%= chainDef.nativeCurrency.decimals %>,
},
rpcUrls: {
default: {
http: ['<%= chainDef.rpc %>'],
},
rpcUrls: {
default: {
http: ['<%= chainDef.rpc %>'],
},
},
blockExplorers: {
default: {
name: '<%= chainDef.chainName %> Explorer',
url: '<%= chainDef.explorer %>',
},
blockExplorers: {
default: {
name: '<%= chainDef.chainName %> Explorer',
url: '<%= chainDef.explorer %>',
},
},
contracts: {
...chainConfig.contracts,
<%_ Object.entries(chainDef.l1Addresses).forEach(function([name, address]){ %>
<%= name %>: {
<%= chainDef.sourceChainId %>: {
address: '<%= address %>',
},
},
contracts: {
...chainConfig.contracts,
<% Object.entries(chainDef.l1Addresses).forEach(function([name, address]){ _%>
<%= name %>: {
<%= chainDef.sourceChainId %>: {
address: '<%= address %>',
}
},
<% }) %>

}
<%_ }) %>
},
})

<% }) _%>
<% }) -%>

export const <%= it.network %>Chains = [
<% it.chainDefs.forEach(function(chainDef){ _%>
<%= chainDef.exportName %>,
<% }) %>

<%_ it.chainDefs.forEach(function(chainDef){ %>
<%= chainDef.exportName %>,
<%_ }) %>
]
24 changes: 1 addition & 23 deletions packages/viem/src/chains/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { chainConfig } from 'viem/op-stack'

/**
* Chain Definition for arena-z
* @type {Chain}
*/
export const arenaZMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -65,7 +64,6 @@ export const arenaZMainnet: Chain = defineChain({

/**
* Chain Definition for Automata Mainnet
* @type {Chain}
*/
export const automataMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -130,7 +128,6 @@ export const automataMainnet: Chain = defineChain({

/**
* Chain Definition for Base
* @type {Chain}
*/
export const baseMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -195,7 +192,6 @@ export const baseMainnet: Chain = defineChain({

/**
* Chain Definition for Cyber Mainnet
* @type {Chain}
*/
export const cyberMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -260,7 +256,6 @@ export const cyberMainnet: Chain = defineChain({

/**
* Chain Definition for Ethernity
* @type {Chain}
*/
export const ethernityMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -325,7 +320,6 @@ export const ethernityMainnet: Chain = defineChain({

/**
* Chain Definition for Funki
* @type {Chain}
*/
export const funkiMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -390,7 +384,6 @@ export const funkiMainnet: Chain = defineChain({

/**
* Chain Definition for Ink
* @type {Chain}
*/
export const inkMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -450,7 +443,6 @@ export const inkMainnet: Chain = defineChain({

/**
* Chain Definition for Lisk
* @type {Chain}
*/
export const liskMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -515,7 +507,6 @@ export const liskMainnet: Chain = defineChain({

/**
* Chain Definition for Lyra Chain
* @type {Chain}
*/
export const lyraMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -575,7 +566,6 @@ export const lyraMainnet: Chain = defineChain({

/**
* Chain Definition for Metal L2
* @type {Chain}
*/
export const metalMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -635,7 +625,6 @@ export const metalMainnet: Chain = defineChain({

/**
* Chain Definition for Mode
* @type {Chain}
*/
export const modeMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -695,7 +684,6 @@ export const modeMainnet: Chain = defineChain({

/**
* Chain Definition for OP Mainnet
* @type {Chain}
*/
export const opMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -755,7 +743,6 @@ export const opMainnet: Chain = defineChain({

/**
* Chain Definition for Orderly Mainnet
* @type {Chain}
*/
export const orderlyMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -815,7 +802,6 @@ export const orderlyMainnet: Chain = defineChain({

/**
* Chain Definition for RACE Mainnet
* @type {Chain}
*/
export const raceMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -875,7 +861,6 @@ export const raceMainnet: Chain = defineChain({

/**
* Chain Definition for Redstone
* @type {Chain}
*/
export const redstoneMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -940,7 +925,6 @@ export const redstoneMainnet: Chain = defineChain({

/**
* Chain Definition for Shape
* @type {Chain}
*/
export const shapeMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -1005,7 +989,6 @@ export const shapeMainnet: Chain = defineChain({

/**
* Chain Definition for Superseed
* @type {Chain}
*/
export const sseedMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -1070,7 +1053,6 @@ export const sseedMainnet: Chain = defineChain({

/**
* Chain Definition for Swan Chain Mainnet
* @type {Chain}
*/
export const swanMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -1135,7 +1117,6 @@ export const swanMainnet: Chain = defineChain({

/**
* Chain Definition for Swellchain
* @type {Chain}
*/
export const swellMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -1195,7 +1176,6 @@ export const swellMainnet: Chain = defineChain({

/**
* Chain Definition for Binary Mainnet
* @type {Chain}
*/
export const tbnMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -1260,7 +1240,6 @@ export const tbnMainnet: Chain = defineChain({

/**
* Chain Definition for World Chain
* @type {Chain}
*/
export const worldchainMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -1325,7 +1304,6 @@ export const worldchainMainnet: Chain = defineChain({

/**
* Chain Definition for Zora
* @type {Chain}
*/
export const zoraMainnet: Chain = defineChain({
...chainConfig,
Expand Down Expand Up @@ -1406,4 +1384,4 @@ export const mainnetChains = [
tbnMainnet,
worldchainMainnet,
zoraMainnet,
]
]
Loading

0 comments on commit 2ed2d20

Please sign in to comment.