@@ -29,10 +29,16 @@ error BridgeTokenNotSupported();
29
29
error InvalidSlippageParam ();
30
30
error InvalidPayload ();
31
31
32
+ // Note: The `IPool` wasn't updated to avoid changing interface
33
+ // Refs: https://github.com/autonomoussoftware/metronome-synth/issues/877
34
+ interface IPoolV4 is IPool {
35
+ function isBridgingActive () external view returns (bool );
36
+ }
37
+
32
38
/**
33
39
* @title Cross-chain dispatcher
34
40
*/
35
- contract CrossChainDispatcher is ReentrancyGuard , CrossChainDispatcherStorageV1 {
41
+ contract CrossChainDispatcher is ReentrancyGuard , CrossChainDispatcherStorageV2 {
36
42
using SafeERC20 for IERC20 ;
37
43
using BytesLib for bytes ;
38
44
@@ -96,7 +102,8 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
96
102
}
97
103
98
104
modifier onlyIfBridgingIsNotPaused () {
99
- if (! isBridgingActive) revert BridgingIsPaused ();
105
+ if (! isBridgingActive || ! IPoolV4 (address (IManageable (msg .sender ).pool ())).isBridgingActive ())
106
+ revert BridgingIsPaused ();
100
107
_;
101
108
}
102
109
@@ -193,7 +200,8 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
193
200
uint256 _requestId ,
194
201
uint256 _sgPoolId ,
195
202
address _account ,
196
- uint256 _amountOutMin
203
+ uint256 _amountOutMin ,
204
+ uint256 _callbackTxNativeFee
197
205
) = CrossChainLib.decodeLeverageSwapPayload (payload_);
198
206
199
207
address _bridgeToken = IStargatePool (IStargateFactory (stargateComposer.factory ()).getPool (_sgPoolId)).token ();
@@ -216,7 +224,7 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
216
224
tokenIn: _bridgeToken,
217
225
dstChainId: _srcChainId,
218
226
amountIn: amountIn_,
219
- nativeFee: poolRegistry. quoter (). quoteLeverageCallbackNativeFee (_srcChainId) ,
227
+ nativeFee: _callbackTxNativeFee + extraCallbackTxNativeFee[_requestId] ,
220
228
payload: CrossChainLib.encodeLeverageCallbackPayload (_srcSmartFarmingManager, _requestId),
221
229
refundAddress: _account,
222
230
dstGasForCall: leverageCallbackTxGasLimit,
@@ -315,7 +323,8 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
315
323
address _dstProxyOFT ,
316
324
uint256 _requestId ,
317
325
address _account ,
318
- uint256 _amountOutMin
326
+ uint256 _amountOutMin ,
327
+ uint256 _callbackTxNativeFee
319
328
) = CrossChainLib.decodeFlashRepaySwapPayload (payload_);
320
329
321
330
address _syntheticToken = IProxyOFT (_dstProxyOFT).token ();
@@ -344,7 +353,7 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
344
353
refundAddress: _account,
345
354
dstGasForCall: flashRepayCallbackTxGasLimit,
346
355
dstNativeAmount: 0 ,
347
- nativeFee: poolRegistry. quoter (). quoteFlashRepayCallbackNativeFee (_srcChainId)
356
+ nativeFee: _callbackTxNativeFee + extraCallbackTxNativeFee[_requestId]
348
357
})
349
358
);
350
359
}
@@ -380,7 +389,11 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
380
389
payload_
381
390
);
382
391
383
- (, , uint256 _requestId , address _account , ) = CrossChainLib.decodeFlashRepaySwapPayload (payload_);
392
+ (, , uint256 _requestId , address _account , , ) = CrossChainLib.decodeFlashRepaySwapPayload (payload_);
393
+
394
+ if (msg .value > 0 ) {
395
+ extraCallbackTxNativeFee[_requestId] += msg .value ;
396
+ }
384
397
385
398
if (msg .sender == _account) {
386
399
// Note: If `swapAmountOutMin[_requestId]` is `0` (default value), swap function will use payload's slippage param
@@ -409,12 +422,16 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
409
422
bytes calldata payload_ ,
410
423
uint256 newAmountOutMin_
411
424
) external payable nonReentrant {
412
- (, address _dstProxyOFT , uint256 _requestId , , address _account , ) = CrossChainLib.decodeLeverageSwapPayload (
425
+ (, address _dstProxyOFT , uint256 _requestId , , address _account , , ) = CrossChainLib.decodeLeverageSwapPayload (
413
426
payload_
414
427
);
415
428
416
429
if (! _isValidProxyOFT (_dstProxyOFT)) revert InvalidPayload ();
417
430
431
+ if (msg .value > 0 ) {
432
+ extraCallbackTxNativeFee[_requestId] += msg .value ;
433
+ }
434
+
418
435
if (msg .sender == _account) {
419
436
// Note: If `swapAmountOutMin[_requestId]` is `0` (default value), swap function will use payload's slippage param
420
437
if (newAmountOutMin_ == 0 ) revert InvalidSlippageParam ();
@@ -472,7 +489,8 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
472
489
dstProxyOFT_: _dstProxyOFT,
473
490
requestId_: _requestId,
474
491
account_: _account,
475
- amountOutMin_: amountOutMin_
492
+ amountOutMin_: amountOutMin_,
493
+ callbackTxNativeFee_: callbackTxNativeFee_
476
494
});
477
495
}
478
496
@@ -508,7 +526,7 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
508
526
uint256 amountIn_ ,
509
527
uint256 amountOutMin_ ,
510
528
bytes calldata lzArgs_
511
- ) external payable override nonReentrant onlyIfSmartFarmingManager {
529
+ ) external payable override nonReentrant onlyIfSmartFarmingManager onlyIfBridgingIsNotPaused {
512
530
address _account = account_; // stack too deep
513
531
514
532
(uint16 _dstChainId , uint256 _callbackTxNativeFee , uint64 _leverageSwapTxGasLimit ) = CrossChainLib.decodeLzArgs (
@@ -534,7 +552,8 @@ contract CrossChainDispatcher is ReentrancyGuard, CrossChainDispatcherStorageV1
534
552
requestId_: _requestId,
535
553
sgPoolId_: _sgPoolId,
536
554
account_: _account,
537
- amountOutMin_: _amountOutMin
555
+ amountOutMin_: _amountOutMin,
556
+ callbackTxNativeFee_: _callbackTxNativeFee
538
557
});
539
558
}
540
559
0 commit comments