Skip to content

Commit 0944d6a

Browse files
authored
feat: Update MockSpokePool to include a depositV2 test function (#429)
* feat: Add depositV2 to MockSpokePool to support relayer-v2/sdk-v2 unit tests These unit tests expect to query FundsDeposited events so we should add a function to the MockSpokePool so that they can access these older events using functions exported out of dist/test-utils * Add back logic * Update package.json
1 parent df87470 commit 0944d6a

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

contracts/test/MockSpokePool.sol

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
1111
contract 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
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@across-protocol/contracts-v2",
3-
"version": "2.5.0-beta.3",
3+
"version": "2.5.0-beta.4",
44
"author": "UMA Team",
55
"license": "AGPL-3.0-only",
66
"repository": {

test/fixtures/SpokePool.Fixture.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function enableRoutes(spokePool: Contract, routes: DepositRoute[])
8080
}
8181
}
8282

83-
export async function deposit(
83+
export async function depositV2(
8484
spokePool: Contract,
8585
token: Contract,
8686
recipient: SignerWithAddress,
@@ -91,7 +91,7 @@ export async function deposit(
9191
quoteTimestamp?: number,
9292
message?: string
9393
): Promise<Record<string, number | BigNumber | string> | null> {
94-
await spokePool.connect(depositor).deposit(
94+
await spokePool.connect(depositor).depositV2(
9595
...getDepositParams({
9696
recipient: recipient.address,
9797
originToken: token.address,
@@ -103,7 +103,7 @@ export async function deposit(
103103
})
104104
);
105105
const [events, originChainId] = await Promise.all([
106-
spokePool.queryFilter(spokePool.filters.V3FundsDeposited()),
106+
spokePool.queryFilter(spokePool.filters.FundsDeposited()),
107107
spokePool.chainId(),
108108
]);
109109

0 commit comments

Comments
 (0)