Skip to content

Commit

Permalink
Added legacy data compare script to make sure we migrate every chain …
Browse files Browse the repository at this point in the history
…correctly.
  • Loading branch information
DominicF96 committed May 7, 2024
1 parent c7c9650 commit 3d59989
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"generate:types": "bun run generate:type_graphid && bun run generate:type_pinaxid && bun run format",
"generate:type_graphid": "bun ./scripts/generate/V2/type_graphid.ts",
"generate:type_pinaxid": "bun ./scripts/generate/V2/type_pinaxid.ts",
"generate:match_legacy_check": "bun ./scripts/generate/V2/match_legacy_data.ts",
"generate_v1": "npm run generate_v1:data",
"generate_v1:data": "node ./scripts/generate/V1/data_json.js",
"generate_v1:types": "npm run generate_v1:type_graphid && npm run generate_v1:type_pinaxid && npm run format",
Expand Down
42 changes: 42 additions & 0 deletions scripts/generate/V2/match_legacy_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from 'fs';

// Read and parse the JSON files
const dataLegacy = JSON.parse(
fs.readFileSync('./dist/data_legacy.json', 'utf8'),
);
const data = JSON.parse(fs.readFileSync('./dist/data.json', 'utf8'));

// Create a new array for the missing chain IDs
let missingChainIDs = [];

// Iterate over the chains in data_legacy.json
for (let legacyChain of dataLegacy) {
// Find the corresponding chain in data.json
let chain = data.find((c: any) => c.id === legacyChain.id);

// If the chain doesn't exist in data.json, check the mainnet of the chain
if (!chain) {
let mainnetChain = data.find((c: any) => c.id === legacyChain.mainnet);
if (mainnetChain) {
// Check both testnets and consensus_layers arrays within that mainnet
if (
mainnetChain.testnets?.find((t: any) => t.id === legacyChain.id) !==
undefined
) {
continue;
}
if (
mainnetChain.consensus_layers?.find(
(c: any) => c.id === legacyChain.id,
) !== undefined
) {
continue;
}
}
// If the chain doesn't exist in data.json, add the legacy chain ID to the missingChainIDs array
missingChainIDs.push(legacyChain.id);
}
}

// Log the missing chain IDs
console.log(missingChainIDs);
2 changes: 1 addition & 1 deletion src/types/graph.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is auto-generated on pre-commit to avoid maintaining it.
// Do not modify manually as it will be overwritten.
// Last generation on 5/7/2024, 4:33:43 PM.
// Last generation on 5/7/2024, 4:50:21 PM.
export type GraphID =
| 'arbitrum-one'
| 'arbitrum-sepolia'
Expand Down
2 changes: 1 addition & 1 deletion src/types/pinax.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is auto-generated on pre-commit to avoid maintaining it / circular dependencies.
// Do not modify manually as it will be overwritten.
// Last generation on 5/7/2024, 4:33:43 PM.
// Last generation on 5/7/2024, 4:50:22 PM.
export type PinaxID =
| 'arbgoerli'
| 'arbsepolia'
Expand Down

0 comments on commit 3d59989

Please sign in to comment.