forked from OffchainLabs/arbitrum-orbit-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwagmi.config.ts
234 lines (208 loc) Β· 6.53 KB
/
wagmi.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import { erc, etherscan } from '@wagmi/cli/plugins';
import { hashMessage } from 'viem';
import dotenv from 'dotenv';
import { ParentChainId } from './src';
import {
mainnet,
arbitrumOne,
arbitrumNova,
base,
sepolia,
holesky,
arbitrumSepolia,
baseSepolia,
nitroTestnodeL1,
nitroTestnodeL2,
nitroTestnodeL3,
} from './src/chains';
dotenv.config();
function loadApiKey(key: string): string {
const apiKey = process.env[key];
if (typeof apiKey === 'undefined' || apiKey.length === 0) {
throw new Error(`Missing the ${key} environment variable!`);
}
return apiKey;
}
function sleep(ms: number = 1_000) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const arbiscanApiKey = loadApiKey('ARBISCAN_API_KEY');
const etherscanApiKey = loadApiKey('ETHERSCAN_API_KEY');
const basescanApikey = loadApiKey('BASESCAN_API_KEY');
const blockExplorerApiUrls: Record<ParentChainId, { url: string; apiKey: string }> = {
// mainnet L1
[mainnet.id]: {
url: 'https://api.etherscan.io/api',
apiKey: etherscanApiKey,
},
// mainnet L2
[arbitrumOne.id]: {
url: 'https://api.arbiscan.io/api',
apiKey: arbiscanApiKey,
},
[arbitrumNova.id]: {
url: 'https://api-nova.arbiscan.io/api',
apiKey: arbiscanApiKey,
},
[base.id]: {
url: 'https://api.basescan.org/api',
apiKey: basescanApikey,
},
// testnet L1
[sepolia.id]: {
url: 'https://api-sepolia.etherscan.io/api',
apiKey: etherscanApiKey,
},
[holesky.id]: {
url: 'https://api-holesky.etherscan.io/api',
apiKey: etherscanApiKey,
},
// testnet L2
[arbitrumSepolia.id]: {
url: 'https://api-sepolia.arbiscan.io/api',
apiKey: arbiscanApiKey,
},
[baseSepolia.id]: {
url: 'https://api-sepolia.basescan.org/api',
apiKey: basescanApikey,
},
// local nitro-testnode / fine to omit these as we skip abi fetch
[nitroTestnodeL1.id]: { url: '', apiKey: '' },
[nitroTestnodeL2.id]: { url: '', apiKey: '' },
};
export async function fetchAbi(chainId: ParentChainId, address: `0x${string}`) {
const { url, apiKey } = blockExplorerApiUrls[chainId];
const responseJson = await (
await fetch(
`${url}?module=contract&action=getabi&format=raw&address=${address}&apikey=${apiKey}`,
)
).json();
if (responseJson.message === 'NOTOK') {
throw new Error(`Failed to fetch ABI for ${chainId}: ${responseJson.result}`);
}
return responseJson;
}
type ContractConfig = {
name: string;
version?: string;
address: Record<ParentChainId, `0x${string}`> | `0x${string}`;
};
const contracts: ContractConfig[] = [
{
name: 'RollupCreator',
version: '1.1.0',
address: {
// mainnet L1
[mainnet.id]: '0x90d68b056c411015eae3ec0b98ad94e2c91419f1',
// mainnet L2
[arbitrumOne.id]: '0x9CAd81628aB7D8e239F1A5B497313341578c5F71',
[arbitrumNova.id]: '0x9CAd81628aB7D8e239F1A5B497313341578c5F71',
[base.id]: '0x850F050C65B34966895AdA26a4D06923901916DB',
// testnet L1
[sepolia.id]: '0xfbd0b034e6305788007f6e0123cc5eae701a5751',
[holesky.id]: '0xB512078282F462Ba104231ad856464Ceb0a7747e',
// testnet L2
[arbitrumSepolia.id]: '0x06E341073b2749e0Bb9912461351f716DeCDa9b0',
[baseSepolia.id]: '0x1E0921818df948c338380e722C8aE91Bb285763C',
// local nitro-testnode (on "release" branch with --tokenbridge --l3node --l3-token-bridge flags)
[nitroTestnodeL1.id]: '0x596eabe0291d4cdafac7ef53d16c92bf6922b5e0',
[nitroTestnodeL2.id]: '0x3BaF9f08bAD68869eEdEa90F2Cc546Bd80F1A651',
},
},
{
name: 'TokenBridgeCreator',
version: '1.2.0',
address: {
// mainnet L1
[mainnet.id]: '0x60D9A46F24D5a35b95A78Dd3E793e55D94EE0660',
// mainnet L2
[arbitrumOne.id]: '0x2f5624dc8800dfA0A82AC03509Ef8bb8E7Ac000e',
[arbitrumNova.id]: '0x8B9D9490a68B1F16ac8A21DdAE5Fd7aB9d708c14',
[base.id]: '0x4C240987d6fE4fa8C7a0004986e3db563150CA55',
// testnet L1
[sepolia.id]: '0x7edb2dfBeEf9417e0454A80c51EE0C034e45a570',
[holesky.id]: '0xac890ED9bC2494C053cE701F138958df95966d94',
// testnet L2
[arbitrumSepolia.id]: '0x56C486D3786fA26cc61473C499A36Eb9CC1FbD8E',
[baseSepolia.id]: '0xFC71d21a4FE10Cc0d34745ba9c713836f82f8DE3',
// local nitro-testnode (on "release" branch with --tokenbridge --l3node --l3-token-bridge flags)
[nitroTestnodeL1.id]: '0x54B4D4e578E10178a6cA602bdb6df0F213296Af4',
[nitroTestnodeL2.id]: '0x38f35af53bf913c439eab06a367e09d6eb253492',
},
},
{
name: 'ArbOwner',
address: '0x0000000000000000000000000000000000000070',
},
{
name: 'ArbGasInfo',
address: '0x000000000000000000000000000000000000006c',
},
{
name: 'ArbOwnerPublic',
address: '0x000000000000000000000000000000000000006b',
},
{
name: 'ArbAggregator',
address: '0x000000000000000000000000000000000000006d',
},
];
function allEqual<T>(array: T[]) {
return array.every((value) => value === array[0]);
}
export async function assertContractAbisMatch(contract: ContractConfig) {
// skip check when single address is provided
if (typeof contract.address === 'string') {
console.log(`- ${contract.name} β\n`);
return;
}
console.log(`- ${contract.name}`);
const abiHashes = await Promise.all(
Object.entries(contract.address)
// don't fetch abis for testnode
.filter(([chainIdString]) => {
const chainId = Number(chainIdString);
return (
chainId !== nitroTestnodeL1.id &&
chainId !== nitroTestnodeL2.id &&
chainId !== nitroTestnodeL3.id
);
})
// fetch abis for all chains and hash them
.map(async ([chainId, address]) => {
const abi = await fetchAbi(Number(chainId) as ParentChainId, address);
const abiHash = hashMessage(JSON.stringify(abi));
console.log(`- ${abiHash} (${chainId})`);
return abiHash;
}),
);
// make sure all abis hashes are the same
if (!allEqual(abiHashes)) {
throw new Error(`- ${contract.name}`);
}
console.log(`- ${contract.name} β\n`);
}
export default async function () {
console.log(`Checking if contracts match by comparing hashed JSON ABIs.\n`);
for (const contract of contracts) {
await assertContractAbisMatch(contract);
await sleep(); // sleep to avoid rate limiting
}
console.log(`Done.\n`);
return {
out: 'src/generated.ts',
plugins: [
erc({
20: true,
721: false,
4626: false,
}),
etherscan({
chainId: arbitrumSepolia.id,
apiKey: arbiscanApiKey,
contracts,
cacheDuration: 0,
}),
],
};
}