Skip to content

Commit

Permalink
improve: Make MockSpokePool.depositV2 virtual (#430)
Browse files Browse the repository at this point in the history
* 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

* Update MockSpokePool.sol

* Update package.json

* WIP

* Update HubPool.Fixture.ts
  • Loading branch information
nicholaspai authored Feb 9, 2024
1 parent 0944d6a commit a208a1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
20 changes: 2 additions & 18 deletions contracts/test/MockSpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,14 @@ contract MockSpokePool is SpokePool, OwnableUpgradeable {
uint32 quoteTimestamp,
bytes memory message,
uint256 // maxCount
) public payable nonReentrant unpausedDeposits {
// Check that deposit route is enabled.
require(enabledDepositRoutes[originToken][destinationChainId], "Disabled route");

// We limit the relay fees to prevent the user spending all their funds on fees.
require(SignedMath.abs(relayerFeePct) < 0.5e18, "Invalid relayer fee");
require(amount <= MAX_TRANSFER_SIZE, "Amount too large");

// Require that quoteTimestamp has a maximum age so that depositors pay an LP fee based on recent HubPool usage.
// It is assumed that cross-chain timestamps are normally loosely in-sync, but clock drift can occur. If the
// SpokePool time stalls or lags significantly, it is still possible to make deposits by setting quoteTimestamp
// within the configured buffer. The owner should pause deposits if this is undesirable. This will underflow if
// quoteTimestamp is more than depositQuoteTimeBuffer; this is safe but will throw an unintuitive error.

// slither-disable-next-line timestamp
require(getCurrentTime() - quoteTimestamp <= depositQuoteTimeBuffer, "invalid quoteTimestamp");

) public payable virtual nonReentrant unpausedDeposits {
// Increment count of deposits so that deposit ID for this spoke pool is unique.
uint32 newDepositId = numberOfDeposits++;

// If the address of the origin token is a wrappedNativeToken contract and there is a msg.value with the
// transaction then the user is sending ETH. In this case, the ETH should be deposited to wrappedNativeToken.
if (originToken == address(wrappedNativeToken) && msg.value > 0) {
require(msg.value == amount, "msg.value must match amount");
require(msg.value == amount);
wrappedNativeToken.deposit{ value: msg.value }();
// Else, it is a normal ERC20. In this case pull the token from the user's wallet as per normal.
// Note: this includes the case where the L2 user has WETH (already wrapped ETH) and wants to bridge them.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@across-protocol/contracts-v2",
"version": "2.5.0-beta.4",
"version": "2.5.0-beta.5",
"author": "UMA Team",
"license": "AGPL-3.0-only",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/HubPool.Fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const hubPoolFixture = hre.deployments.createFixture(async ({ ethers }) =
return await deployHubPool(ethers);
});

export async function deployHubPool(ethers: any) {
export async function deployHubPool(ethers: any, spokePoolName = "MockSpokePool") {
const [signer, crossChainAdmin] = await ethers.getSigners();

// This fixture is dependent on the UMA ecosystem fixture. Run it first and grab the output. This is used in the
Expand Down Expand Up @@ -44,7 +44,7 @@ export async function deployHubPool(ethers: any) {
// Deploy a mock chain adapter and add it as the chainAdapter for the test chainId. Set the SpokePool to address 0.
const mockAdapter = await (await getContractFactory("Mock_Adapter", signer)).deploy();
const mockSpoke = await hre.upgrades.deployProxy(
await getContractFactory("MockSpokePool", signer),
await getContractFactory(spokePoolName, signer),
[0, crossChainAdmin.address, hubPool.address],
{ kind: "uups", unsafeAllow: ["delegatecall"], constructorArgs: [weth.address] }
);
Expand All @@ -55,7 +55,7 @@ export async function deployHubPool(ethers: any) {
const mainnetChainId = await hre.getChainId();
const mockAdapterMainnet = await (await getContractFactory("Mock_Adapter", signer)).deploy();
const mockSpokeMainnet = await hre.upgrades.deployProxy(
await getContractFactory("MockSpokePool", signer),
await getContractFactory(spokePoolName, signer),
[0, crossChainAdmin.address, hubPool.address],
{ kind: "uups", unsafeAllow: ["delegatecall"], constructorArgs: [weth.address] }
);
Expand Down

0 comments on commit a208a1f

Please sign in to comment.