@@ -11,6 +11,7 @@ import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/
11
11
12
12
import {IBridgehub, L2TransactionRequestDirect, L2TransactionRequestTwoBridgesOuter, L2TransactionRequestTwoBridgesInner} from "./IBridgehub.sol " ;
13
13
import {IL1AssetRouter} from "../bridge/interfaces/IL1AssetRouter.sol " ;
14
+ import {IL1BaseTokenAssetHandler} from "../bridge/interfaces/IL1BaseTokenAssetHandler.sol " ;
14
15
import {IStateTransitionManager} from "../state-transition/IStateTransitionManager.sol " ;
15
16
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol " ;
16
17
import {DataEncoding} from "../common/libraries/DataEncoding.sol " ;
@@ -48,15 +49,17 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
48
49
IL1AssetRouter public sharedBridge;
49
50
50
51
/// @notice StateTransitionManagers that are registered, and ZKchains that use these STMs can use this bridgehub as settlement layer.
51
- mapping (address _stateTransitionManager = > bool ) public stateTransitionManagerIsRegistered;
52
+ mapping (address stateTransitionManager = > bool ) public stateTransitionManagerIsRegistered;
53
+
52
54
/// @notice we store registered tokens (for arbitrary base token)
53
- mapping (address _baseToken = > bool ) public tokenIsRegistered ;
55
+ mapping (address baseToken = > bool ) public __DEPRECATED_tokenIsRegistered ;
54
56
55
57
/// @notice chainID => StateTransitionManager contract address, STM that is managing rules for a given ZKchain.
56
- mapping (uint256 _chainId = > address ) public stateTransitionManager;
58
+ mapping (uint256 chainId = > address ) public stateTransitionManager;
57
59
58
60
/// @notice chainID => baseToken contract address, token that is used as 'base token' by a given child chain.
59
- mapping (uint256 _chainId = > address ) public baseToken;
61
+ // slither-disable-next-line uninitialized-state
62
+ mapping (uint256 chainId = > address ) public __DEPRECATED_baseToken;
60
63
61
64
/// @dev used to manage non critical updates
62
65
address public admin;
@@ -73,7 +76,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
73
76
IMessageRoot public override messageRoot;
74
77
75
78
/// @notice Mapping from chain id to encoding of the base token used for deposits / withdrawals
76
- mapping (uint256 _chainId = > bytes32 ) public baseTokenAssetId;
79
+ mapping (uint256 chainId = > bytes32 ) public baseTokenAssetId;
77
80
78
81
/// @notice The deployment tracker for the state transition managers.
79
82
ISTMDeploymentTracker public stmDeployer;
@@ -89,6 +92,9 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
89
92
/// @dev Sync layer chain is expected to have .. as the base token.
90
93
mapping (uint256 chainId = > bool isWhitelistedSettlementLayer ) public whitelistedSettlementLayers;
91
94
95
+ /// @notice we store registered assetIds (for arbitrary base token)
96
+ mapping (bytes32 baseTokenAssetId = > bool ) public assetIdIsRegistered;
97
+
92
98
modifier onlyOwnerOrAdmin () {
93
99
require (msg .sender == admin || msg .sender == owner (), "BH: not owner or admin " );
94
100
_;
@@ -181,7 +187,7 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
181
187
if (baseTokenAssetId[_chainId] == bytes32 (0 )) {
182
188
return ;
183
189
}
184
- address token = baseToken [_chainId];
190
+ address token = __DEPRECATED_baseToken [_chainId];
185
191
require (token != address (0 ), "BH: token not set " );
186
192
baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId (block .chainid , token);
187
193
}
@@ -222,13 +228,13 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
222
228
emit StateTransitionManagerRemoved (_stateTransitionManager);
223
229
}
224
230
225
- /// @notice token can be any contract with the appropriate interface/functionality
226
- /// @param _token address of base token to be registered
227
- function addToken ( address _token ) external onlyOwner {
228
- require (! tokenIsRegistered[_token ], "BH: token already registered " );
229
- tokenIsRegistered[_token ] = true ;
231
+ /// @notice asset id can represent any token contract with the appropriate interface/functionality
232
+ /// @param _baseTokenAssetId asset id of base token to be registered
233
+ function addTokenAssetId ( bytes32 _baseTokenAssetId ) external onlyOwner {
234
+ require (! assetIdIsRegistered[_baseTokenAssetId ], "BH: asset id already registered " );
235
+ assetIdIsRegistered[_baseTokenAssetId ] = true ;
230
236
231
- emit TokenRegistered (_token );
237
+ emit BaseTokenAssetIdRegistered (_baseTokenAssetId );
232
238
}
233
239
234
240
/// @notice Used to register a chain as a settlement layer.
@@ -274,15 +280,15 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
274
280
/// @notice for Eth the baseToken address is 1
275
281
/// @param _chainId the chainId of the chain
276
282
/// @param _stateTransitionManager the state transition manager address
277
- /// @param _baseToken the base token of the chain
283
+ /// @param _baseTokenAssetId the base token asset id of the chain
278
284
/// @param _salt the salt for the chainId, currently not used
279
285
/// @param _admin the admin of the chain
280
286
/// @param _initData the fixed initialization data for the chain
281
287
/// @param _factoryDeps the factory dependencies for the chain's deployment
282
288
function createNewChain (
283
289
uint256 _chainId ,
284
290
address _stateTransitionManager ,
285
- address _baseToken ,
291
+ bytes32 _baseTokenAssetId ,
286
292
// solhint-disable-next-line no-unused-vars
287
293
uint256 _salt ,
288
294
address _admin ,
@@ -294,21 +300,19 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
294
300
require (_chainId != block .chainid , "BH: chain id must not match current chainid " );
295
301
296
302
require (stateTransitionManagerIsRegistered[_stateTransitionManager], "BH: state transition not registered " );
297
- require (tokenIsRegistered[_baseToken ], "BH: token not registered " );
303
+ require (assetIdIsRegistered[_baseTokenAssetId ], "BH: asset id not registered " );
298
304
require (address (sharedBridge) != address (0 ), "BH: shared bridge not set " );
299
305
300
306
require (stateTransitionManager[_chainId] == address (0 ), "BH: chainId already registered " );
301
307
302
308
stateTransitionManager[_chainId] = _stateTransitionManager;
303
- baseToken[_chainId] = _baseToken;
304
309
305
- /// For now all base tokens have to use the NTV.
306
- baseTokenAssetId[_chainId] = DataEncoding.encodeNTVAssetId (block .chainid , _baseToken);
310
+ baseTokenAssetId[_chainId] = _baseTokenAssetId;
307
311
settlementLayer[_chainId] = block .chainid ;
308
312
309
313
address chainAddress = IStateTransitionManager (_stateTransitionManager).createNewChain ({
310
314
_chainId: _chainId,
311
- _baseToken: _baseToken ,
315
+ _baseTokenAssetId: _baseTokenAssetId ,
312
316
_sharedBridge: address (sharedBridge),
313
317
_admin: _admin,
314
318
_initData: _initData,
@@ -332,6 +336,15 @@ contract Bridgehub is IBridgehub, ReentrancyGuard, Ownable2StepUpgradeable, Paus
332
336
Getters
333
337
//////////////////////////////////////////////////////////////*/
334
338
339
+ /// @notice baseToken function, which takes assetId as input, reads assetHandler from AR, and tokenAddress from AH
340
+ function baseToken (uint256 _chainId ) public view returns (address ) {
341
+ bytes32 baseTokenAssetId = baseTokenAssetId[_chainId];
342
+ IL1BaseTokenAssetHandler assetHandlerAddress = IL1BaseTokenAssetHandler (
343
+ sharedBridge.assetHandlerAddress (baseTokenAssetId)
344
+ );
345
+ return assetHandlerAddress.tokenAddress (baseTokenAssetId);
346
+ }
347
+
335
348
/// @notice Returns all the registered hyperchain addresses
336
349
function getAllHyperchains () public view override returns (address [] memory chainAddresses ) {
337
350
uint256 [] memory keys = hyperchainMap.keys ();
0 commit comments