Skip to content

Commit e2768cf

Browse files
committed
add update-custom-network file
1 parent 2a8b126 commit e2768cf

File tree

4 files changed

+139
-81
lines changed

4 files changed

+139
-81
lines changed

.github/workflows/test-all.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ jobs:
3232
nitro-testnode-ref: release
3333
args: --tokenbridge --l3node --l3-token-bridge
3434

35+
- name: Update custom network file
36+
env:
37+
ORBIT_TEST: '1'
38+
run: yarn update-custom-network
39+
3540
- name: Test
3641
run: yarn run testAll
3742

@@ -54,21 +59,11 @@ jobs:
5459
with:
5560
nitro-testnode-ref: release
5661
args: --tokenbridge --l3node --l3-token-bridge --l3-fee-token
57-
58-
- name: Modify custom network file
59-
# Some contract addresses are different when using a custom gas token chain
60-
run: >
61-
jq -c '
62-
.[1].nativeToken = "0xE069078bA9ACCE4eeAE609d8754515Cf13dd6706" |
63-
.[1].ethBridge.rollup = "0x44612A67F6A7c4C894fB4AeA66c7Cfa7A0f0D388" |
64-
.[1].tokenBridge.parentGatewayRouter = "0x0C085152C2799834fc1603533ff6916fa1FdA302" |
65-
.[1].tokenBridge.parentErc20Gateway = "0x59156b0596689D965Ba707E160e5370AF22461a0" |
66-
.[1].tokenBridge.parentCustomGateway = "0xCe02eA568090ae7d5184B0a98df90f6aa69C1552" |
67-
.[1].tokenBridge.parentWethGateway = "0x0000000000000000000000000000000000000000" |
68-
.[1].tokenBridge.childWethGateway = "0x0000000000000000000000000000000000000000" |
69-
.[1].tokenBridge.parentWeth = "0x0000000000000000000000000000000000000000" |
70-
.[1].tokenBridge.childWeth = "0x0000000000000000000000000000000000000000"
71-
' customNetwork.json > tmp.customNetwork.json && mv tmp.customNetwork.json customNetwork.json
62+
63+
- name: Update custom network file
64+
env:
65+
ORBIT_TEST: '1'
66+
run: yarn update-custom-network
7267

7368
- name: Test
7469
run: yarn run testAll

customNetwork.json

Lines changed: 25 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,38 @@
11
[
22
{
3-
"chainID": 412346,
3+
"parentChainId": 1337,
4+
"chainId": 412346,
45
"confirmPeriodBlocks": 20,
56
"ethBridge": {
6-
"bridge": "0xd21d0cA137A64165E3C3702a37C5D42E6a5CdACC",
7-
"inbox": "0xF52c6E85A9E6287942fD913DfCc269EB571816a6",
8-
"outbox": "0xbf2265Cd6Fd551e5EAA862Fd81BA317D585eE693",
9-
"rollup": "0x1b172F52EC0EFFeeC7946903F20410B5d6571AA0",
10-
"sequencerInbox": "0x7F6958d308593dC0BdEa73c4bcD742965E1C79af"
7+
"bridge": "0xC179edf2Ecdc3764574AEF66D8919154F3F9DAeD",
8+
"inbox": "0xd4b3d83F8089c1FF413525b3707Bd5AcBafa80bc",
9+
"outbox": "0x528342A53723c9729465d484FB27ed2c893D310f",
10+
"rollup": "0xD0B8D2BA3e2ac9AA58b8D9BB1887dC9F7649C5C8",
11+
"sequencerInbox": "0xF03488b09fdF9301d7Bde7e0a1D7Ee0EbD43BA16"
1112
},
12-
"explorerUrl": "",
13-
"isArbitrum": true,
1413
"isCustom": true,
15-
"name": "ArbLocal",
16-
"partnerChainID": 1337,
14+
"name": "OrbitLocal",
1715
"retryableLifetimeSeconds": 604800,
18-
"nitroGenesisBlock": 0,
19-
"nitroGenesisL1Block": 0,
20-
"depositTimeout": 900000,
16+
"isTestnet": true,
2117
"tokenBridge": {
22-
"parentGatewayRouter": "0x145899e2EF2A3f460Cfb2F7897615F5758000F66",
23-
"childGatewayRouter": "0x32656396981868E925280FB772b3f806892cf4bF",
24-
"parentErc20Gateway": "0x4D9Aa26aCee73293ba84fB1FcA8100006239860E",
25-
"childErc20Gateway": "0x7424e3DAAAAcd867c85ceB75c1E00119F2ee5eb7",
26-
"parentCustomGateway": "0xC9ba2864E0E5dC3B78a539fA5e50b4508595A236",
27-
"childCustomGateway": "0x0B35cfE62314C3852A0942b5830c728353BD654F",
28-
"parentWethGateway": "0xCb24A87c3Dfc5b6DC8f1Da8D62D731fA1109A32C",
29-
"childWethGateway": "0x67aE8014BD1A0c1Ed747715d22b3b3a188aC324B",
30-
"parentWeth": "0x7E32b54800705876d3b5cFbc7d9c226a211F7C1a",
31-
"childWeth": "0xA1abD387192e3bb4e84D3109181F9f005aBaF5CA",
18+
"parentCustomGateway": "0x3cfd8C5F1A00544Ee7F5D78C9846A60bfb1a868a",
19+
"parentErc20Gateway": "0xd4Ee82dcf6f42F2316d527215A33aF8a156cA786",
20+
"parentGatewayRouter": "0xb9c99B231E37aBD2d433cC3545eD32d044Df3126",
21+
"parentMultiCall": "0x49117fC32930E324F2E9A7BeA588FFb26008b8eC",
3222
"parentProxyAdmin": "0x275FC51309e5928Cb085b463ADEF5cbD45c76b62",
23+
"parentWeth": "0x7E32b54800705876d3b5cFbc7d9c226a211F7C1a",
24+
"parentWethGateway": "0x5C8BF9aA60CcCA8D3eF39874Edb1Ad755a001b61",
25+
"childCustomGateway": "0x0B35cfE62314C3852A0942b5830c728353BD654F",
26+
"childErc20Gateway": "0x7424e3DAAAAcd867c85ceB75c1E00119F2ee5eb7",
27+
"childGatewayRouter": "0x32656396981868E925280FB772b3f806892cf4bF",
28+
"childMultiCall": "0x6B1E93aE298B64e8f5b9f43B65Dd8F1eaA6DD4c3",
3329
"childProxyAdmin": "0x9F95547ABB0FfC92b4E37b3124d1e8613d5aB74A",
34-
"parentMultiCall": "0x49117fC32930E324F2E9A7BeA588FFb26008b8eC",
35-
"childMultiCall": "0x6B1E93aE298B64e8f5b9f43B65Dd8F1eaA6DD4c3"
36-
},
37-
"chainId": 412346,
38-
"parentChainId": 1337
39-
},
40-
{
41-
"chainID": 333333,
42-
"confirmPeriodBlocks": 20,
43-
"ethBridge": {
44-
"bridge": "0xFbd865f29BadF3fdcf14b7e742F78c8DdF7fa4C9",
45-
"inbox": "0x7CB5a1892d31936a13CeE3a4A8183Ed40300e87c",
46-
"outbox": "0x3dAEcE87269310A2f055920ef5C84679ca50F218",
47-
"rollup": "0x9129f7A7f4D5A87F971Fe15C554AD1CF22ceb4EF",
48-
"sequencerInbox": "0x99c807B58c00DE2b068e521AAC227A1e8ADe1fa9"
30+
"childWeth": "0xA1abD387192e3bb4e84D3109181F9f005aBaF5CA",
31+
"childWethGateway": "0x67aE8014BD1A0c1Ed747715d22b3b3a188aC324B"
4932
},
50-
"explorerUrl": "",
33+
"chainID": 412346,
34+
"partnerChainID": 1337,
5135
"isArbitrum": true,
52-
"isCustom": true,
53-
"name": "ArbLocalL3",
54-
"partnerChainID": 412346,
55-
"retryableLifetimeSeconds": 604800,
56-
"nitroGenesisBlock": 0,
57-
"nitroGenesisL1Block": 0,
58-
"depositTimeout": 900000,
59-
"tokenBridge": {
60-
"parentGatewayRouter": "0x9a6E8E638451781B47b8632a11E56020270A335B",
61-
"childGatewayRouter": "0x8B6BC759226f8Fe687c8aD8Cc0DbF85E095e9297",
62-
"parentErc20Gateway": "0x7A6b9Ca6e4f87E6a641c1AbD7671aD42bF538977",
63-
"childErc20Gateway": "0xaa7d51aFFEeB32d99b1CB2fd6d81D7adA4a896e8",
64-
"parentCustomGateway": "0xDCa39C8Fbd686cb8838106Ed94C0B9e9802697d6",
65-
"childCustomGateway": "0xD4816AeF8f85A3C1E01Cd071a81daD4fa941625f",
66-
"parentWethGateway": "0x3bF927fc03d13bD2199b02a029ABb490D13706b3",
67-
"childWethGateway": "0xA6AB233B3c7bfd0399834897b5073974A3D467e2",
68-
"parentWeth": "0xA1abD387192e3bb4e84D3109181F9f005aBaF5CA",
69-
"childWeth": "0x582a8dBc77f665dF2c49Ce0a138978e9267dd968",
70-
"parentProxyAdmin": "0x74513d47D265527f0647eD5B90072578c609B378",
71-
"childProxyAdmin": "0x36C56eC2CF3a3f53db9F01d0A5Ae84b36fb0A1e2",
72-
"parentMultiCall": "0x20a3627Dcc53756E38aE3F92717DE9B23617b422",
73-
"childMultiCall": "0x052B15c8Ff0544287AE689C4F2FC53A3905d7Db3"
74-
},
75-
"chainId": 333333,
76-
"parentChainId": 412346
36+
"explorerUrl": ""
7737
}
78-
]
38+
]

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"prettier:format": "prettier './**/*.{js,json,md,sol,ts,yml}' --write && yarn run lint --fix",
1616
"prettier:check": "prettier './**/*.{js,json,md,sol,ts,yml}' --check && yarn run lint",
1717
"testAll": "tests/runAll.sh",
18-
"setup-envs": "node scripts/setup-envs.js"
18+
"setup-envs": "node scripts/setup-envs.js",
19+
"update-custom-network": "node scripts/update-custom-network.js"
1920
},
2021
"devDependencies": {
2122
"@offchainlabs/eslint-config-typescript": "^0.2.1",

scripts/update-custom-network.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
* Update customNetwork.json from a local nitro-testnode container.
5+
* Usage:
6+
* yarn update-custom-network
7+
* ORBIT_TEST=1 yarn update-custom-network # also adds L3 network info
8+
*/
9+
10+
const { execSync } = require('child_process');
11+
const fs = require('fs');
12+
const path = require('path');
13+
14+
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
15+
16+
const OUTPUT_PATH = path.join(__dirname, '..', 'customNetwork.json');
17+
const isTestingOrbitChains = process.env.ORBIT_TEST === '1';
18+
19+
function getLocalNetworksFromContainer(which) {
20+
const dockerNames = [
21+
'nitro_sequencer_1',
22+
'nitro-sequencer-1',
23+
'nitro-testnode-sequencer-1',
24+
'nitro-testnode_sequencer_1',
25+
];
26+
27+
for (const dockerName of dockerNames) {
28+
try {
29+
const raw = execSync(
30+
`docker exec ${dockerName} cat /tokenbridge-data/${which}_network.json`
31+
).toString();
32+
return JSON.parse(raw);
33+
} catch {
34+
// try next container name
35+
}
36+
}
37+
38+
throw new Error('nitro-testnode sequencer not found');
39+
}
40+
41+
function isLegacyNetworkType(network) {
42+
return network && 'partnerChainID' in network && !('parentChainId' in network);
43+
}
44+
45+
function normalizeNetwork(network) {
46+
const normalized = { ...network };
47+
const chainId = normalized.chainId ?? normalized.chainID;
48+
const parentChainId = normalized.parentChainId ?? normalized.partnerChainID;
49+
50+
if (chainId != null) {
51+
normalized.chainId = chainId;
52+
normalized.chainID = chainId;
53+
}
54+
55+
if (parentChainId != null) {
56+
normalized.parentChainId = parentChainId;
57+
normalized.partnerChainID = parentChainId;
58+
}
59+
60+
if (normalized.isArbitrum == null) normalized.isArbitrum = true;
61+
if (normalized.isCustom == null) normalized.isCustom = true;
62+
if (normalized.explorerUrl == null) normalized.explorerUrl = '';
63+
64+
return normalized;
65+
}
66+
67+
function buildCustomNetworks(output) {
68+
const networks = [];
69+
if (output.l2Network) networks.push(normalizeNetwork(output.l2Network));
70+
if (output.l3Network) networks.push(normalizeNetwork(output.l3Network));
71+
if (!networks.length) {
72+
throw new Error('No L2/L3 network info found in docker output.');
73+
}
74+
return networks;
75+
}
76+
77+
async function main() {
78+
const output = getLocalNetworksFromContainer('l1l2');
79+
80+
if (isTestingOrbitChains) {
81+
const { l2Network: l3Network } = getLocalNetworksFromContainer('l2l3');
82+
output.l3Network = l3Network;
83+
}
84+
85+
if (
86+
isLegacyNetworkType(output.l2Network) ||
87+
(output.l3Network && isLegacyNetworkType(output.l3Network))
88+
) {
89+
throw new Error(
90+
'Legacy L2Network type detected. Please use the latest testnode version and token-bridge-contracts version 1.2.5 or above.'
91+
);
92+
}
93+
94+
const customNetworks = buildCustomNetworks(output);
95+
fs.writeFileSync(OUTPUT_PATH, JSON.stringify(customNetworks, null, 2));
96+
console.log(`customNetwork.json updated: ${OUTPUT_PATH}`);
97+
}
98+
99+
main().catch((error) => {
100+
console.error(error);
101+
process.exit(1);
102+
});

0 commit comments

Comments
 (0)