@@ -8,6 +8,7 @@ import "./utils/SafeCast.sol";
88import "./interfaces/IDepositExecute.sol " ;
99import "./interfaces/IERCHandler.sol " ;
1010import "./interfaces/IGenericHandler.sol " ;
11+ import "./interfaces/IFeeHandler.sol " ;
1112
1213/**
1314 @title Facilitates deposits, creation and voting of deposit proposals, and deposit executions.
@@ -21,9 +22,10 @@ contract Bridge is Pausable, AccessControl, SafeMath {
2122
2223 uint8 public _domainID;
2324 uint8 public _relayerThreshold;
24- uint128 public _fee;
2525 uint40 public _expiry;
2626
27+ IFeeHandler public _feeHandler;
28+
2729 enum ProposalStatus {Inactive, Active, Passed, Executed, Cancelled}
2830
2931 struct Proposal {
@@ -45,6 +47,7 @@ contract Bridge is Pausable, AccessControl, SafeMath {
4547 event RelayerThresholdChanged (uint256 newThreshold );
4648 event RelayerAdded (address relayer );
4749 event RelayerRemoved (address relayer );
50+ event FeeHandlerChanged (address newFeeHandler );
4851 event Deposit (
4952 uint8 destinationDomainID ,
5053 bytes32 resourceID ,
@@ -125,10 +128,9 @@ contract Bridge is Pausable, AccessControl, SafeMath {
125128 @param initialRelayers Addresses that should be initially granted the relayer role.
126129 @param initialRelayerThreshold Number of votes needed for a deposit proposal to be considered passed.
127130 */
128- constructor (uint8 domainID , address [] memory initialRelayers , uint256 initialRelayerThreshold , uint256 fee , uint256 expiry ) public {
131+ constructor (uint8 domainID , address [] memory initialRelayers , uint256 initialRelayerThreshold , uint256 expiry ) public {
129132 _domainID = domainID;
130133 _relayerThreshold = initialRelayerThreshold.toUint8 ();
131- _fee = fee.toUint128 ();
132134 _expiry = expiry.toUint40 ();
133135
134136 _setupRole (DEFAULT_ADMIN_ROLE, _msgSender ());
@@ -315,13 +317,13 @@ contract Bridge is Pausable, AccessControl, SafeMath {
315317 }
316318
317319 /**
318- @notice Changes deposit fee.
320+ @notice Changes deposit fee handler contract address .
319321 @notice Only callable by admin.
320- @param newFee Value {_fee } will be updated to.
322+ @param newFeeHandler Address {_feeHandler } will be updated to.
321323 */
322- function adminChangeFee ( uint256 newFee ) external onlyAdmin {
323- require (_fee != newFee, " Current fee is equal to new fee " );
324- _fee = newFee. toUint128 ( );
324+ function adminChangeFeeHandler ( address newFeeHandler ) external onlyAdmin {
325+ _feeHandler = IFeeHandler (newFeeHandler );
326+ emit FeeHandlerChanged (newFeeHandler );
325327 }
326328
327329 /**
@@ -342,25 +344,31 @@ contract Bridge is Pausable, AccessControl, SafeMath {
342344 @notice Only callable when Bridge is not paused.
343345 @param destinationDomainID ID of chain deposit will be bridged to.
344346 @param resourceID ResourceID used to find address of handler to be used for deposit.
345- @param data Additional data to be passed to specified handler.
347+ @param depositData Additional data to be passed to specified handler.
348+ @param feeData Additional data to be passed to the fee handler.
346349 @notice Emits {Deposit} event with all necessary parameters and a handler response.
347350 - ERC20Handler: responds with an empty data.
348351 - ERC721Handler: responds with the deposited token metadata acquired by calling a tokenURI method in the token contract.
349352 - GenericHandler: responds with the raw bytes returned from the call to the target contract.
350353 */
351- function deposit (uint8 destinationDomainID , bytes32 resourceID , bytes calldata data ) external payable whenNotPaused {
352- require (msg .value == _fee, "Incorrect fee supplied " );
354+ function deposit (uint8 destinationDomainID , bytes32 resourceID , bytes calldata depositData , bytes calldata feeData ) external payable whenNotPaused {
355+ address sender = _msgSender ();
356+ if (address (_feeHandler) == address (0 )) {
357+ require (msg .value == 0 , "no FeeHandler, msg.value != 0 " );
358+ } else {
359+ // Reverts on failure
360+ _feeHandler.collectFee {value: msg .value }(sender, _domainID, destinationDomainID, resourceID, depositData, feeData);
361+ }
353362
354363 address handler = _resourceIDToHandlerAddress[resourceID];
355364 require (handler != address (0 ), "resourceID not mapped to handler " );
356365
357366 uint64 depositNonce = ++ _depositCounts[destinationDomainID];
358- address sender = _msgSender ();
359367
360368 IDepositExecute depositHandler = IDepositExecute (handler);
361- bytes memory handlerResponse = depositHandler.deposit (resourceID, sender, data );
369+ bytes memory handlerResponse = depositHandler.deposit (resourceID, sender, depositData );
362370
363- emit Deposit (destinationDomainID, resourceID, depositNonce, sender, data , handlerResponse);
371+ emit Deposit (destinationDomainID, resourceID, depositNonce, sender, depositData , handlerResponse);
364372 }
365373
366374 /**
@@ -489,16 +497,4 @@ contract Bridge is Pausable, AccessControl, SafeMath {
489497
490498 emit ProposalEvent (domainID, depositNonce, ProposalStatus.Executed, dataHash);
491499 }
492-
493- /**
494- @notice Transfers eth in the contract to the specified addresses. The parameters addrs and amounts are mapped 1-1.
495- This means that the address at index 0 for addrs will receive the amount (in WEI) from amounts at index 0.
496- @param addrs Array of addresses to transfer {amounts} to.
497- @param amounts Array of amonuts to transfer to {addrs}.
498- */
499- function transferFunds (address payable [] calldata addrs , uint [] calldata amounts ) external onlyAdmin {
500- for (uint256 i = 0 ; i < addrs.length ; i++ ) {
501- addrs[i].transfer (amounts[i]);
502- }
503- }
504500}
0 commit comments