-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: prepare release #941
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getLocalNetworksConfig, getSafeDeploymentNetworks } from './utils' | ||
|
||
/** | ||
* Checks if there are any differences between the local EIP-3770 network configurations and the safe deployment networks. | ||
* | ||
* @function checkConfigDiff | ||
* @returns {void} - nothing, just throws an error if there are any discrepancies | ||
*/ | ||
function checkConfigDiff() { | ||
const safeDeployments = getSafeDeploymentNetworks() | ||
const localNetworks = getLocalNetworksConfig() | ||
|
||
const chainIdsMissing = safeDeployments.filter((chainId) => !localNetworks.includes(chainId)) | ||
if (chainIdsMissing.length > 0) { | ||
const errorMessage = `EIP-3770 local config is missing chainIds: ${chainIdsMissing}\nPlease run 'yarn workspace @safe-global/protocol-kit update-safe-deployments` | ||
throw new Error(errorMessage) | ||
} | ||
|
||
const chainIdsExtra = localNetworks.filter((chainId) => !safeDeployments.includes(chainId)) | ||
if (chainIdsExtra.length > 0) { | ||
const errorMessage = `EIP-3770 local config has not required chainIds: ${chainIdsExtra}` | ||
throw new Error(errorMessage) | ||
} | ||
} | ||
|
||
checkConfigDiff() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getChainShortName } from './utils' | ||
import { networks } from '../../src/utils/eip-3770/config' | ||
|
||
/** | ||
* Checks the short names of local EIP-3770 networks to match their corresponding chain short names. | ||
* | ||
* @async | ||
* @function checkShortNameIntegrity | ||
* @returns {void} - nothing, just prints those chains where the name is not the same. | ||
*/ | ||
async function checkShortNameIntegrity() { | ||
for (const network of networks) { | ||
try { | ||
const shortName = await getChainShortName(network.chainId.toString()) | ||
if (network.shortName !== shortName) { | ||
// It just prints the chain that is not aligned so we can check if manual action is necessary. | ||
console.log(`Update ${network.chainId} from '${network.shortName}' to '${shortName}'`) | ||
} | ||
} catch (error) { | ||
console.log(`EIP-3770 Failed to retrieve chain name for ${network.chainId}`) | ||
} | ||
} | ||
|
||
console.log('Local network configuration checked successfully!') | ||
} | ||
|
||
checkShortNameIntegrity() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import fs from 'fs' | ||
import { getChainShortName, getLocalNetworksConfig, getSafeDeploymentNetworks } from './utils' | ||
import { networks } from '../../src/utils/eip-3770/config' | ||
|
||
interface NetworkShortName { | ||
shortName: string | ||
chainId: bigint | ||
} | ||
|
||
/** | ||
* Updates the local networks array in the configuration file. | ||
* | ||
* @param {NetworkShortName[]} networks - The full list of networks. | ||
*/ | ||
|
||
function updateLocalNetworks(networks: NetworkShortName[]) { | ||
const path = 'src/utils/eip-3770/config.ts' | ||
|
||
fs.readFile(path, (err, data) => { | ||
if (err) { | ||
console.error(err) | ||
return | ||
} | ||
|
||
const content = data.toString() | ||
const startIndex = | ||
content.indexOf('export const networks: NetworkShortName[] = [') + | ||
'export const networks: NetworkShortName[] = ['.length | ||
const endIndex = content.indexOf(']\n\nif (process.env.TEST_NETWORK ===') | ||
|
||
const sortedNetworks = networks | ||
.sort((a, b) => Number(a.chainId - b.chainId)) | ||
.map( | ||
(network, index) => | ||
` { chainId: ${network.chainId}n, shortName: '${network.shortName}' }${index === networks.length - 1 ? '' : ','}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with this thing is that, because we are assembling bits of content in different statements, its hard to understand the outgoing structure. Life would be much kinder to us if it looked more like "stuffing" a template (if possible)... e.g.:
|
||
) | ||
.join('\n') | ||
|
||
fs.writeFile( | ||
path, | ||
`${content.substring(0, startIndex)}\n${sortedNetworks}\n${content.substring(endIndex)}`, | ||
(err) => { | ||
if (err) { | ||
console.error(err) | ||
} else { | ||
console.log('Networks array updated successfully!') | ||
} | ||
} | ||
) | ||
}) | ||
} | ||
|
||
/** | ||
* Checks and updates the local networks configuration file. | ||
*/ | ||
async function checkAndUpdate() { | ||
const safeDeployments = getSafeDeploymentNetworks() | ||
const localNetworks = getLocalNetworksConfig() | ||
|
||
const chainIdsMissing = safeDeployments.filter((chainId) => !localNetworks.includes(chainId)) | ||
if (chainIdsMissing.length > 0) { | ||
const updateNetworks = [...networks] | ||
for (const chainId of chainIdsMissing) { | ||
try { | ||
const shortName = await getChainShortName(chainId) | ||
console.log(`Adding ${chainId} with shortName ${shortName}`) | ||
updateNetworks.push({ chainId: BigInt(chainId), shortName: shortName }) | ||
} catch (error) { | ||
throw new Error(`EIP-3770 Failed to retrieve chain name for ${chainId}`) | ||
} | ||
} | ||
|
||
updateLocalNetworks(updateNetworks) | ||
} | ||
} | ||
|
||
checkAndUpdate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the comment on the right-hand side still correct? You could use the viem#parseEther and remove the comment altogether.