Skip to content

Commit db95804

Browse files
committed
Import entire PUBLIC_NETWORKS
1 parent ff0e925 commit db95804

File tree

3 files changed

+406
-95
lines changed

3 files changed

+406
-95
lines changed

script/utils/Constants.sol

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -218,61 +218,39 @@ contract Constants is Script {
218218
}
219219

220220
// Circle domain IDs mapping
221-
function getCircleDomainId(uint256 chainId) public view returns (uint32) {
222-
return uint32(vm.parseJsonUint(file, string.concat(".CIRCLE_DOMAIN_IDs.", vm.toString(chainId))));
221+
function getCircleDomainId(uint256 chainId) public view returns (uint256) {
222+
// return uint32(vm.parseJsonUint(file, string.concat(".CIRCLE_DOMAIN_IDs.", vm.toString(chainId))));
223+
int256 cctpDomain = vm.parseJsonInt(
224+
file,
225+
string.concat(".PUBLIC_NETWORKS.", vm.toString(chainId), ".cctpDomain")
226+
);
227+
if (cctpDomain == -1) {
228+
revert("Circle domain ID not found");
229+
}
230+
return uint256(cctpDomain);
231+
}
232+
233+
function getOftEid(uint256 chainId) public view returns (uint256) {
234+
int256 oftEid = vm.parseJsonInt(file, string.concat(".PUBLIC_NETWORKS.", vm.toString(chainId), ".oftEid"));
235+
if (oftEid == -1) {
236+
revert("OFT EID not found");
237+
}
238+
return uint256(oftEid);
223239
}
224240

225241
// Get WETH address for any supported chain
226242
function getWETHAddress(uint256 chainId) public view returns (address) {
227243
return vm.parseJsonAddress(file, string.concat(".WETH.", vm.toString(chainId)));
228244
}
229245

230-
// Helper function to convert chain ID to chain name
231-
function _getChainName(uint256 chainId) internal view returns (string memory) {
232-
if (chainId == getChainId("MAINNET")) return "MAINNET";
233-
if (chainId == getChainId("SEPOLIA")) return "SEPOLIA";
234-
if (chainId == getChainId("ARBITRUM")) return "ARBITRUM";
235-
if (chainId == getChainId("ARBITRUM_SEPOLIA")) return "ARBITRUM_SEPOLIA";
236-
if (chainId == getChainId("BSC")) return "BSC";
237-
if (chainId == getChainId("POLYGON")) return "POLYGON";
238-
if (chainId == getChainId("POLYGON_AMOY")) return "POLYGON_AMOY";
239-
if (chainId == getChainId("ZK_SYNC")) return "ZK_SYNC";
240-
if (chainId == getChainId("OPTIMISM")) return "OPTIMISM";
241-
if (chainId == getChainId("OPTIMISM_SEPOLIA")) return "OPTIMISM_SEPOLIA";
242-
if (chainId == getChainId("BASE")) return "BASE";
243-
if (chainId == getChainId("BASE_SEPOLIA")) return "BASE_SEPOLIA";
244-
if (chainId == getChainId("LENS")) return "LENS";
245-
if (chainId == getChainId("LENS_SEPOLIA")) return "LENS_SEPOLIA";
246-
if (chainId == getChainId("LINEA")) return "LINEA";
247-
if (chainId == getChainId("SCROLL_SEPOLIA")) return "SCROLL_SEPOLIA";
248-
if (chainId == getChainId("SCROLL")) return "SCROLL";
249-
if (chainId == getChainId("UNICHAIN")) return "UNICHAIN";
250-
if (chainId == getChainId("UNICHAIN_SEPOLIA")) return "UNICHAIN_SEPOLIA";
251-
if (chainId == getChainId("ALEPH_ZERO")) return "ALEPH_ZERO";
252-
if (chainId == getChainId("BLAST")) return "BLAST";
253-
if (chainId == getChainId("BLAST_SEPOLIA")) return "BLAST_SEPOLIA";
254-
if (chainId == getChainId("BOBA")) return "BOBA";
255-
if (chainId == getChainId("INK")) return "INK";
256-
if (chainId == getChainId("LISK")) return "LISK";
257-
if (chainId == getChainId("LISK_SEPOLIA")) return "LISK_SEPOLIA";
258-
if (chainId == getChainId("MODE")) return "MODE";
259-
if (chainId == getChainId("MODE_SEPOLIA")) return "MODE_SEPOLIA";
260-
if (chainId == getChainId("REDSTONE")) return "REDSTONE";
261-
if (chainId == getChainId("SONEIUM")) return "SONEIUM";
262-
if (chainId == getChainId("WORLD_CHAIN")) return "WORLD_CHAIN";
263-
if (chainId == getChainId("ZORA")) return "ZORA";
264-
revert("Unsupported chain ID");
265-
}
266-
267246
/**
268247
* @notice Get L2 address from constants.json
269248
* @param chainId The chain ID to get the address for
270249
* @param addressType The type of address to get (e.g., "l2GatewayRouter", "cctpTokenMessenger")
271250
* @return The L2 address
272251
*/
273252
function getL2Address(uint256 chainId, string memory addressType) public view returns (address) {
274-
string memory chainName = _getChainName(chainId);
275-
string memory jsonPath = string(abi.encodePacked(".L2_ADDRESS_MAP.", chainName, ".", addressType));
253+
string memory jsonPath = string(abi.encodePacked(".L2_ADDRESS_MAP.", vm.toString(chainId), ".", addressType));
276254
return vm.parseJsonAddress(file, jsonPath);
277255
}
278256

@@ -282,8 +260,7 @@ contract Constants is Script {
282260
* @return The USDC address
283261
*/
284262
function getUSDCAddress(uint256 chainId) public view returns (address) {
285-
string memory chainName = _getChainName(chainId);
286-
string memory jsonPath = string(abi.encodePacked(".USDC.", chainName));
263+
string memory jsonPath = string(abi.encodePacked(".USDC.", vm.toString(chainId)));
287264
return vm.parseJsonAddress(file, jsonPath);
288265
}
289266

@@ -293,8 +270,7 @@ contract Constants is Script {
293270
* @return The USDC.e address
294271
*/
295272
function getUSDCeAddress(uint256 chainId) public view returns (address) {
296-
string memory chainName = _getChainName(chainId);
297-
string memory jsonPath = string(abi.encodePacked(".USDCe.", chainName));
273+
string memory jsonPath = string(abi.encodePacked(".USDCe.", vm.toString(chainId)));
298274
return vm.parseJsonAddress(file, jsonPath);
299275
}
300276

@@ -304,13 +280,7 @@ contract Constants is Script {
304280
* @return The WGHO address
305281
*/
306282
function getWghoAddress(uint256 chainId) public view returns (address) {
307-
string memory chainName = _getChainName(chainId);
308-
string memory jsonPath = string(abi.encodePacked(".WGHO.", chainName));
283+
string memory jsonPath = string(abi.encodePacked(".WGHO.", vm.toString(chainId)));
309284
return vm.parseJsonAddress(file, jsonPath);
310285
}
311-
312-
function getOftEid(uint256 chainId) public view returns (uint256) {
313-
string memory chainName = _getChainName(chainId);
314-
return vm.parseJsonUint(file, string.concat(".OFT_EIDs.", chainName));
315-
}
316286
}

script/utils/GenerateConstantsJson.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as fs from "fs";
44
import * as path from "path";
55

66
// Import the constants from the TypeScript files
7-
import { CHAIN_IDs } from "../../utils/constants";
7+
import { CHAIN_IDs, PUBLIC_NETWORKS } from "../../utils/constants";
88
import {
99
ZERO_ADDRESS,
1010
USDC,
@@ -21,8 +21,6 @@ import {
2121
L1_ADDRESS_MAP,
2222
OP_STACK_ADDRESS_MAP,
2323
L2_ADDRESS_MAP,
24-
CIRCLE_DOMAIN_IDs,
25-
OFT_EIDs,
2624
} from "../../deploy/consts";
2725

2826
// Helper function to convert chain IDs object to the expected format
@@ -53,13 +51,12 @@ function filterInvalidValues(values: { [key: string]: number }): { [key: string]
5351
// Generate the constants.json structure
5452
function generateConstantsJson() {
5553
const constants = {
54+
PUBLIC_NETWORKS,
5655
CHAIN_IDs: convertChainIdsToObject(CHAIN_IDs),
57-
OFT_EIDs: filterInvalidValues(Object.fromEntries(OFT_EIDs)),
5856
WETH,
5957
L2_ADDRESS_MAP,
6058
L1_ADDRESS_MAP,
6159
OP_STACK_ADDRESS_MAP,
62-
CIRCLE_DOMAIN_IDs: filterInvalidValues(CIRCLE_DOMAIN_IDs),
6360
TIME_CONSTANTS: {
6461
QUOTE_TIME_BUFFER,
6562
FILL_DEADLINE_BUFFER,

0 commit comments

Comments
 (0)