|
1 | 1 | import fs from "fs";
|
2 | 2 | import path from "path";
|
| 3 | +import * as existingDeployments from "../deployments/deployments.json"; |
3 | 4 |
|
| 5 | +export type Deployments = Record<string, Record<string, { address: string; blockNumber: number }>>; |
4 | 6 | // Prunes the hardhat export file sent to the cache directory to only contain the deployment addresses of each contract
|
5 | 7 | // over the network of chains the Across v2 contracts are deployed on. Meant to be run as part of a publish process.
|
6 | 8 | export async function run(): Promise<void> {
|
7 | 9 | try {
|
8 | 10 | const deploymentExport = require("../cache/massExport.json");
|
9 | 11 | const castExport = deploymentExport as any;
|
10 | 12 | console.log("Generating exports on the following networks(if they have deployments)", Object.keys(castExport));
|
11 |
| - const processedOutput: { [chainId: string]: { [name: string]: { address: string; blockNumber: number } } } = {}; |
| 13 | + const processedOutput: Deployments = {}; |
12 | 14 | Object.keys(castExport).forEach((chainId) => {
|
13 | 15 | if (castExport[chainId][0])
|
14 | 16 | Object.keys(castExport[chainId][0].contracts).forEach((contractName) => {
|
15 | 17 | if (!processedOutput[chainId]) processedOutput[chainId] = {};
|
16 | 18 | const address = castExport[chainId][0]?.contracts[contractName].address;
|
17 | 19 | const blockNumber = findDeploymentBlockNumber(castExport[chainId][0].name, contractName);
|
| 20 | + const existingBlockNumber = (existingDeployments as Deployments)[chainId][contractName].blockNumber; |
| 21 | + console.log( |
| 22 | + `Not updating ${contractName} as it has a later block number set in deployments.json than the one in deployments/${contractName}.json` |
| 23 | + ); |
| 24 | + const hasLaterBlockNumber = existingBlockNumber > blockNumber; |
| 25 | + if (hasLaterBlockNumber) return; // If we have already found a later block number for this contract, then ignore this one. |
| 26 | + // As its likely that we manually updated the `deployments` file and we don't want to override it. |
18 | 27 | if (/.*_SpokePool/.test(contractName)) contractName = "SpokePool"; // Strip the network name from the spoke pool in the contractName.
|
19 | 28 | processedOutput[chainId][contractName] = { address, blockNumber };
|
20 | 29 | });
|
|
0 commit comments