Skip to content

Commit

Permalink
chore: reorganize json config structure for more efficient loading
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIryna committed Feb 4, 2025
1 parent b7f3a36 commit a015c7a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 78 deletions.
40 changes: 18 additions & 22 deletions config/deploy/sepolia.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
{
"hub": {
"11155111": {
"m_token": "0x0c941AD94Ca4A52EDAeAbF203b61bdd1807CeEC0",
"registrar": "0x975Bf5f212367D09CB7f69D3dc4BA8C9B440aD3A",
"m_token": "0x245902cAB620E32DF09DA4a26094064e096dd480",
"registrar": "0xB9425BDb88CD1210E4C3CE95a8F192FbAa7a7F34",
"wormhole": {
"chain_id": "10002",
"chain_id": 10002,
"consistency_level": 200,
"core_bridge": "0x4a8bc80Ed5a4067f1CCf107057b8270E0cC11A78",
"gas_limit": 300000,
"relayer": "0x7B1bD7a6b4E61c2a123AC6BC2cbfC614437D0470",
"special_relayer": "0x0000000000000000000000000000000000000000",
"consistency_level": "200",
"gas_limit": "250000"
"special_relayer": "0x0000000000000000000000000000000000000000"
}
}
},
"spoke": {
"84532": {
"hub_vault": {
"address": "0x3dc71Be52d6D687e21FC0d4FFc196F32cacbc26d",
"wormhole_chain_id": "10002"
},
"hub_vault": "0x3dc71Be52d6D687e21FC0d4FFc196F32cacbc26d",
"hub_wormhole_chain_id": 10002,
"wormhole": {
"chain_id": "10004",
"chain_id": 10004,
"consistency_level": 200,
"core_bridge": "0x79A1027a6A159502049F10906D333EC57E95F083",
"gas_limit": 300000,
"relayer": "0x93BAD53DDfB6132b0aC8E37f6029163E63372cEE",
"special_relayer": "0x0000000000000000000000000000000000000000",
"consistency_level": "200",
"gas_limit": "250000"
"special_relayer": "0x0000000000000000000000000000000000000000"
}
},
"11155420": {
"hub_vault": {
"address": "0x3dc71Be52d6D687e21FC0d4FFc196F32cacbc26d",
"wormhole_chain_id": "10002"
},
"hub_vault": "0x3dc71Be52d6D687e21FC0d4FFc196F32cacbc26d",
"hub_wormhole_chain_id": 10002,
"wormhole": {
"chain_id": "10005",
"chain_id": 10005,
"consistency_level": 200,
"core_bridge": "0x31377888146f3253211EFEf5c676D41ECe7D58Fe",
"gas_limit": 300000,
"relayer": "0x93BAD53DDfB6132b0aC8E37f6029163E63372cEE",
"special_relayer": "0x0000000000000000000000000000000000000000",
"consistency_level": "200",
"gas_limit": "250000"
"special_relayer": "0x0000000000000000000000000000000000000000"
}
}
}
Expand Down
47 changes: 14 additions & 33 deletions script/deploy/DeployBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ contract DeployBase is Script, Utils {

struct WormholeConfiguration {
uint16 chainId;
uint8 consistencyLevel;
address coreBridge;
uint256 gasLimit;
address relayer;
address specialRelayer;
uint8 consistencyLevel;
uint256 gasLimit;
}

struct HubConfiguration {
Expand All @@ -47,7 +47,7 @@ contract DeployBase is Script, Utils {

struct SpokeConfiguration {
address hubVault;
uint16 hubVaultWormholechainId;
uint16 hubWormholeChainId;
WormholeConfiguration wormhole;
}

Expand Down Expand Up @@ -290,52 +290,33 @@ contract DeployBase is Script, Utils {
uint256 chainId_
) internal view returns (HubConfiguration memory hubConfig_) {
string memory file_ = vm.readFile(filepath_);
string memory hub_ = string.concat("$.hub.", vm.toString(chainId_), ".");

console.log("Hub configuration for chain ID %s loaded:", chainId_);

hubConfig_.mToken = file_.readAddress(_readKey(hub_, "m_token"));
hubConfig_.registrar = file_.readAddress(_readKey(hub_, "registrar"));
bytes memory data = vm.parseJson(file_, string.concat(".hub.", vm.toString(chainId_)));
hubConfig_ = abi.decode(data, (HubConfiguration));

console.log("Hub configuration for Chain ID %s loaded:", chainId_);
console.log("M Token:", hubConfig_.mToken);
console.log("Registrar:", hubConfig_.registrar);

hubConfig_.wormhole = _loadWormholeConfig(file_, hub_);
_logWormholeConfig(hubConfig_.wormhole);
}

function _loadSpokeConfig(
string memory filepath_,
uint256 chainId_
) internal view returns (SpokeConfiguration memory spokeConfig_) {
string memory file_ = vm.readFile(filepath_);
bytes memory data = vm.parseJson(file_, string.concat(".spoke.", vm.toString(chainId_)));
string memory spoke_ = string.concat("$.spoke.", vm.toString(chainId_), ".");
string memory hubVault_ = string.concat(spoke_, "hub_vault.");
spokeConfig_ = abi.decode(data, (SpokeConfiguration));

console.log("Spoke configuration for chain ID %s loaded:", chainId_);

spokeConfig_.hubVault = file_.readAddress(_readKey(hubVault_, "address"));
spokeConfig_.hubVaultWormholechainId = uint16(file_.readUint(_readKey(hubVault_, "wormhole_chain_id")));

console.log("Spoke configuration for Chain ID %s loaded:", chainId_);
console.log("Hub Vault:", spokeConfig_.hubVault);
console.log("Hub Vault Wormhole Chain ID:", spokeConfig_.hubVaultWormholechainId);

spokeConfig_.wormhole = _loadWormholeConfig(file_, spoke_);
console.log("Hub Wormhole Chain ID:", spokeConfig_.hubWormholeChainId);
_logWormholeConfig(spokeConfig_.wormhole);
}

function _loadWormholeConfig(
string memory file_,
string memory parentNode_
) internal pure returns (WormholeConfiguration memory wormholeConfig_) {
string memory wormhole_ = string.concat(parentNode_, "wormhole.");

wormholeConfig_.chainId = uint16(file_.readUint(_readKey(wormhole_, "chain_id")));
wormholeConfig_.coreBridge = file_.readAddress(_readKey(wormhole_, "core_bridge"));
wormholeConfig_.relayer = file_.readAddress(_readKey(wormhole_, "relayer"));
wormholeConfig_.specialRelayer = file_.readAddress(_readKey(wormhole_, "special_relayer"));
wormholeConfig_.consistencyLevel = uint8(file_.readUint(_readKey(wormhole_, "consistency_level")));
wormholeConfig_.gasLimit = file_.readUint(_readKey(wormhole_, "gas_limit"));

console.log("Wormhole chain ID:", wormholeConfig_.chainId);
function _logWormholeConfig(WormholeConfiguration memory wormholeConfig_) internal pure {
console.log("Wormhole Chain ID:", wormholeConfig_.chainId);
console.log("Wormhole Core Bridge:", wormholeConfig_.coreBridge);
console.log("Wormhole Relayer:", wormholeConfig_.relayer);
console.log("Wormhole Special Relayer:", wormholeConfig_.specialRelayer);
Expand Down
2 changes: 1 addition & 1 deletion script/deploy/DeploySpoke.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract DeploySpoke is DeployBase {
deployer_,
spokePortal_,
spokeConfig_.hubVault,
spokeConfig_.hubVaultWormholechainId,
spokeConfig_.hubWormholeChainId,
migrationAdmin_
);

Expand Down
4 changes: 2 additions & 2 deletions test/fork/ForkTestBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract ForkTestBase is CastBase, ConfigureBase, DeployBase, Test {
_DEPLOYER,
_baseSpokePortal,
baseSpokeConfig_.hubVault,
baseSpokeConfig_.hubVaultWormholechainId,
baseSpokeConfig_.hubWormholeChainId,
_MIGRATION_ADMIN
);

Expand Down Expand Up @@ -184,7 +184,7 @@ contract ForkTestBase is CastBase, ConfigureBase, DeployBase, Test {
_DEPLOYER,
_optimismSpokePortal,
optimismSpokeConfig_.hubVault,
optimismSpokeConfig_.hubVaultWormholechainId,
optimismSpokeConfig_.hubWormholeChainId,
_MIGRATION_ADMIN
);

Expand Down
36 changes: 16 additions & 20 deletions test/fork/fixtures/deploy-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,38 @@
"m_token": "0x866A2BF4E572CbcF37D5071A7a58503Bfb36be1b",
"registrar": "0x119FbeeDD4F4f4298Fb59B720d5654442b81ae2c",
"wormhole": {
"chain_id": "2",
"chain_id": 2,
"consistency_level": 15,
"core_bridge": "0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B",
"gas_limit": 300000,
"relayer": "0x27428DD2d3DD32A4D7f7C497eAaa23130d894911",
"special_relayer": "0x0000000000000000000000000000000000000000",
"consistency_level": "15",
"gas_limit": "300000"
"special_relayer": "0x0000000000000000000000000000000000000000"
}
}
},
"spoke": {
"8453": {
"hub_vault": {
"address": "0xd7298f620B0F752Cf41BD818a16C756d9dCAA34f",
"wormhole_chain_id": "2"
},
"hub_vault": "0xd7298f620B0F752Cf41BD818a16C756d9dCAA34f",
"hub_wormhole_chain_id": 2,
"wormhole": {
"chain_id": "30",
"chain_id": 30,
"consistency_level": 15,
"core_bridge": "0xbebdb6C8ddC678FfA9f8748f85C815C556Dd8ac6",
"gas_limit": 300000,
"relayer": "0x706F82e9bb5b0813501714Ab5974216704980e31",
"special_relayer": "0x0000000000000000000000000000000000000000",
"consistency_level": "15",
"gas_limit": "300000"
"special_relayer": "0x0000000000000000000000000000000000000000"
}
},
"10": {
"hub_vault": {
"address": "0xd7298f620B0F752Cf41BD818a16C756d9dCAA34f",
"wormhole_chain_id": "2"
},
"hub_vault": "0xd7298f620B0F752Cf41BD818a16C756d9dCAA34f",
"hub_wormhole_chain_id": 2,
"wormhole": {
"chain_id": "24",
"chain_id": 24,
"consistency_level": 15,
"core_bridge": "0xEe91C335eab126dF5fDB3797EA9d6aD93aeC9722",
"gas_limit": 300000,
"relayer": "0x27428DD2d3DD32A4D7f7C497eAaa23130d894911",
"special_relayer": "0x0000000000000000000000000000000000000000",
"consistency_level": "15",
"gas_limit": "300000"
"special_relayer": "0x0000000000000000000000000000000000000000"
}
}
}
Expand Down

0 comments on commit a015c7a

Please sign in to comment.