@@ -11,6 +11,7 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
1111contract MockSpokePool is SpokePool , OwnableUpgradeable {
1212 uint256 private chainId_;
1313 uint256 private currentTime;
14+ using SafeERC20Upgradeable for IERC20Upgradeable ;
1415
1516 event BridgedToHubPool (uint256 amount , address token );
1617 event PreLeafExecuteHook (address token );
@@ -105,4 +106,63 @@ contract MockSpokePool is SpokePool, OwnableUpgradeable {
105106 function setChainId (uint256 _chainId ) public {
106107 chainId_ = _chainId;
107108 }
109+
110+ // Use this function to unit test that relayer-v2 and sdk-v2 clients can handle FundsDeposited events while also
111+ // handling the new V3 events. This function is not explicitly tested in this repository but this contract is
112+ // exported and tested in relayer-v2 and sdk-v2 by clients that do contain logic to handle these deprecated
113+ // V2 events. After the V3 migration has taken place and there are no more FundsDeposited events queried by
114+ // the dataworker and relayer, this function can be deprecated and the V2 unit tests can be removed from
115+ // relayer-v2 and sdk-v2.
116+ function depositV2 (
117+ address recipient ,
118+ address originToken ,
119+ uint256 amount ,
120+ uint256 destinationChainId ,
121+ int64 relayerFeePct ,
122+ uint32 quoteTimestamp ,
123+ bytes memory message ,
124+ uint256 // maxCount
125+ ) public payable nonReentrant unpausedDeposits {
126+ // Check that deposit route is enabled.
127+ require (enabledDepositRoutes[originToken][destinationChainId], "Disabled route " );
128+
129+ // We limit the relay fees to prevent the user spending all their funds on fees.
130+ require (SignedMath.abs (relayerFeePct) < 0.5e18 , "Invalid relayer fee " );
131+ require (amount <= MAX_TRANSFER_SIZE, "Amount too large " );
132+
133+ // Require that quoteTimestamp has a maximum age so that depositors pay an LP fee based on recent HubPool usage.
134+ // It is assumed that cross-chain timestamps are normally loosely in-sync, but clock drift can occur. If the
135+ // SpokePool time stalls or lags significantly, it is still possible to make deposits by setting quoteTimestamp
136+ // within the configured buffer. The owner should pause deposits if this is undesirable. This will underflow if
137+ // quoteTimestamp is more than depositQuoteTimeBuffer; this is safe but will throw an unintuitive error.
138+
139+ // slither-disable-next-line timestamp
140+ require (getCurrentTime () - quoteTimestamp <= depositQuoteTimeBuffer, "invalid quoteTimestamp " );
141+
142+ // Increment count of deposits so that deposit ID for this spoke pool is unique.
143+ uint32 newDepositId = numberOfDeposits++ ;
144+
145+ // If the address of the origin token is a wrappedNativeToken contract and there is a msg.value with the
146+ // transaction then the user is sending ETH. In this case, the ETH should be deposited to wrappedNativeToken.
147+ if (originToken == address (wrappedNativeToken) && msg .value > 0 ) {
148+ require (msg .value == amount, "msg.value must match amount " );
149+ wrappedNativeToken.deposit { value: msg .value }();
150+ // Else, it is a normal ERC20. In this case pull the token from the user's wallet as per normal.
151+ // Note: this includes the case where the L2 user has WETH (already wrapped ETH) and wants to bridge them.
152+ // In this case the msg.value will be set to 0, indicating a "normal" ERC20 bridging action.
153+ } else IERC20Upgradeable (originToken).safeTransferFrom (msg .sender , address (this ), amount);
154+
155+ emit FundsDeposited (
156+ amount,
157+ chainId (),
158+ destinationChainId,
159+ relayerFeePct,
160+ newDepositId,
161+ quoteTimestamp,
162+ originToken,
163+ recipient,
164+ msg .sender ,
165+ message
166+ );
167+ }
108168}
0 commit comments