generated from bgd-labs/bgd-forge-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADITestBase.sol
678 lines (607 loc) · 24.9 KB
/
ADITestBase.sol
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import 'forge-std/StdJson.sol';
import 'forge-std/Test.sol';
import {IBaseAdaptersUpdate} from '../../src/templates/interfaces/IBaseAdaptersUpdate.sol';
import {ChainHelpers, ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {GovV3Helpers} from 'aave-helpers/GovV3Helpers.sol';
import {ProxyHelpers} from 'aave-v3-origin/../tests/utils/ProxyHelpers.sol';
import {ICrossChainReceiver, ICrossChainForwarder} from 'aave-address-book/common/ICrossChainController.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {GovernanceV3Polygon} from 'aave-address-book/GovernanceV3Polygon.sol';
import {GovernanceV3Avalanche} from 'aave-address-book/GovernanceV3Avalanche.sol';
import {GovernanceV3Optimism} from 'aave-address-book/GovernanceV3Optimism.sol';
import {GovernanceV3BNB} from 'aave-address-book/GovernanceV3BNB.sol';
import {GovernanceV3Metis} from 'aave-address-book/GovernanceV3Metis.sol';
import {GovernanceV3Base} from 'aave-address-book/GovernanceV3Base.sol';
import {GovernanceV3Arbitrum} from 'aave-address-book/GovernanceV3Arbitrum.sol';
import {GovernanceV3Gnosis} from 'aave-address-book/GovernanceV3Gnosis.sol';
import {GovernanceV3Scroll} from 'aave-address-book/GovernanceV3Scroll.sol';
import {IBaseAdapter} from 'aave-address-book/common/IBaseAdapter.sol';
contract ADITestBase is Test {
using stdJson for string;
struct ReceiverConfigByChain {
uint8 requiredConfirmations;
uint256 chainId;
uint256 validityTimestamp;
}
struct ReceiverAdaptersByChain {
uint256 chainId;
address[] receiverAdapters;
}
struct ForwarderAdaptersByChain {
uint256 chainId;
ICrossChainForwarder.ChainIdBridgeConfig[] forwarders;
}
struct CCCConfig {
address crossChainControllerImpl;
ReceiverConfigByChain[] receiverConfigs;
ReceiverAdaptersByChain[] receiverAdaptersConfig;
ForwarderAdaptersByChain[] forwarderAdaptersConfig;
}
struct ForwarderAdapters {
ICrossChainForwarder.ChainIdBridgeConfig[] adapters;
uint256 chainId;
}
struct AdaptersByChain {
address[] adapters;
uint256 chainId;
}
struct DestinationPayload {
uint256 chainId;
bytes payloadCode;
}
struct SnapshotParams {
address crossChainController;
bool receiverConfigs;
bool receiverAdapterConfigs;
bool forwarderAdapterConfigs;
bool cccImplUpdate;
string reportName;
}
function executePayload(Vm vm, address payload) internal {
GovV3Helpers.executePayload(vm, payload);
}
/**
* @dev generates the diff between two reports
*/
function diffReports(string memory reportBefore, string memory reportAfter) internal {
string memory outPath = string(
abi.encodePacked('./diffs/', reportBefore, '_', reportAfter, '.md')
);
string memory beforePath = string(abi.encodePacked('./reports/', reportBefore, '.json'));
string memory afterPath = string(abi.encodePacked('./reports/', reportAfter, '.json'));
string[] memory inputs = new string[](7);
inputs[0] = 'npx';
inputs[1] = '@bgd-labs/aave-cli@^0.16.2';
inputs[2] = 'adi-diff-snapshots';
inputs[3] = beforePath;
inputs[4] = afterPath;
inputs[5] = '-o';
inputs[6] = outPath;
vm.ffi(inputs);
}
function defaultTest(
string memory reportName,
address crossChainController,
address payload,
bool runE2E,
Vm vm
) public returns (CCCConfig memory, CCCConfig memory) {
string memory beforeString = string(abi.encodePacked('adi_', reportName, '_before'));
CCCConfig memory configBefore = createConfigurationSnapshot(beforeString, crossChainController);
uint256 snapshotId = vm.snapshot();
executePayload(vm, payload);
string memory afterString = string(abi.encodePacked('adi_', reportName, '_after'));
CCCConfig memory configAfter = createConfigurationSnapshot(afterString, crossChainController);
diffReports(beforeString, afterString);
vm.revertTo(snapshotId);
if (runE2E) e2eTest(payload, crossChainController);
return (configBefore, configAfter);
}
function e2eTest(address payload, address crossChainController) public {
// test receivers
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[]
memory receiversToAllow = IBaseAdaptersUpdate(payload).getReceiverBridgeAdaptersToAllow();
if (receiversToAllow.length != 0) {
_testCorrectReceiverAdaptersConfiguration(payload, receiversToAllow, crossChainController);
_testCorrectTrustedRemotes(receiversToAllow);
}
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[]
memory receiversToRemove = IBaseAdaptersUpdate(payload).getReceiverBridgeAdaptersToRemove();
if (receiversToRemove.length != 0) {
_testOnlyRemovedSpecifiedReceiverAdapters(payload, receiversToRemove, crossChainController);
}
// test forwarders
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory forwardersToEnable = IBaseAdaptersUpdate(payload).getForwarderBridgeAdaptersToEnable();
if (forwardersToEnable.length != 0) {
_testCorrectForwarderAdaptersConfiguration(payload, crossChainController, forwardersToEnable);
_testDestinationAdapterIsRegistered(forwardersToEnable);
}
ICrossChainForwarder.BridgeAdapterToDisable[] memory forwardersToRemove = IBaseAdaptersUpdate(
payload
).getForwarderBridgeAdaptersToRemove();
if (forwardersToRemove.length != 0) {
_testOnlyRemovedSpecificForwarderAdapters(payload, crossChainController, forwardersToRemove);
}
}
function getDestinationPayloadsByChain()
public
view
virtual
returns (DestinationPayload[] memory)
{
return new DestinationPayload[](0);
}
function _testDestinationAdapterIsRegistered(
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[] memory forwardersToEnable
) internal {
DestinationPayload[] memory destinationPayloads = getDestinationPayloadsByChain();
bytes memory empty;
for (uint256 i = 0; i < forwardersToEnable.length; i++) {
uint256 currentChainId = block.chainid;
// change fork to destination network
(uint256 previousFork, ) = ChainHelpers.selectChain(
vm,
forwardersToEnable[i].destinationChainId
);
address destinationCCC = getCCCByChainId(block.chainid);
if (destinationPayloads.length > 0) {
for (uint256 j = 0; j < destinationPayloads.length; j++) {
if (destinationPayloads[j].chainId == forwardersToEnable[i].destinationChainId) {
if (keccak256(destinationPayloads[j].payloadCode) != keccak256(empty)) {
address destinationPayload = GovV3Helpers.deployDeterministic(
destinationPayloads[j].payloadCode
);
executePayload(vm, destinationPayload);
// check that adapter is registered
assertEq(
ICrossChainReceiver(destinationCCC).isReceiverBridgeAdapterAllowed(
forwardersToEnable[i].destinationBridgeAdapter,
currentChainId
),
true
);
break;
}
}
}
} else {
assertEq(
ICrossChainReceiver(destinationCCC).isReceiverBridgeAdapterAllowed(
forwardersToEnable[i].destinationBridgeAdapter,
currentChainId
),
true
);
}
vm.selectFork(previousFork);
}
}
function _testOnlyRemovedSpecificForwarderAdapters(
address payload,
address crossChainController,
ICrossChainForwarder.BridgeAdapterToDisable[] memory adaptersToRemove
) internal {
ForwarderAdapters[]
memory forwardersBridgeAdaptersByChainBefore = _getCurrentForwarderAdaptersByChain(
crossChainController,
block.chainid
);
executePayload(vm, payload);
ForwarderAdapters[]
memory forwardersBridgeAdaptersByChainAfter = _getCurrentForwarderAdaptersByChain(
crossChainController,
block.chainid
);
for (uint256 l = 0; l < forwardersBridgeAdaptersByChainBefore.length; l++) {
for (uint256 j = 0; j < forwardersBridgeAdaptersByChainAfter.length; j++) {
if (
forwardersBridgeAdaptersByChainBefore[l].chainId ==
forwardersBridgeAdaptersByChainAfter[j].chainId
) {
for (uint256 i = 0; i < forwardersBridgeAdaptersByChainBefore[l].adapters.length; i++) {
bool forwarderFound;
for (uint256 m = 0; m < forwardersBridgeAdaptersByChainAfter[j].adapters.length; m++) {
if (
forwardersBridgeAdaptersByChainBefore[l].adapters[i].destinationBridgeAdapter ==
forwardersBridgeAdaptersByChainAfter[j].adapters[m].destinationBridgeAdapter &&
forwardersBridgeAdaptersByChainBefore[l].adapters[i].currentChainBridgeAdapter ==
forwardersBridgeAdaptersByChainAfter[j].adapters[m].currentChainBridgeAdapter
) {
forwarderFound = true;
break;
}
}
if (!forwarderFound) {
bool isAdapterToBeRemoved;
for (uint256 k = 0; k < adaptersToRemove.length; k++) {
if (
forwardersBridgeAdaptersByChainBefore[l].adapters[i].currentChainBridgeAdapter ==
adaptersToRemove[k].bridgeAdapter
) {
for (uint256 n = 0; n < adaptersToRemove[k].chainIds.length; n++) {
if (
forwardersBridgeAdaptersByChainBefore[l].chainId ==
adaptersToRemove[k].chainIds[n]
) {
isAdapterToBeRemoved = true;
break;
}
}
}
}
assertEq(isAdapterToBeRemoved, true);
}
}
}
}
}
}
function _testCorrectForwarderAdaptersConfiguration(
address payload,
address crossChainController,
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[] memory forwardersToEnable
) internal {
executePayload(vm, payload);
for (uint256 i = 0; i < forwardersToEnable.length; i++) {
ICrossChainForwarder.ChainIdBridgeConfig[]
memory forwardersBridgeAdaptersByChain = ICrossChainForwarder(crossChainController)
.getForwarderBridgeAdaptersByChain(forwardersToEnable[i].destinationChainId);
bool newAdapterFound;
for (uint256 j = 0; j < forwardersBridgeAdaptersByChain.length; j++) {
if (
forwardersBridgeAdaptersByChain[j].destinationBridgeAdapter ==
forwardersToEnable[i].destinationBridgeAdapter &&
forwardersBridgeAdaptersByChain[j].currentChainBridgeAdapter ==
forwardersToEnable[i].currentChainBridgeAdapter
) {
newAdapterFound = true;
break;
}
}
assertEq(newAdapterFound, true);
}
}
function _testCorrectTrustedRemotes(
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[] memory receiversToAllow
) internal {
for (uint256 i = 0; i < receiversToAllow.length; i++) {
for (uint256 j = 0; j < receiversToAllow[i].chainIds.length; j++) {
address trustedRemote = IBaseAdapter(receiversToAllow[i].bridgeAdapter)
.getTrustedRemoteByChainId(receiversToAllow[i].chainIds[j]);
assertEq(trustedRemote, getCCCByChainId(receiversToAllow[i].chainIds[j]));
}
}
}
function _testOnlyRemovedSpecifiedReceiverAdapters(
address payload,
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[] memory adaptersToRemove,
address crossChainController
) internal {
AdaptersByChain[] memory adaptersBefore = _getCurrentReceiverAdaptersByChain(
crossChainController
);
executePayload(vm, payload);
for (uint256 i = 0; i < adaptersBefore.length; i++) {
for (uint256 j = 0; j < adaptersToRemove.length; j++) {
for (uint256 x = 0; x < adaptersToRemove[j].chainIds.length; x++) {
if (adaptersToRemove[j].chainIds[x] == adaptersBefore[i].chainId) {
for (uint256 k = 0; k < adaptersBefore[i].adapters.length; k++) {
if (adaptersBefore[i].adapters[k] == adaptersToRemove[j].bridgeAdapter) {
assertEq(
ICrossChainReceiver(crossChainController).isReceiverBridgeAdapterAllowed(
adaptersToRemove[j].bridgeAdapter,
adaptersBefore[i].chainId
),
false
);
} else {
assertEq(
ICrossChainReceiver(crossChainController).isReceiverBridgeAdapterAllowed(
adaptersBefore[i].adapters[k],
adaptersBefore[i].chainId
),
true
);
}
}
}
}
}
}
}
function _testCorrectReceiverAdaptersConfiguration(
address payload,
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[] memory receiversToAllow,
address crossChainController
) internal {
for (uint256 i = 0; i < receiversToAllow.length; i++) {
for (uint256 j = 0; j < receiversToAllow[i].chainIds.length; j++) {
assertEq(
ICrossChainReceiver(crossChainController).isReceiverBridgeAdapterAllowed(
receiversToAllow[i].bridgeAdapter,
receiversToAllow[i].chainIds[j]
),
false
);
}
}
executePayload(vm, payload);
for (uint256 i = 0; i < receiversToAllow.length; i++) {
for (uint256 j = 0; j < receiversToAllow[i].chainIds.length; j++) {
assertEq(
ICrossChainReceiver(crossChainController).isReceiverBridgeAdapterAllowed(
receiversToAllow[i].bridgeAdapter,
receiversToAllow[i].chainIds[j]
),
true
);
}
}
}
/**
* @dev Generates a markdown compatible snapshot of the whole CrossChainController configuration into `/reports`.
* @param reportName filename suffix for the generated reports.
* @param crossChainController the ccc to be snapshot
* @return ReserveConfig[] list of configs
*/
function createConfigurationSnapshot(
string memory reportName,
address crossChainController
) public returns (CCCConfig memory) {
return
createConfigurationSnapshot(
SnapshotParams({
crossChainController: crossChainController,
receiverConfigs: true,
receiverAdapterConfigs: true,
forwarderAdapterConfigs: true,
cccImplUpdate: true,
reportName: reportName
})
);
}
function createConfigurationSnapshot(
SnapshotParams memory snapshotParams
) public returns (CCCConfig memory) {
string memory path = string(abi.encodePacked('./reports/', snapshotParams.reportName, '.json'));
// overwrite with empty json to later be extended
vm.writeFile(
path,
'{ "cccImplementation": {}, "receiverConfigsByChain": {}, "receiverAdaptersByChain": {}, "forwarderAdaptersByChain": {}}'
);
vm.serializeUint('root', 'chainId', block.chainid);
CCCConfig memory config = _getCCCConfig(snapshotParams.crossChainController);
if (snapshotParams.receiverConfigs) _writeReceiverConfigs(path, config);
if (snapshotParams.receiverAdapterConfigs) _writeReceiverAdapters(path, config);
if (snapshotParams.forwarderAdapterConfigs) _writeForwarderAdapters(path, config);
if (snapshotParams.cccImplUpdate) _writeCCCImplUpdate(path, config);
return config;
}
function _writeCCCImplUpdate(string memory path, CCCConfig memory config) internal {
string memory output = vm.serializeAddress(
'root',
'crossChainControllerImpl',
config.crossChainControllerImpl
);
vm.writeJson(output, path);
}
function _writeForwarderAdapters(string memory path, CCCConfig memory config) internal {
// keys for json stringification
string memory forwarderAdaptersKey = 'forwarderAdapters';
string memory content = '{}';
vm.serializeJson(forwarderAdaptersKey, '{}');
ForwarderAdaptersByChain[] memory forwarderConfig = config.forwarderAdaptersConfig;
for (uint256 i = 0; i < forwarderConfig.length; i++) {
uint256 chainId = forwarderConfig[i].chainId;
string memory key = vm.toString(chainId);
vm.serializeJson(key, '{}');
string memory object;
ICrossChainForwarder.ChainIdBridgeConfig[] memory forwarders = forwarderConfig[i].forwarders;
for (uint256 j = 0; j < forwarders.length; j++) {
if (j == forwarders.length - 1) {
object = vm.serializeString(
key,
vm.toString(forwarders[j].currentChainBridgeAdapter),
vm.toString(forwarders[j].destinationBridgeAdapter)
);
} else {
vm.serializeString(
key,
vm.toString(forwarders[j].currentChainBridgeAdapter),
vm.toString(forwarders[j].destinationBridgeAdapter)
);
}
}
content = vm.serializeString(forwarderAdaptersKey, key, object);
}
string memory output = vm.serializeString('root', 'forwarderAdaptersByChain', content);
vm.writeJson(output, path);
}
function _writeReceiverAdapters(string memory path, CCCConfig memory config) internal {
// keys for json stringification
string memory receiverAdaptersKey = 'receiverAdapters';
string memory content = '{}';
vm.serializeJson(receiverAdaptersKey, '{}');
ReceiverAdaptersByChain[] memory receiverConfig = config.receiverAdaptersConfig;
for (uint256 i = 0; i < receiverConfig.length; i++) {
uint256 chainId = receiverConfig[i].chainId;
string memory key = vm.toString(chainId);
vm.serializeJson(key, '{}');
string memory object;
for (uint256 j = 0; j < receiverConfig[i].receiverAdapters.length; j++) {
if (j == receiverConfig[i].receiverAdapters.length - 1) {
object = vm.serializeString(
key,
vm.toString(receiverConfig[i].receiverAdapters[j]),
vm.toString(true)
);
} else {
vm.serializeString(
key,
vm.toString(receiverConfig[i].receiverAdapters[j]),
vm.toString(true)
);
}
}
content = vm.serializeString(receiverAdaptersKey, key, object);
}
string memory output = vm.serializeString('root', 'receiverAdaptersByChain', content);
vm.writeJson(output, path);
}
function _writeReceiverConfigs(string memory path, CCCConfig memory configs) internal {
// keys for json stringification
string memory receiverConfigsKey = 'receiverConfigs';
string memory content = '{}';
vm.serializeJson(receiverConfigsKey, '{}');
ReceiverConfigByChain[] memory receiverConfig = configs.receiverConfigs;
for (uint256 i = 0; i < receiverConfig.length; i++) {
uint256 chainId = receiverConfig[i].chainId;
string memory key = vm.toString(chainId);
vm.serializeJson(key, '{}');
string memory object;
vm.serializeString(
key,
'requiredConfirmations',
vm.toString(receiverConfig[i].requiredConfirmations)
);
object = vm.serializeString(
key,
'validityTimestamp',
vm.toString(receiverConfig[i].validityTimestamp)
);
content = vm.serializeString(receiverConfigsKey, key, object);
}
string memory output = vm.serializeString('root', 'receiverConfigs', content);
vm.writeJson(output, path);
}
function _getCCCConfig(address ccc) internal view returns (CCCConfig memory) {
CCCConfig memory config;
// get crossChainController implementation
config.crossChainControllerImpl = ProxyHelpers
.getInitializableAdminUpgradeabilityProxyImplementation(vm, ccc);
// get supported networks
uint256[] memory receiverSupportedChains = ICrossChainReceiver(ccc).getSupportedChains();
ReceiverConfigByChain[] memory receiverConfigs = new ReceiverConfigByChain[](
receiverSupportedChains.length
);
ReceiverAdaptersByChain[] memory receiverAdaptersConfig = new ReceiverAdaptersByChain[](
receiverSupportedChains.length
);
for (uint256 i = 0; i < receiverSupportedChains.length; i++) {
uint256 chainId = receiverSupportedChains[i];
ICrossChainReceiver.ReceiverConfiguration memory receiverConfig = ICrossChainReceiver(ccc)
.getConfigurationByChain(chainId);
receiverConfigs[i] = ReceiverConfigByChain({
chainId: chainId,
requiredConfirmations: receiverConfig.requiredConfirmation,
validityTimestamp: receiverConfig.validityTimestamp
});
receiverAdaptersConfig[i] = ReceiverAdaptersByChain({
chainId: chainId,
receiverAdapters: ICrossChainReceiver(ccc).getReceiverBridgeAdaptersByChain(chainId)
});
}
config.receiverAdaptersConfig = receiverAdaptersConfig;
config.receiverConfigs = receiverConfigs;
// get receiver configs by network
uint256[] memory supportedForwardingNetworks = _getForwarderSupportedChainsByChainId(
block.chainid
);
ForwarderAdaptersByChain[] memory forwardersByChain = new ForwarderAdaptersByChain[](
supportedForwardingNetworks.length
);
for (uint256 i = 0; i < supportedForwardingNetworks.length; i++) {
uint256 chainId = supportedForwardingNetworks[i];
forwardersByChain[i] = ForwarderAdaptersByChain({
chainId: chainId,
forwarders: ICrossChainForwarder(ccc).getForwarderBridgeAdaptersByChain(chainId)
});
}
config.forwarderAdaptersConfig = forwardersByChain;
return config;
}
/// @dev Update when supporting new forwarding networks
function _getForwarderSupportedChainsByChainId(
uint256 chainId
) internal pure returns (uint256[] memory) {
if (chainId == ChainIds.MAINNET) {
uint256[] memory chainIds = new uint256[](10);
chainIds[0] = ChainIds.MAINNET;
chainIds[1] = ChainIds.POLYGON;
chainIds[2] = ChainIds.AVALANCHE;
chainIds[3] = ChainIds.BNB;
chainIds[4] = ChainIds.GNOSIS;
chainIds[5] = ChainIds.ARBITRUM;
chainIds[6] = ChainIds.OPTIMISM;
chainIds[7] = ChainIds.METIS;
chainIds[8] = ChainIds.BASE;
chainIds[9] = ChainIds.SCROLL;
return chainIds;
} else if (chainId == ChainIds.POLYGON) {
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = ChainIds.MAINNET;
return chainIds;
} else if (chainId == ChainIds.AVALANCHE) {
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = ChainIds.MAINNET;
return chainIds;
} else {
return new uint256[](0);
}
}
function _getCurrentForwarderAdaptersByChain(
address crossChainController,
uint256 chainId
) internal view returns (ForwarderAdapters[] memory) {
uint256[] memory supportedChains = _getForwarderSupportedChainsByChainId(chainId);
ForwarderAdapters[] memory forwarderAdapters = new ForwarderAdapters[](supportedChains.length);
for (uint256 i = 0; i < supportedChains.length; i++) {
ICrossChainForwarder.ChainIdBridgeConfig[] memory forwarders = ICrossChainForwarder(
crossChainController
).getForwarderBridgeAdaptersByChain(supportedChains[i]);
forwarderAdapters[i] = ForwarderAdapters({adapters: forwarders, chainId: supportedChains[i]});
}
return forwarderAdapters;
}
function _getCurrentReceiverAdaptersByChain(
address crossChainController
) internal view returns (AdaptersByChain[] memory) {
uint256[] memory supportedChains = ICrossChainReceiver(crossChainController)
.getSupportedChains();
AdaptersByChain[] memory receiverAdapters = new AdaptersByChain[](supportedChains.length);
for (uint256 i = 0; i < supportedChains.length; i++) {
address[] memory receivers = ICrossChainReceiver(crossChainController)
.getReceiverBridgeAdaptersByChain(supportedChains[i]);
receiverAdapters[i] = AdaptersByChain({adapters: receivers, chainId: supportedChains[i]});
}
return receiverAdapters;
}
/// @dev add new chains t
function getCCCByChainId(uint256 chainId) public pure returns (address) {
if (chainId == ChainIds.MAINNET) {
return GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.POLYGON) {
return GovernanceV3Polygon.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.AVALANCHE) {
return GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.OPTIMISM) {
return GovernanceV3Optimism.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.BNB) {
return GovernanceV3BNB.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.METIS) {
return GovernanceV3Metis.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.BASE) {
return GovernanceV3Base.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.ARBITRUM) {
return GovernanceV3Arbitrum.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.GNOSIS) {
return GovernanceV3Gnosis.CROSS_CHAIN_CONTROLLER;
} else if (chainId == ChainIds.SCROLL) {
return GovernanceV3Scroll.CROSS_CHAIN_CONTROLLER;
}
revert();
}
}