@@ -30,7 +30,7 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
30
30
uint256 public constant MAX_DEPOSITORS_PER_BRIDGE = 300 ;
31
31
32
32
/// @notice The duration of time that depositors have after the market's green light is given to rage quit before they can be bridged.
33
- uint256 public constant RAGE_QUIT_PERIOD_DURATION = 48 hours ;
33
+ uint256 public constant RAGE_QUIT_PERIOD_DURATION = 0 hours ;
34
34
35
35
/// @notice The code hash of the Uniswap V2 Pair contract.
36
36
bytes32 internal constant UNISWAP_V2_PAIR_CODE_HASH = 0x5b83bdbcc56b2e630f2807bbadd2b0c21619108066b92a58de081261089e9ce5 ;
@@ -99,6 +99,12 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
99
99
/// @notice The Uniswap V2 router on the source chain.
100
100
IUniswapV2Router01 public immutable UNISWAP_V2_ROUTER;
101
101
102
+ /// @notice The hash of the Weiroll Wallet code
103
+ bytes32 public immutable WEIROLL_WALLET_PROXY_CODE_HASH;
104
+
105
+ /// @notice The address of the Weiroll Wallet that deposited into the CCDM in this transaction.
106
+ address public transient currentlyDepositingWeirollWallet;
107
+
102
108
/// @notice The party that green lights bridging on a per market basis
103
109
address public greenLighter;
104
110
@@ -240,6 +246,9 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
240
246
*/
241
247
event GreenLightTurnedOff (bytes32 indexed marketHash );
242
248
249
+ /// @notice Error emitted when calling deposit from an address that isn't a Weiroll Wallet.
250
+ error OnlyWeirollWallet ();
251
+
243
252
/// @notice Error emitted when trying to deposit into the locker for a Royco market that is either not created or has an undeployed input token.
244
253
error RoycoMarketNotInitialized ();
245
254
@@ -279,10 +288,30 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
279
288
/// @notice Error emitted when bridging all the specified deposits fails.
280
289
error FailedToBridgeAllDeposits ();
281
290
291
+ /// @notice Error emitted when the lengths of the source market hashes and owners array don't match in the constructor.
292
+ error ArrayLengthMismatch ();
293
+
294
+ /// @notice Error emitted when transferring back excess msg.value fails.
295
+ error RefundFailed ();
296
+
282
297
/*//////////////////////////////////////////////////////////////
283
298
Modifiers
284
299
//////////////////////////////////////////////////////////////*/
285
300
301
+ /// @dev Modifier to ensure the caller is a Weiroll Wallet created using the clone with immutable args pattern.
302
+ modifier onlyWeirollWallet () {
303
+ bytes memory code = msg .sender .code;
304
+ bytes32 codeHash;
305
+ assembly ("memory-safe" ) {
306
+ // Get code hash of the runtime bytecode without the immutable args
307
+ codeHash := keccak256 (add (code, 32 ), 56 )
308
+ }
309
+
310
+ // Check that the length is valid and the codeHash matches that of a Weiroll Wallet proxy
311
+ require (code.length == 195 && codeHash == WEIROLL_WALLET_PROXY_CODE_HASH, OnlyWeirollWallet ());
312
+ _;
313
+ }
314
+
286
315
/// @dev Modifier to ensure the caller is the authorized multisig for the market.
287
316
modifier onlyGreenLighter () {
288
317
require (msg .sender == greenLighter, OnlyGreenLighter ());
@@ -334,6 +363,11 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
334
363
RECIPE_MARKET_HUB = _recipeMarketHub;
335
364
WRAPPED_NATIVE_ASSET_TOKEN = IWETH (_uniswap_v2_router.WETH ());
336
365
UNISWAP_V2_ROUTER = _uniswap_v2_router;
366
+ WEIROLL_WALLET_PROXY_CODE_HASH = keccak256 (
367
+ abi.encodePacked (
368
+ hex "363d3d3761008b603836393d3d3d3661008b013d73 " , _recipeMarketHub.WEIROLL_WALLET_IMPLEMENTATION (), hex "5af43d82803e903d91603657fd5bf3 "
369
+ )
370
+ );
337
371
ccdmNonce = 1 ; // The first CCDM bridge transaction will have a nonce of 1
338
372
339
373
for (uint256 i = 0 ; i < _lzV2OFTs.length ; ++ i) {
@@ -357,7 +391,7 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
357
391
/**
358
392
* @notice Called by the deposit script from the depositor's Weiroll wallet.
359
393
*/
360
- function deposit () external nonReentrant {
394
+ function deposit () external nonReentrant onlyWeirollWallet {
361
395
// Get Weiroll Wallet's market hash, depositor/owner/AP, and amount deposited
362
396
WeirollWallet wallet = WeirollWallet (payable (msg .sender ));
363
397
bytes32 targetMarketHash = wallet.marketHash ();
@@ -386,6 +420,9 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
386
420
walletInfo.ccdmNonceOnDeposit = ccdmNonce;
387
421
walletInfo.amountDeposited = amountDeposited;
388
422
423
+ // Set the depositing Weiroll Wallet in transient state
424
+ currentlyDepositingWeirollWallet = msg .sender ;
425
+
389
426
// Emit deposit event
390
427
emit UserDeposited (targetMarketHash, depositor, amountDeposited);
391
428
}
@@ -428,8 +465,6 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
428
465
* @param _depositors The addresses of the depositors (APs) to bridge
429
466
*/
430
467
function bridgeSingleTokens (bytes32 _marketHash , address [] calldata _depositors ) external payable readyToBridge (_marketHash) nonReentrant {
431
- require (_depositors.length <= MAX_DEPOSITORS_PER_BRIDGE, DepositorsPerBridgeLimitExceeded ());
432
-
433
468
// The CCDM nonce for this CCDM bridge transaction
434
469
uint256 nonce = ccdmNonce;
435
470
// Initialize compose message
@@ -455,6 +490,8 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
455
490
456
491
// Ensure that at least one depositor was included in the bridge payload
457
492
require (totalAmountToBridge > 0 , MustBridgeAtLeastOneDepositor ());
493
+ // Ensure that the number of depositors bridged is less than the globally defined limit
494
+ require (numDepositorsIncluded <= MAX_DEPOSITORS_PER_BRIDGE, DepositorsPerBridgeLimitExceeded ());
458
495
459
496
// Resize the compose message to reflect the actual number of depositors included in the payload
460
497
composeMsg.resizeComposeMsg (numDepositorsIncluded);
@@ -476,7 +513,8 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
476
513
477
514
// Refund any excess value sent with the transaction
478
515
if (msg .value > bridgingFee) {
479
- payable (msg .sender ).transfer (msg .value - bridgingFee);
516
+ (bool success ,) = payable (msg .sender ).call { value: msg .value - bridgingFee }("" );
517
+ require (success, RefundFailed ());
480
518
}
481
519
482
520
// Emit event to keep track of bridged deposits
@@ -504,8 +542,6 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
504
542
readyToBridge (_marketHash)
505
543
nonReentrant
506
544
{
507
- require (_depositors.length <= MAX_DEPOSITORS_PER_BRIDGE, DepositorsPerBridgeLimitExceeded ());
508
-
509
545
// The CCDM nonce for this CCDM bridge transaction
510
546
uint256 nonce = ccdmNonce;
511
547
@@ -571,8 +607,10 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
571
607
// Ensure that at least one depositor was included in the bridge payload
572
608
require (totals.token0_TotalAmountToBridge > 0 && totals.token1_TotalAmountToBridge > 0 , MustBridgeAtLeastOneDepositor ());
573
609
574
- // Resize the compose messages to reflect the actual number of depositors bridged
575
610
uint256 numDepositorsIncluded = params.numDepositorsIncluded;
611
+ // Ensure that the number of depositors bridged is less than the globally defined limit
612
+ require (numDepositorsIncluded <= MAX_DEPOSITORS_PER_BRIDGE, DepositorsPerBridgeLimitExceeded ());
613
+ // Resize the compose messages to reflect the actual number of depositors bridged
576
614
token0_ComposeMsg.resizeComposeMsg (numDepositorsIncluded);
577
615
token1_ComposeMsg.resizeComposeMsg (numDepositorsIncluded);
578
616
@@ -760,7 +798,8 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
760
798
761
799
// Refund excess value sent with the transaction
762
800
if (msg .value > totalBridgingFee) {
763
- payable (msg .sender ).transfer (msg .value - totalBridgingFee);
801
+ (bool success ,) = payable (msg .sender ).call { value: msg .value - totalBridgingFee }("" );
802
+ require (success, RefundFailed ());
764
803
}
765
804
766
805
// Emit event to keep track of bridged deposits
@@ -899,24 +938,29 @@ contract DepositLocker is Ownable2Step, ReentrancyGuardTransient {
899
938
}
900
939
901
940
/**
902
- * @notice Sets the owner of an LP token market .
941
+ * @notice Sets the owners of LP token markets .
903
942
* @dev Only callable by the contract owner.
904
- * @param _marketHash The market hash to set the LP token owner for.
905
- * @param _lpMarketOwner Address of the LP token market owner.
906
- */
907
- function setLpMarketOwner (bytes32 _marketHash , address _lpMarketOwner ) external onlyOwner {
908
- marketHashToLpMarketOwner[_marketHash] = _lpMarketOwner;
909
- emit LpMarketOwnerSet (_marketHash, _lpMarketOwner);
943
+ * @param _marketHashes The market hashes to set the LP market owners for.
944
+ * @param _lpMarketOwners Addresses of the LP market owners.
945
+ */
946
+ function setLpMarketOwners (bytes32 [] calldata _marketHashes , address [] calldata _lpMarketOwners ) external onlyOwner {
947
+ require (_marketHashes.length == _lpMarketOwners.length , ArrayLengthMismatch ());
948
+ for (uint256 i = 0 ; i < _marketHashes.length ; ++ i) {
949
+ marketHashToLpMarketOwner[_marketHashes[i]] = _lpMarketOwners[i];
950
+ emit LpMarketOwnerSet (_marketHashes[i], _lpMarketOwners[i]);
951
+ }
910
952
}
911
953
912
954
/**
913
- * @notice Sets the LayerZero V2 OFT for the underlying token .
914
- * @notice _lzV2OFT must implement IOFT.
955
+ * @notice Sets the LayerZero V2 OFTs for the underlying tokens .
956
+ * @notice Elements of _lzV2OFTs must implement IOFT.
915
957
* @dev Only callable by the contract owner.
916
- * @param _lzV2OFT LayerZero OFT to use to bridge the specified token .
958
+ * @param _lzV2OFTs LayerZero OFTs to use to bridge the underlying tokens .
917
959
*/
918
- function setLzOFT (IOFT _lzV2OFT ) external onlyOwner {
919
- _setLzV2OFTForToken (_lzV2OFT);
960
+ function setLzOFTs (IOFT[] calldata _lzV2OFTs ) external onlyOwner {
961
+ for (uint256 i = 0 ; i < _lzV2OFTs.length ; ++ i) {
962
+ _setLzV2OFTForToken (_lzV2OFTs[i]);
963
+ }
920
964
}
921
965
922
966
/**
0 commit comments