From fe69d77285c85425b9483578fd7dc1f410eef13f Mon Sep 17 00:00:00 2001 From: chrismaree Date: Wed, 16 Mar 2022 10:00:47 +0200 Subject: [PATCH 1/3] fix[N12] Fix typographical errors Signed-off-by: chrismaree --- contracts/HubPool.sol | 34 +++++----- contracts/HubPoolInterface.sol | 2 +- contracts/Polygon_SpokePool.sol | 2 +- contracts/SpokePool.sol | 8 +-- contracts/SpokePoolInterface.sol | 4 +- test/HubPool.Admin.ts | 2 +- test/HubPool.ExecuteRootBundle.ts | 66 ++++++++++--------- test/HubPool.LiquidityProvisionFees.ts | 8 +-- test/HubPool.PooledTokenSynchronization.ts | 22 +++---- test/HubPool.ProposeRootBundle.ts | 2 +- test/HubPool.ProtocolFees.ts | 8 +-- test/MerkleLib.Proofs.ts | 24 +++---- test/MerkleLib.utils.ts | 38 +++++------ test/SpokePool.ExecuteRootBundle.ts | 44 ++++++------- test/chain-adapters/Arbitrum_Adapter.ts | 4 +- test/chain-adapters/Ethereum_Adapter.ts | 6 +- test/chain-adapters/Optimism_Adapter.ts | 8 +-- test/chain-adapters/Polygon_Adapter.ts | 8 +-- .../Arbitrum_SpokePool.ts | 7 +- .../Ethereum_SpokePool.ts | 4 +- .../Optimism_SpokePool.ts | 18 +++-- .../Polygon_SpokePool.ts | 4 +- test/gas-analytics/HubPool.RootExecution.ts | 14 ++-- .../SpokePool.RelayerRefundRootExecution.ts | 4 +- 24 files changed, 177 insertions(+), 164 deletions(-) diff --git a/contracts/HubPool.sol b/contracts/HubPool.sol index c970e0fd2..85e6cfc4d 100644 --- a/contracts/HubPool.sol +++ b/contracts/HubPool.sol @@ -100,7 +100,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { // Mapping of L1 token addresses to the associated pool information. mapping(address => PooledToken) public pooledTokens; - // Heler contracts to facilitate cross chain actions between HubPool and SpokePool for a specific network. + // Helper contracts to facilitate cross chain actions between HubPool and SpokePool for a specific network. struct CrossChainContract { address adapter; address spokePool; @@ -213,7 +213,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { event RootBundleCanceled(address indexed disputer, uint256 requestTime, bytes disputedAncillaryData); modifier noActiveRequests() { - require(!_activeRequest(), "proposal has unclaimed leafs"); + require(!_activeRequest(), "Proposal has unclaimed leaves"); _; } @@ -280,8 +280,8 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { /** * @notice Sends message to SpokePool from this contract. Callable only by owner. - * @dev This function has permission to call onlyAdmin functions on the SpokePool, so its imperative - * that this contract only allows the owner to call this method directly or indirectly. + * @dev This function has permission to call onlyAdmin functions on the SpokePool, so it's imperative that this + * contract only allows the owner to call this method directly or indirectly. * @param chainId Chain with SpokePool to send message to. * @param functionData ABI encoded function call to send to SpokePool, but can be any arbitrary data technically. */ @@ -446,7 +446,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { * @notice Deposit liquidity into this contract to earn LP fees in exchange for funding relays on SpokePools. * Caller is essentially loaning their funds to be sent from this contract to the SpokePool, where it will be used * to repay a relayer, and ultimately receives their loan back after the tokens are bridged back to this contract - * via the canonical token bridge. Then, the caller's loans are used for again. This loan cycle repeats continuously + * via the canonical token bridge. Then, the caller's loans are used again. This loan cycle repeats continuously * and the caller, or "liquidity provider" earns a continuous fee for their credit that they are extending relayers. * @notice Caller will receive an LP token representing their share of this pool. The LP token's redemption value * increments from the time that they enter the pool to reflect their accrued fees. @@ -488,7 +488,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { ExpandedIERC20(pooledTokens[l1Token].lpToken).burnFrom(msg.sender, lpTokenAmount); // Note this method does not make any liquidity utilization checks before letting the LP redeem their LP tokens. - // If they try access more funds that available (i.e l1TokensToReturn > liquidReserves) this will underflow. + // If they try access more funds than available (i.e l1TokensToReturn > liquidReserves) this will underflow. pooledTokens[l1Token].liquidReserves -= l1TokensToReturn; if (sendEth) _unwrapWETHTo(payable(msg.sender), l1TokensToReturn); @@ -544,12 +544,12 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { *************************************************/ /** - * @notice Publish a new root bundle to along with all of the block numbers that the merkle roots are relevant for. + * @notice Publish a new root bundle along with all of the block numbers that the merkle roots are relevant for. * This is used to aid off-chain validators in evaluating the correctness of this bundle. Caller stakes a bond that * can be slashed if the root bundle proposal is invalid, and they will receive it back if accepted. * @notice After proposeRootBundle is called, if the any props are wrong then this proposal can be challenged. * Once the challenge period passes, then the roots are no longer disputable, and only executeRootBundle can be - * called; moreover, this method can't be called again until all leafs are executed. + * called; moreover, this method can't be called again until all leaves are executed. * @param bundleEvaluationBlockNumbers should contain the latest block number for all chains, even if there are no * relays contained on some of them. The usage of this variable should be defined in an off chain UMIP. * @param poolRebalanceLeafCount Number of leaves contained in pool rebalance root. Max is the number of whitelisted chains. @@ -603,7 +603,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { * @notice Deletes the published root bundle if this is the last leaf to be executed in the root bundle. * @param chainId ChainId number of the target spoke pool on which the bundle is executed. * @param groupIndex If set to 0, then relay roots to SpokePool via cross chain bridge. Used by off-chain validator - * to organize leafs with the same chain ID and also set which leaves should result in relayed messages. + * to organize leaves with the same chain ID and also set which leaves should result in relayed messages. * @param bundleLpFees Array representing the total LP fee amount per token in this bundle for all bundled relays. * @param netSendAmounts Array representing the amount of tokens to send to the SpokePool on the target chainId. * @param runningBalances Array used to track any unsent tokens that are not included in the netSendAmounts. @@ -646,8 +646,8 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { ); // Make sure SpokePool address is initialized since _sendTokensToChainAndUpdatePooledTokenTrackers() will not - // revert if its accidentally set to address(0). We don't make the same check on the adapter for this - // chainId because the internal method's delegatecall() to the adapter will revert if its address is set + // revert if it's accidentally set to address(0). We don't make the same check on the adapter for this + // chainId because the internal method's delegatecall() to the adapter will revert if it's address is set // incorrectly. address spokePool = crossChainContracts[chainId].spokePool; require(spokePool != address(0), "Uninitialized spoke pool"); @@ -659,7 +659,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { rootBundleProposal.unclaimedPoolRebalanceLeafCount--; // Relay each L1 token to destination chain. - // Note: We don't check that the adapter is initialized since if its the zero address or invalid otherwise, + // Note: We don't check that the adapter is initialized since if it's the zero address or invalid otherwise, // then the delegate call should revert. address adapter = crossChainContracts[chainId].adapter; _sendTokensToChainAndUpdatePooledTokenTrackers( @@ -689,8 +689,8 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { require(success, "delegatecall failed"); } - // Transfer the bondAmount to back to the proposer, if this the last executed leaf. Only sending this once all - // leafs have been executed acts to force the data worker to execute all bundles or they wont receive their bond. + // Transfer the bondAmount back to the proposer, if this the last executed leaf. Only sending this once all + // leaves have been executed acts to force the data worker to execute all bundles or they won't receive their bond. if (rootBundleProposal.unclaimedPoolRebalanceLeafCount == 0) bondToken.safeTransfer(rootBundleProposal.proposer, bondAmount); @@ -947,7 +947,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { // Calculate the unallocated accumulatedFees from the last time the contract was called. function _getAccumulatedFees(uint256 undistributedLpFees, uint256 lastLpFeeUpdate) internal view returns (uint256) { // accumulatedFees := min(undistributedLpFees * lpFeeRatePerSecond * timeFromLastInteraction, undistributedLpFees) - // The min acts to pay out all fees in the case the equation returns more than the remaining a fees. + // The min acts to pay out all fees in the case the equation returns more than the remaining fees. uint256 timeFromLastInteraction = getCurrentTime() - lastLpFeeUpdate; uint256 maxUndistributedLpFees = (undistributedLpFees * lpFeeRatePerSecond * timeFromLastInteraction) / (1e18); return maxUndistributedLpFees < undistributedLpFees ? maxUndistributedLpFees : undistributedLpFees; @@ -994,7 +994,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { uint256 lpFeesCaptured = bundleLpFees - protocolFeesCaptured; // Assign any LP fees included into the bundle to the pooled token. These LP fees are tracked in the - // undistributedLpFees and within the utilizedReserves. undistributedLpFees is gradually decrease + // undistributedLpFees and within the utilizedReserves. undistributedLpFees is gradually decreased // over the smear duration to give the LPs their rewards over a period of time. Adding to utilizedReserves // acts to track these rewards after the smear duration. See _exchangeRateCurrent for more details. if (lpFeesCaptured > 0) { @@ -1044,7 +1044,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { } // Added to enable the HubPool to receive ETH. This will occur both when the HubPool unwraps WETH to send to LPs and - // when ETH is send over the canonical Optimism bridge, which sends ETH. + // when ETH is sent over the canonical Optimism bridge, which sends ETH. fallback() external payable { _depositEthToWeth(); } diff --git a/contracts/HubPoolInterface.sol b/contracts/HubPoolInterface.sol index 692ac40d2..6e69c3b38 100644 --- a/contracts/HubPoolInterface.sol +++ b/contracts/HubPoolInterface.sol @@ -10,7 +10,7 @@ import "./interfaces/AdapterInterface.sol"; interface HubPoolInterface { // This leaf is meant to be decoded in the HubPool to rebalance tokens between HubPool and SpokePool. struct PoolRebalanceLeaf { - // This is used to know which chain to send cross-chain transactions to (and which SpokePool to sent to). + // This is used to know which chain to send cross-chain transactions to (and which SpokePool to send to). uint256 chainId; // Total LP fee amount per token in this bundle, encompassing all associated bundled relays. uint256[] bundleLpFees; diff --git a/contracts/Polygon_SpokePool.sol b/contracts/Polygon_SpokePool.sol index 142456afb..70173c361 100644 --- a/contracts/Polygon_SpokePool.sol +++ b/contracts/Polygon_SpokePool.sol @@ -40,7 +40,7 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool { // Note: validating calls this way ensures that strange calls coming from the fxChild won't be misinterpreted. // Put differently, just checking that msg.sender == fxChild is not sufficient. - // All calls that have admin priviledges must be fired from within the processMessageFromRoot method that's gone + // All calls that have admin privileges must be fired from within the processMessageFromRoot method that's gone // through validation where the sender is checked and the root (mainnet) sender is also validated. // This modifier sets the callValidated variable so this condition can be checked in _requireAdminSender(). modifier validateInternalCalls() { diff --git a/contracts/SpokePool.sol b/contracts/SpokePool.sol index c42cec6f8..f5f3d9e66 100644 --- a/contracts/SpokePool.sol +++ b/contracts/SpokePool.sol @@ -48,7 +48,7 @@ abstract contract SpokePool is SpokePoolInterface, Testable, Lockable, MultiCall // Count of deposits is used to construct a unique deposit identifier for this spoke pool. uint32 public numberOfDeposits; - // Origin token to destination token routings can be turned on or off, which can enable or disable deposits. + // Origin token to destination chainId routings can be turned on or off, which can enable or disable deposits. // A reverse mapping is stored on the L1 HubPool to enable or disable rebalance transfers from the HubPool to this // contract. mapping(address => mapping(uint256 => bool)) public enabledDepositRoutes; @@ -60,7 +60,7 @@ abstract contract SpokePool is SpokePoolInterface, Testable, Lockable, MultiCall bytes32 slowRelayRoot; // Merkle root of relayer refunds for successful relays. bytes32 relayerRefundRoot; - // This is a 2D bitmap tracking which leafs in the relayer refund root have been claimed, with max size of + // This is a 2D bitmap tracking which leaves in the relayer refund root have been claimed, with max size of // 256x256 leaves per root. mapping(uint256 => uint256) claimedBitmap; } @@ -285,7 +285,7 @@ abstract contract SpokePool is SpokePoolInterface, Testable, Lockable, MultiCall if (originToken == address(weth) && msg.value > 0) { require(msg.value == amount, "msg.value must match amount"); weth.deposit{ value: msg.value }(); - // Else, it is a normal ERC20. In this case pull the token from the users wallet as per normal. + // 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. // In this case the msg.value will be set to 0, indicating a "normal" ERC20 bridging action. } else IERC20(originToken).safeTransferFrom(msg.sender, address(this), amount); @@ -343,7 +343,7 @@ abstract contract SpokePool is SpokePoolInterface, Testable, Lockable, MultiCall **************************************/ /** - * @notice Called by relayer to fulfill part of a deposit by sending destination tokens to the receipient. + * @notice Called by relayer to fulfill part of a deposit by sending destination tokens to the recipient. * Relayer is expected to pass in unique identifying information for deposit that they want to fulfill, and this * relay submission will be validated by off-chain data workers who can dispute this relay if any part is invalid. * If the relay is valid, then the relayer will be refunded on their desired repayment chain. If relay is invalid, diff --git a/contracts/SpokePoolInterface.sol b/contracts/SpokePoolInterface.sol index 5f49b0ca8..fba0c025d 100644 --- a/contracts/SpokePoolInterface.sol +++ b/contracts/SpokePoolInterface.sol @@ -8,7 +8,7 @@ interface SpokePoolInterface { // This leaf is meant to be decoded in the SpokePool to pay out successful relayers. struct RelayerRefundLeaf { // This is the amount to return to the HubPool. This occurs when there is a PoolRebalanceLeaf netSendAmount that is - // negative. This is just that value inverted. + // negative. This is just the negative of this value. uint256 amountToReturn; // Used to verify that this is being executed on the correct destination chainId. uint256 chainId; @@ -24,7 +24,7 @@ interface SpokePoolInterface { // This struct represents the data to fully specify a relay. If any portion of this data differs, the relay is // considered to be completely distinct. Only one relay for a particular depositId, chainId pair should be - // considered valid and repaid. This data is hashed and inserted into a the slow relay merkle root so that an off + // considered valid and repaid. This data is hashed and inserted into the slow relay merkle root so that an off // chain validator can choose when to refund slow relayers. struct RelayData { // The address that made the deposit on the origin chain. diff --git a/test/HubPool.Admin.ts b/test/HubPool.Admin.ts index 107ac60be..f501cdb15 100644 --- a/test/HubPool.Admin.ts +++ b/test/HubPool.Admin.ts @@ -127,7 +127,7 @@ describe("HubPool Admin functions", function () { await seedWallet(owner, [], weth, totalBond); await weth.approve(hubPool.address, totalBond); await hubPool.proposeRootBundle([1, 2, 3], 5, mockTreeRoot, mockTreeRoot, mockSlowRelayRoot); - await expect(hubPool.setBond(usdc.address, "1")).to.be.revertedWith("proposal has unclaimed leafs"); + await expect(hubPool.setBond(usdc.address, "1")).to.be.revertedWith("proposal has unclaimed leaves"); }); it("Cannot change bond token to unwhitelisted token", async function () { await expect(hubPool.setBond(randomAddress(), "1")).to.be.revertedWith("Not on whitelist"); diff --git a/test/HubPool.ExecuteRootBundle.ts b/test/HubPool.ExecuteRootBundle.ts index cfd40be1a..4d0cc5367 100644 --- a/test/HubPool.ExecuteRootBundle.ts +++ b/test/HubPool.ExecuteRootBundle.ts @@ -1,19 +1,19 @@ import { toBNWei, SignerWithAddress, seedWallet, expect, Contract, ethers } from "./utils"; import * as consts from "./constants"; import { hubPoolFixture, enableTokensForLP } from "./fixtures/HubPool.Fixture"; -import { buildPoolRebalanceLeafTree, buildPoolRebalanceLeafs } from "./MerkleLib.utils"; +import { buildPoolRebalanceLeafTree, buildPoolRebalanceLeaves } from "./MerkleLib.utils"; import { ZERO_ADDRESS } from "@uma/common"; let hubPool: Contract, mockAdapter: Contract, weth: Contract, dai: Contract, mockSpoke: Contract, timer: Contract; let owner: SignerWithAddress, dataWorker: SignerWithAddress, liquidityProvider: SignerWithAddress; let l2Weth: string, l2Dai: string; -// Construct the leafs that will go into the merkle tree. For this function create a simple set of leafs that will +// Construct the leaves that will go into the merkle tree. For this function create a simple set of leaves that will // repay two token to one chain Id with simple lpFee, netSend and running balance amounts. async function constructSimpleTree() { const wethToSendToL2 = toBNWei(100); const daiToSend = toBNWei(1000); - const leafs = buildPoolRebalanceLeafs( + const leaves = buildPoolRebalanceLeaves( [consts.repaymentChainId, consts.repaymentChainId], // repayment chain. [[weth.address, dai.address], []], // l1Token. We will only be sending WETH and DAI to the associated repayment chain. [[toBNWei(1), toBNWei(10)], []], // bundleLpFees. Set to 1 ETH and 10 DAI respectively to attribute to the LPs. @@ -21,9 +21,9 @@ async function constructSimpleTree() { [[wethToSendToL2, daiToSend], []], // runningBalances. Set to 100 ETH and 1000 DAI. [0, 1] // groupIndex. Second leaf should not relay roots to spoke pool. ); - const tree = await buildPoolRebalanceLeafTree(leafs); + const tree = await buildPoolRebalanceLeafTree(leaves); - return { wethToSendToL2, daiToSend, leafs, tree }; + return { wethToSendToL2, daiToSend, leaves, tree }; } describe("HubPool Root Bundle Execution", function () { @@ -43,10 +43,10 @@ describe("HubPool Root Bundle Execution", function () { }); it("Executing root bundle correctly produces the relay bundle call and sends repayment actions", async function () { - const { wethToSendToL2, daiToSend, leafs, tree } = await constructSimpleTree(); + const { wethToSendToL2, daiToSend, leaves, tree } = await constructSimpleTree(); await hubPool.connect(dataWorker).proposeRootBundle( - [3117, 3118], // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leafs. + [3117, 3118], // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leaves. 2, // poolRebalanceLeafCount. tree.getHexRoot(), // poolRebalanceRoot. Generated from the merkle tree constructed before. consts.mockRelayerRefundRoot, // Not relevant for this test. @@ -56,7 +56,7 @@ describe("HubPool Root Bundle Execution", function () { // Advance time so the request can be executed and execute first leaf. await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); expect( - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])) + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])) ).to.emit(hubPool, "RootBundleExecuted"); // Balances should have updated as expected. Note that pool should still have bond remaining since a leaf @@ -101,7 +101,7 @@ describe("HubPool Root Bundle Execution", function () { }); it("Executing two leaves with the same chain ID does not relay root bundle to spoke pool twice", async function () { - const { leafs, tree } = await constructSimpleTree(); + const { leaves, tree } = await constructSimpleTree(); await hubPool .connect(dataWorker) @@ -109,8 +109,8 @@ describe("HubPool Root Bundle Execution", function () { // Advance time so the request can be executed and execute two leaves with same chain ID. await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[1]), tree.getHexProof(leafs[1])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[1]), tree.getHexProof(leaves[1])); // Since the mock adapter is delegatecalled, when querying, its address should be the hubPool address. const mockAdapterAtHubPool = mockAdapter.attach(hubPool.address); @@ -132,7 +132,7 @@ describe("HubPool Root Bundle Execution", function () { }); it("Executing all leaves returns bond to proposer", async function () { - const { leafs, tree } = await constructSimpleTree(); + const { leaves, tree } = await constructSimpleTree(); await hubPool .connect(dataWorker) @@ -140,17 +140,17 @@ describe("HubPool Root Bundle Execution", function () { // Advance time so the request can be executed and execute both leaves. await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // Second execution sends bond back to data worker. const bondAmount = consts.bondAmount.add(consts.finalFee); expect( - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[1]), tree.getHexProof(leafs[1])) + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[1]), tree.getHexProof(leaves[1])) ).to.changeTokenBalances(weth, [dataWorker, hubPool], [bondAmount, bondAmount.mul(-1)]); }); it("Reverts if spoke pool not set for chain ID", async function () { - const { leafs, tree } = await constructSimpleTree(); + const { leaves, tree } = await constructSimpleTree(); await hubPool .connect(dataWorker) @@ -162,12 +162,12 @@ describe("HubPool Root Bundle Execution", function () { // Advance time so the request can be executed and check that executing the request reverts. await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); await expect( - hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])) + hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])) ).to.be.revertedWith("Uninitialized spoke pool"); }); it("Execution rejects leaf claim before liveness passed", async function () { - const { leafs, tree } = await constructSimpleTree(); + const { leaves, tree } = await constructSimpleTree(); await hubPool .connect(dataWorker) .proposeRootBundle([3117, 3118], 2, tree.getHexRoot(), consts.mockRelayerRefundRoot, consts.mockSlowRelayRoot); @@ -176,16 +176,16 @@ describe("HubPool Root Bundle Execution", function () { await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness - 10); await expect( - hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])) + hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])) ).to.be.revertedWith("Not passed liveness"); // Set time after expiration. Should no longer revert. await timer.setCurrentTime(Number(await timer.getCurrentTime()) + 11); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); }); - it("Execution rejects invalid leafs", async function () { - const { leafs, tree } = await constructSimpleTree(); + it("Execution rejects invalid leaves", async function () { + const { leaves, tree } = await constructSimpleTree(); await hubPool .connect(dataWorker) .proposeRootBundle([3117, 3118], 2, tree.getHexRoot(), consts.mockRelayerRefundRoot, consts.mockSlowRelayRoot); @@ -193,28 +193,28 @@ describe("HubPool Root Bundle Execution", function () { // Take the valid root but change some element within it, such as the chainId. This will change the hash of the leaf // and as such the contract should reject it for not being included within the merkle tree for the valid proof. - const badLeaf = { ...leafs[0], chainId: 13371 }; + const badLeaf = { ...leaves[0], chainId: 13371 }; await expect( - hubPool.connect(dataWorker).executeRootBundle(...Object.values(badLeaf), tree.getHexProof(leafs[0])) + hubPool.connect(dataWorker).executeRootBundle(...Object.values(badLeaf), tree.getHexProof(leaves[0])) ).to.be.revertedWith("Bad Proof"); }); - it("Execution rejects double claimed leafs", async function () { - const { leafs, tree } = await constructSimpleTree(); + it("Execution rejects double claimed leaves", async function () { + const { leaves, tree } = await constructSimpleTree(); await hubPool .connect(dataWorker) .proposeRootBundle([3117, 3118], 2, tree.getHexRoot(), consts.mockRelayerRefundRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); // First claim should be fine. Second claim should be reverted as you cant double claim a leaf. - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); await expect( - hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])) + hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])) ).to.be.revertedWith("Already claimed"); }); it("Cannot execute while paused", async function () { - const { leafs, tree } = await constructSimpleTree(); + const { leaves, tree } = await constructSimpleTree(); await hubPool .connect(dataWorker) @@ -225,12 +225,14 @@ describe("HubPool Root Bundle Execution", function () { // Should revert while paused. await hubPool.setPaused(true); - await expect(hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0]))) - .to.be.reverted; + await expect( + hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])) + ).to.be.reverted; // Should not revert after unpaused. await hubPool.setPaused(false); - await expect(hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0]))) - .to.not.be.reverted; + await expect( + hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])) + ).to.not.be.reverted; }); }); diff --git a/test/HubPool.LiquidityProvisionFees.ts b/test/HubPool.LiquidityProvisionFees.ts index 59a094ae2..8d8547529 100644 --- a/test/HubPool.LiquidityProvisionFees.ts +++ b/test/HubPool.LiquidityProvisionFees.ts @@ -27,13 +27,13 @@ describe("HubPool Liquidity Provision Fees", function () { expect(pooledTokenInfoPreExecution.undistributedLpFees).to.equal(0); expect(pooledTokenInfoPreExecution.lastLpFeeUpdate).to.equal(await timer.getCurrentTime()); - const { tokensSendToL2, realizedLpFees, leafs, tree } = await constructSingleChainTree(weth.address); + const { tokensSendToL2, realizedLpFees, leaves, tree } = await constructSingleChainTree(weth.address); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // Validate the post execution values have updated as expected. Liquid reserves should be the original LPed amount // minus the amount sent to L2. Utilized reserves should be the amount sent to L2 plus the attribute to LPs. @@ -49,7 +49,7 @@ describe("HubPool Liquidity Provision Fees", function () { // Fees are designed to be attributed over a period of time so they dont all arrive on L1 as soon as the bundle is // executed. We can validate that fees are correctly smeared by attributing some and then moving time forward and // validating that key variable shift as a function of time. - const { leafs, tree } = await constructSingleChainTree(weth.address); + const { leaves, tree } = await constructSingleChainTree(weth.address); // Exchange rate current before any fees are attributed execution should be 1. expect(await hubPool.callStatic.exchangeRateCurrent(weth.address)).to.equal(toWei(1)); @@ -59,7 +59,7 @@ describe("HubPool Liquidity Provision Fees", function () { .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // Exchange rate current right after the refund execution should be the amount deposited, grown by the 100 second // liveness period. Of the 10 ETH attributed to LPs, a total of 10*0.0000015*7201=0.108015 was attributed to LPs. diff --git a/test/HubPool.PooledTokenSynchronization.ts b/test/HubPool.PooledTokenSynchronization.ts index 8e4c18988..2e370cbfb 100644 --- a/test/HubPool.PooledTokenSynchronization.ts +++ b/test/HubPool.PooledTokenSynchronization.ts @@ -32,7 +32,7 @@ describe("HubPool Pooled Token Synchronization", function () { expect(await hubPool.callStatic.exchangeRateCurrent(weth.address)).to.equal(toWei(1)); // Execute a relayer refund. Check counters move accordingly. - const { tokensSendToL2, realizedLpFees, leafs, tree } = await constructSingleChainTree(weth.address); + const { tokensSendToL2, realizedLpFees, leaves, tree } = await constructSingleChainTree(weth.address); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); @@ -43,7 +43,7 @@ describe("HubPool Pooled Token Synchronization", function () { // Counters should move once the root bundle is executed. await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); expect((await hubPool.pooledTokens(weth.address)).liquidReserves).to.equal(consts.amountToLp.sub(tokensSendToL2)); expect((await hubPool.pooledTokens(weth.address)).utilizedReserves).to.equal(tokensSendToL2.add(realizedLpFees)); @@ -102,7 +102,7 @@ describe("HubPool Pooled Token Synchronization", function () { // Liquidity utilization starts off at 0 before any actions are done. expect(await hubPool.callStatic.liquidityUtilizationCurrent(weth.address)).to.equal(0); // Execute a relayer refund. Check counters move accordingly. - const { tokensSendToL2, realizedLpFees, leafs, tree } = await constructSingleChainTree(weth.address); + const { tokensSendToL2, realizedLpFees, leaves, tree } = await constructSingleChainTree(weth.address); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); @@ -110,7 +110,7 @@ describe("HubPool Pooled Token Synchronization", function () { // Liquidity is not used until the relayerRefund is executed(i.e "pending" reserves are not considered). expect(await hubPool.callStatic.liquidityUtilizationCurrent(weth.address)).to.equal(0); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // Now that the liquidity is used (sent to L2) we should be able to find the utilization. This should simply be // the utilizedReserves / (liquidReserves + utilizedReserves) = 110 / (900 + 110) = 0.108910891089108910 @@ -173,7 +173,7 @@ describe("HubPool Pooled Token Synchronization", function () { expect(await hubPool.callStatic.liquidityUtilizationPostRelay(weth.address, toBNWei(100))).to.equal(toBNWei(0.1)); // Execute a relay refund bundle to increase the liquidity utilization. - const { leafs, tree } = await constructSingleChainTree(weth.address); + const { leaves, tree } = await constructSingleChainTree(weth.address); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); @@ -181,7 +181,7 @@ describe("HubPool Pooled Token Synchronization", function () { // Liquidity is not used until the relayerRefund is executed(i.e "pending" reserves are not considered). expect(await hubPool.callStatic.liquidityUtilizationCurrent(weth.address)).to.equal(0); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // Now that the liquidity is used (sent to L2) we should be able to find the utilization. This should simply be // the utilizedReserves / (liquidReserves + utilizedReserves) = 110 / (900 + 110) = 0.108910891089108910 @@ -189,12 +189,12 @@ describe("HubPool Pooled Token Synchronization", function () { }); it("High liquidity utilization blocks LPs from withdrawing", async function () { // Execute a relayer refund bundle. Set the scalingSize to 5. This will use 500 ETH from the hubPool. - const { leafs, tree } = await constructSingleChainTree(weth.address, 5); + const { leaves, tree } = await constructSingleChainTree(weth.address, 5); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + 10 * 24 * 60 * 60); // Move time to accumulate all fees. // Liquidity utilization should now be (550) / (500 + 550) = 0.523809523809523809. I.e utilization is over 50%. @@ -222,12 +222,12 @@ describe("HubPool Pooled Token Synchronization", function () { await expect(hubPool.connect(liquidityProvider).removeLiquidity(weth.address, 1, false)).to.be.reverted; }); it("Redeeming all LP tokens, after accruing fees, is handled correctly", async function () { - const { leafs, tree, tokensSendToL2, realizedLpFees } = await constructSingleChainTree(weth.address); + const { leaves, tree, tokensSendToL2, realizedLpFees } = await constructSingleChainTree(weth.address); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + 10 * 24 * 60 * 60); // Move time to accumulate all fees. // Send back to L1 the tokensSendToL2 + realizedLpFees, i.e to mimic the finalization of the relay. @@ -260,7 +260,7 @@ describe("HubPool Pooled Token Synchronization", function () { .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockTreeRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + 10 * 24 * 60 * 60); // Move time to accumulate all fees. // Exchange rate should be 1.01, with 1% accumulated on the back of refunds with no memory of the previous fees. diff --git a/test/HubPool.ProposeRootBundle.ts b/test/HubPool.ProposeRootBundle.ts index f8cf8e53d..a28139780 100644 --- a/test/HubPool.ProposeRootBundle.ts +++ b/test/HubPool.ProposeRootBundle.ts @@ -60,7 +60,7 @@ describe("HubPool Root Bundle Proposal", function () { consts.mockRelayerRefundRoot, consts.mockSlowRelayRoot ) - ).to.be.revertedWith("proposal has unclaimed leafs"); + ).to.be.revertedWith("proposal has unclaimed leaves"); }); it("Cannot propose while paused", async function () { diff --git a/test/HubPool.ProtocolFees.ts b/test/HubPool.ProtocolFees.ts index ea7444f1f..2607f2d6d 100644 --- a/test/HubPool.ProtocolFees.ts +++ b/test/HubPool.ProtocolFees.ts @@ -41,10 +41,10 @@ describe("HubPool Protocol fees", function () { expect(await hubPool.callStatic.protocolFeeCapturePct()).to.equal(newPct); }); it("When fee capture pct is not set to zero fees correctly attribute between LPs and the protocol", async function () { - const { leafs, tree, realizedLpFees } = await constructSingleChainTree(weth.address); + const { leaves, tree, realizedLpFees } = await constructSingleChainTree(weth.address); await hubPool.connect(dataWorker).proposeRootBundle([3117], 1, tree.getHexRoot(), mockTreeRoot, mockTreeRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // 90% of the fees should be attributed to the LPs. expect((await hubPool.pooledTokens(weth.address)).undistributedLpFees).to.equal( @@ -72,10 +72,10 @@ describe("HubPool Protocol fees", function () { }); it("When fee capture pct is set to zero all fees accumulate to the LPs", async function () { await hubPool.setProtocolFeeCapture(owner.address, "0"); - const { leafs, tree, realizedLpFees } = await constructSingleChainTree(weth.address); + const { leaves, tree, realizedLpFees } = await constructSingleChainTree(weth.address); await hubPool.connect(dataWorker).proposeRootBundle([3117], 1, tree.getHexRoot(), mockTreeRoot, mockTreeRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); expect((await hubPool.pooledTokens(weth.address)).undistributedLpFees).to.equal(realizedLpFees); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + 10 * 24 * 60 * 60); // Move time to accumulate all fees. diff --git a/test/MerkleLib.Proofs.ts b/test/MerkleLib.Proofs.ts index 7c45c5636..19fb69ce7 100644 --- a/test/MerkleLib.Proofs.ts +++ b/test/MerkleLib.Proofs.ts @@ -12,7 +12,7 @@ describe("MerkleLib Proofs", async function () { }); it("PoolRebalanceLeaf Proof", async function () { - const poolRebalanceLeafs: PoolRebalanceLeaf[] = []; + const poolRebalanceLeaves: PoolRebalanceLeaf[] = []; const numRebalances = 101; for (let i = 0; i < numRebalances; i++) { const numTokens = 10; @@ -26,7 +26,7 @@ describe("MerkleLib Proofs", async function () { netSendAmounts.push(randomBigNumber()); runningBalances.push(randomBigNumber()); } - poolRebalanceLeafs.push({ + poolRebalanceLeaves.push({ leafId: BigNumber.from(i), chainId: randomBigNumber(), l1Tokens, @@ -38,22 +38,22 @@ describe("MerkleLib Proofs", async function () { } // Remove the last element. - const invalidPoolRebalanceLeaf = poolRebalanceLeafs.pop()!; + const invalidPoolRebalanceLeaf = poolRebalanceLeaves.pop()!; const paramType = await getParamType("MerkleLibTest", "verifyPoolRebalance", "rebalance"); const hashFn = (input: PoolRebalanceLeaf) => keccak256(defaultAbiCoder.encode([paramType!], [input])); - const merkleTree = new MerkleTree(poolRebalanceLeafs, hashFn); + const merkleTree = new MerkleTree(poolRebalanceLeaves, hashFn); const root = merkleTree.getHexRoot(); - const proof = merkleTree.getHexProof(poolRebalanceLeafs[34]); - expect(await merkleLibTest.verifyPoolRebalance(root, poolRebalanceLeafs[34], proof)).to.equal(true); + const proof = merkleTree.getHexProof(poolRebalanceLeaves[34]); + expect(await merkleLibTest.verifyPoolRebalance(root, poolRebalanceLeaves[34], proof)).to.equal(true); // Verify that the excluded element fails to generate a proof and fails verification using the proof generated above. expect(() => merkleTree.getHexProof(invalidPoolRebalanceLeaf)).to.throw(); expect(await merkleLibTest.verifyPoolRebalance(root, invalidPoolRebalanceLeaf, proof)).to.equal(false); }); it("RelayerRefundLeafProof", async function () { - const relayerRefundLeafs: RelayerRefundLeaf[] = []; + const relayerRefundLeaves: RelayerRefundLeaf[] = []; const numDistributions = 101; // Create 101 and remove the last to use as the "invalid" one. for (let i = 0; i < numDistributions; i++) { const numAddresses = 10; @@ -63,7 +63,7 @@ describe("MerkleLib Proofs", async function () { refundAddresses.push(randomAddress()); refundAmounts.push(randomBigNumber()); } - relayerRefundLeafs.push({ + relayerRefundLeaves.push({ leafId: BigNumber.from(i), chainId: randomBigNumber(2), amountToReturn: randomBigNumber(), @@ -74,15 +74,15 @@ describe("MerkleLib Proofs", async function () { } // Remove the last element. - const invalidRelayerRefundLeaf = relayerRefundLeafs.pop()!; + const invalidRelayerRefundLeaf = relayerRefundLeaves.pop()!; const paramType = await getParamType("MerkleLibTest", "verifyRelayerRefund", "refund"); const hashFn = (input: RelayerRefundLeaf) => keccak256(defaultAbiCoder.encode([paramType!], [input])); - const merkleTree = new MerkleTree(relayerRefundLeafs, hashFn); + const merkleTree = new MerkleTree(relayerRefundLeaves, hashFn); const root = merkleTree.getHexRoot(); - const proof = merkleTree.getHexProof(relayerRefundLeafs[14]); - expect(await merkleLibTest.verifyRelayerRefund(root, relayerRefundLeafs[14], proof)).to.equal(true); + const proof = merkleTree.getHexProof(relayerRefundLeaves[14]); + expect(await merkleLibTest.verifyRelayerRefund(root, relayerRefundLeaves[14], proof)).to.equal(true); // Verify that the excluded element fails to generate a proof and fails verification using the proof generated above. expect(() => merkleTree.getHexProof(invalidRelayerRefundLeaf)).to.throw(); diff --git a/test/MerkleLib.utils.ts b/test/MerkleLib.utils.ts index 131698a24..05acbd9f3 100644 --- a/test/MerkleLib.utils.ts +++ b/test/MerkleLib.utils.ts @@ -21,18 +21,18 @@ export interface RelayerRefundLeaf { refundAddresses: string[]; } -export async function buildRelayerRefundTree(relayerRefundLeafs: RelayerRefundLeaf[]) { - for (let i = 0; i < relayerRefundLeafs.length; i++) { +export async function buildRelayerRefundTree(relayerRefundLeaves: RelayerRefundLeaf[]) { + for (let i = 0; i < relayerRefundLeaves.length; i++) { // The 2 provided parallel arrays must be of equal length. - expect(relayerRefundLeafs[i].refundAddresses.length).to.equal(relayerRefundLeafs[i].refundAmounts.length); + expect(relayerRefundLeaves[i].refundAddresses.length).to.equal(relayerRefundLeaves[i].refundAmounts.length); } const paramType = await getParamType("MerkleLibTest", "verifyRelayerRefund", "refund"); const hashFn = (input: RelayerRefundLeaf) => keccak256(defaultAbiCoder.encode([paramType!], [input])); - return new MerkleTree(relayerRefundLeafs, hashFn); + return new MerkleTree(relayerRefundLeaves, hashFn); } -export function buildRelayerRefundLeafs( +export function buildRelayerRefundLeaves( destinationChainIds: number[], amountsToReturn: BigNumber[], l2Tokens: string[], @@ -53,21 +53,21 @@ export function buildRelayerRefundLeafs( }); } -export async function buildPoolRebalanceLeafTree(poolRebalanceLeafs: PoolRebalanceLeaf[]) { - for (let i = 0; i < poolRebalanceLeafs.length; i++) { +export async function buildPoolRebalanceLeafTree(poolRebalanceLeaves: PoolRebalanceLeaf[]) { + for (let i = 0; i < poolRebalanceLeaves.length; i++) { // The 4 provided parallel arrays must be of equal length. - expect(poolRebalanceLeafs[i].l1Tokens.length) - .to.equal(poolRebalanceLeafs[i].bundleLpFees.length) - .to.equal(poolRebalanceLeafs[i].netSendAmounts.length) - .to.equal(poolRebalanceLeafs[i].runningBalances.length); + expect(poolRebalanceLeaves[i].l1Tokens.length) + .to.equal(poolRebalanceLeaves[i].bundleLpFees.length) + .to.equal(poolRebalanceLeaves[i].netSendAmounts.length) + .to.equal(poolRebalanceLeaves[i].runningBalances.length); } const paramType = await getParamType("MerkleLibTest", "verifyPoolRebalance", "rebalance"); const hashFn = (input: PoolRebalanceLeaf) => keccak256(defaultAbiCoder.encode([paramType!], [input])); - return new MerkleTree(poolRebalanceLeafs, hashFn); + return new MerkleTree(poolRebalanceLeaves, hashFn); } -export function buildPoolRebalanceLeafs( +export function buildPoolRebalanceLeaves( destinationChainIds: number[], l1Tokens: string[][], bundleLpFees: BigNumber[][], @@ -91,7 +91,7 @@ export function buildPoolRebalanceLeafs( } export async function constructSingleRelayerRefundTree(l2Token: Contract | String, destinationChainId: number) { - const leafs = buildRelayerRefundLeafs( + const leaves = buildRelayerRefundLeaves( [destinationChainId], // Destination chain ID. [amountToReturn], // amountToReturn. [l2Token as string], // l2Token. @@ -99,15 +99,15 @@ export async function constructSingleRelayerRefundTree(l2Token: Contract | Strin [[]] // refundAmounts. ); - const tree = await buildRelayerRefundTree(leafs); + const tree = await buildRelayerRefundTree(leaves); - return { leafs, tree }; + return { leaves, tree }; } export async function constructSingleChainTree(token: string, scalingSize = 1, repaymentChain = repaymentChainId) { const tokensSendToL2 = toBNWei(100 * scalingSize); const realizedLpFees = toBNWei(10 * scalingSize); - const leafs = buildPoolRebalanceLeafs( + const leaves = buildPoolRebalanceLeaves( [repaymentChain], // repayment chain. In this test we only want to send one token to one chain. [[token]], // l1Token. We will only be sending 1 token to one chain. [[realizedLpFees]], // bundleLpFees. @@ -115,9 +115,9 @@ export async function constructSingleChainTree(token: string, scalingSize = 1, r [[tokensSendToL2]], // runningBalances. [0] // groupIndex ); - const tree = await buildPoolRebalanceLeafTree(leafs); + const tree = await buildPoolRebalanceLeafTree(leaves); - return { tokensSendToL2, realizedLpFees, leafs, tree }; + return { tokensSendToL2, realizedLpFees, leaves, tree }; } export async function buildSlowRelayTree(relays: RelayData[]) { diff --git a/test/SpokePool.ExecuteRootBundle.ts b/test/SpokePool.ExecuteRootBundle.ts index 4b2762af5..8f336e96d 100644 --- a/test/SpokePool.ExecuteRootBundle.ts +++ b/test/SpokePool.ExecuteRootBundle.ts @@ -1,7 +1,7 @@ import { SignerWithAddress, seedContract, toBN, expect, Contract, ethers } from "./utils"; import * as consts from "./constants"; import { spokePoolFixture } from "./fixtures/SpokePool.Fixture"; -import { buildRelayerRefundTree, buildRelayerRefundLeafs } from "./MerkleLib.utils"; +import { buildRelayerRefundTree, buildRelayerRefundLeaves } from "./MerkleLib.utils"; let spokePool: Contract, destErc20: Contract, weth: Contract; let dataWorker: SignerWithAddress, relayer: SignerWithAddress, rando: SignerWithAddress; @@ -9,19 +9,19 @@ let dataWorker: SignerWithAddress, relayer: SignerWithAddress, rando: SignerWith let destinationChainId: number; async function constructSimpleTree(l2Token: Contract, destinationChainId: number) { - const leafs = buildRelayerRefundLeafs( + const leaves = buildRelayerRefundLeaves( [destinationChainId, destinationChainId], // Destination chain ID. [consts.amountToReturn, toBN(0)], // amountToReturn. [l2Token.address, l2Token.address], // l2Token. [[relayer.address, rando.address], []], // refundAddresses. [[consts.amountToRelay, consts.amountToRelay], []] // refundAmounts. ); - const leafsRefundAmount = leafs + const leavesRefundAmount = leaves .map((leaf) => leaf.refundAmounts.reduce((bn1, bn2) => bn1.add(bn2), toBN(0))) .reduce((bn1, bn2) => bn1.add(bn2), toBN(0)); - const tree = await buildRelayerRefundTree(leafs); + const tree = await buildRelayerRefundTree(leaves); - return { leafs, leafsRefundAmount, tree }; + return { leaves, leavesRefundAmount, tree }; } describe("SpokePool Root Bundle Execution", function () { beforeEach(async function () { @@ -34,7 +34,7 @@ describe("SpokePool Root Bundle Execution", function () { }); it("Execute relayer root correctly sends tokens to recipients", async function () { - const { leafs, leafsRefundAmount, tree } = await constructSimpleTree(destErc20, destinationChainId); + const { leaves, leavesRefundAmount, tree } = await constructSimpleTree(destErc20, destinationChainId); // Store new tree. await spokePool.connect(dataWorker).relayRootBundle( @@ -43,10 +43,10 @@ describe("SpokePool Root Bundle Execution", function () { ); // Distribute the first leaf. - await spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0])); + await spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0])); // Relayers should be refunded - expect(await destErc20.balanceOf(spokePool.address)).to.equal(consts.amountHeldByPool.sub(leafsRefundAmount)); + expect(await destErc20.balanceOf(spokePool.address)).to.equal(consts.amountHeldByPool.sub(leavesRefundAmount)); expect(await destErc20.balanceOf(relayer.address)).to.equal(consts.amountToRelay); expect(await destErc20.balanceOf(rando.address)).to.equal(consts.amountToRelay); @@ -65,7 +65,7 @@ describe("SpokePool Root Bundle Execution", function () { expect(tokensBridgedEvents.length).to.equal(1); // Does not attempt to bridge tokens if amountToReturn is 0. Execute a leaf where amountToReturn is 0. - await spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leafs[1], tree.getHexProof(leafs[1])); + await spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leaves[1], tree.getHexProof(leaves[1])); // Show that a second DistributedRelayRefund event was emitted but not a second TokensBridged event. relayTokensEvents = await spokePool.queryFilter(spokePool.filters.ExecutedRelayerRefundRoot()); expect(relayTokensEvents.length).to.equal(2); @@ -74,7 +74,7 @@ describe("SpokePool Root Bundle Execution", function () { }); it("Execution rejects invalid leaf, tree, proof combinations", async function () { - const { leafs, tree } = await constructSimpleTree(destErc20, destinationChainId); + const { leaves, tree } = await constructSimpleTree(destErc20, destinationChainId); await spokePool.connect(dataWorker).relayRootBundle( tree.getHexRoot(), // distribution root. Generated from the merkle tree constructed before. consts.mockSlowRelayRoot @@ -82,36 +82,36 @@ describe("SpokePool Root Bundle Execution", function () { // Take the valid root but change some element within it. This will change the hash of the leaf // and as such the contract should reject it for not being included within the merkle tree for the valid proof. - const badLeaf = { ...leafs[0], chainId: 13371 }; - await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(0, badLeaf, tree.getHexProof(leafs[0]))).to.be + const badLeaf = { ...leaves[0], chainId: 13371 }; + await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(0, badLeaf, tree.getHexProof(leaves[0]))).to.be .reverted; // Reverts if the distribution root index is incorrect. - await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(1, leafs[0], tree.getHexProof(leafs[0]))).to.be - .reverted; + await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(1, leaves[0], tree.getHexProof(leaves[0]))).to + .be.reverted; }); it("Cannot refund leaf with chain ID for another network", async function () { // Create tree for another chain ID - const { leafs, tree } = await constructSimpleTree(destErc20, 13371); + const { leaves, tree } = await constructSimpleTree(destErc20, 13371); await spokePool.connect(dataWorker).relayRootBundle( tree.getHexRoot(), // distribution root. Generated from the merkle tree constructed before. consts.mockSlowRelayRoot ); // Root is valid and leaf is contained in tree, but chain ID doesn't match pool's chain ID. - await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0]))).to.be - .reverted; + await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0]))).to + .be.reverted; }); - it("Execution rejects double claimed leafs", async function () { - const { leafs, tree } = await constructSimpleTree(destErc20, destinationChainId); + it("Execution rejects double claimed leaves", async function () { + const { leaves, tree } = await constructSimpleTree(destErc20, destinationChainId); await spokePool.connect(dataWorker).relayRootBundle( tree.getHexRoot(), // distribution root. Generated from the merkle tree constructed before. consts.mockSlowRelayRoot ); // First claim should be fine. Second claim should be reverted as you cant double claim a leaf. - await spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0])); - await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0]))).to.be - .reverted; + await spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0])); + await expect(spokePool.connect(dataWorker).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0]))).to + .be.reverted; }); }); diff --git a/test/chain-adapters/Arbitrum_Adapter.ts b/test/chain-adapters/Arbitrum_Adapter.ts index e80e4a03d..f88d81645 100644 --- a/test/chain-adapters/Arbitrum_Adapter.ts +++ b/test/chain-adapters/Arbitrum_Adapter.ts @@ -78,12 +78,12 @@ describe("Arbitrum Chain Adapter", function () { it("Correctly calls appropriate arbitrum bridge functions when making ERC20 cross chain calls", async function () { // Create an action that will send an L1->L2 tokens transfer and bundle. For this, create a relayer repayment bundle // and check that at it's finalization the L2 bridge contracts are called as expected. - const { leafs, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, arbitrumChainId); + const { leaves, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, arbitrumChainId); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockRelayerRefundRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // The correct functions should have been called on the arbitrum contracts. expect(l1ERC20Gateway.outboundTransfer).to.have.been.calledOnce; // One token transfer over the canonical bridge. expect(l1ERC20Gateway.outboundTransfer).to.have.been.calledWith( diff --git a/test/chain-adapters/Ethereum_Adapter.ts b/test/chain-adapters/Ethereum_Adapter.ts index cc4e42d4e..4e6dcb71f 100644 --- a/test/chain-adapters/Ethereum_Adapter.ts +++ b/test/chain-adapters/Ethereum_Adapter.ts @@ -48,12 +48,14 @@ describe("Ethereum Chain Adapter", function () { expect(await mockSpoke.crossDomainAdmin()).to.equal(newAdmin); }); it("Correctly transfers tokens when executing pool rebalance", async function () { - const { leafs, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, l1ChainId); + const { leaves, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, l1ChainId); await hubPool .connect(dataWorker) .proposeRootBundle([3117], 1, tree.getHexRoot(), consts.mockRelayerRefundRoot, consts.mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + consts.refundProposalLiveness + 1); - expect(await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0]))) + expect( + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])) + ) .to.emit(ethAdapter.attach(hubPool.address), "TokensRelayed") .withArgs(dai.address, dai.address, tokensSendToL2, mockSpoke.address); }); diff --git a/test/chain-adapters/Optimism_Adapter.ts b/test/chain-adapters/Optimism_Adapter.ts index 4d14c0423..a8fac9a33 100644 --- a/test/chain-adapters/Optimism_Adapter.ts +++ b/test/chain-adapters/Optimism_Adapter.ts @@ -65,10 +65,10 @@ describe("Optimism Chain Adapter", function () { it("Correctly calls appropriate Optimism bridge functions when making ERC20 cross chain calls", async function () { // Create an action that will send an L1->L2 tokens transfer and bundle. For this, create a relayer repayment bundle // and check that at it's finalization the L2 bridge contracts are called as expected. - const { leafs, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, optimismChainId); + const { leaves, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, optimismChainId); await hubPool.connect(dataWorker).proposeRootBundle([3117], 1, tree.getHexRoot(), mockTreeRoot, mockTreeRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // The correct functions should have been called on the optimism contracts. expect(l1StandardBridge.depositERC20To).to.have.been.calledOnce; // One token transfer over the bridge. @@ -84,10 +84,10 @@ describe("Optimism Chain Adapter", function () { }); it("Correctly unwraps WETH and bridges ETH", async function () { // Cant bridge WETH on optimism. Rather, unwrap WETH to ETH then bridge it. Validate the adapter does this. - const { leafs, tree } = await constructSingleChainTree(weth.address, 1, optimismChainId); + const { leaves, tree } = await constructSingleChainTree(weth.address, 1, optimismChainId); await hubPool.connect(dataWorker).proposeRootBundle([3117], 1, tree.getHexRoot(), mockTreeRoot, mockTreeRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // The correct functions should have been called on the optimism contracts. expect(l1StandardBridge.depositETHTo).to.have.been.calledOnce; // One eth transfer over the bridge. diff --git a/test/chain-adapters/Polygon_Adapter.ts b/test/chain-adapters/Polygon_Adapter.ts index b6dd4111e..12796c6c8 100644 --- a/test/chain-adapters/Polygon_Adapter.ts +++ b/test/chain-adapters/Polygon_Adapter.ts @@ -62,10 +62,10 @@ describe("Polygon Chain Adapter", function () { it("Correctly calls appropriate Polygon bridge functions when making ERC20 cross chain calls", async function () { // Create an action that will send an L1->L2 tokens transfer and bundle. For this, create a relayer repayment bundle // and check that at it's finalization the L2 bridge contracts are called as expected. - const { leafs, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, polygonChainId); + const { leaves, tree, tokensSendToL2 } = await constructSingleChainTree(dai.address, 1, polygonChainId); await hubPool.connect(dataWorker).proposeRootBundle([3117], 1, tree.getHexRoot(), mockTreeRoot, mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // The correct functions should have been called on the polygon contracts. expect(rootChainManager.depositFor).to.have.been.calledOnce; // One token transfer over the bridge. @@ -85,10 +85,10 @@ describe("Polygon Chain Adapter", function () { }); it("Correctly unwraps WETH and bridges ETH", async function () { // Cant bridge WETH on polygon. Rather, unwrap WETH to ETH then bridge it. Validate the adapter does this. - const { leafs, tree } = await constructSingleChainTree(weth.address, 1, polygonChainId); + const { leaves, tree } = await constructSingleChainTree(weth.address, 1, polygonChainId); await hubPool.connect(dataWorker).proposeRootBundle([3117], 1, tree.getHexRoot(), mockTreeRoot, mockSlowRelayRoot); await timer.setCurrentTime(Number(await timer.getCurrentTime()) + refundProposalLiveness + 1); - await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leafs[0]), tree.getHexProof(leafs[0])); + await hubPool.connect(dataWorker).executeRootBundle(...Object.values(leaves[0]), tree.getHexProof(leaves[0])); // The correct functions should have been called on the polygon contracts. expect(rootChainManager.depositEtherFor).to.have.been.calledOnce; // One eth transfer over the bridge. diff --git a/test/chain-specific-spokepools/Arbitrum_SpokePool.ts b/test/chain-specific-spokepools/Arbitrum_SpokePool.ts index a2e8dbe32..3a5e0ff36 100644 --- a/test/chain-specific-spokepools/Arbitrum_SpokePool.ts +++ b/test/chain-specific-spokepools/Arbitrum_SpokePool.ts @@ -83,9 +83,12 @@ describe("Arbitrum Spoke Pool", function () { }); it("Bridge tokens to hub pool correctly calls the Standard L2 Gateway router", async function () { - const { leafs, tree } = await constructSingleRelayerRefundTree(l2Dai, await arbitrumSpokePool.callStatic.chainId()); + const { leaves, tree } = await constructSingleRelayerRefundTree( + l2Dai, + await arbitrumSpokePool.callStatic.chainId() + ); await arbitrumSpokePool.connect(crossDomainAlias).relayRootBundle(tree.getHexRoot(), mockTreeRoot); - await arbitrumSpokePool.connect(relayer).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0])); + await arbitrumSpokePool.connect(relayer).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0])); // This should have sent tokens back to L1. Check the correct methods on the gateway are correctly called. // outboundTransfer is overloaded in the arbitrum gateway. Define the interface to check the method is called. diff --git a/test/chain-specific-spokepools/Ethereum_SpokePool.ts b/test/chain-specific-spokepools/Ethereum_SpokePool.ts index 7693c27be..6d4b8c8d0 100644 --- a/test/chain-specific-spokepools/Ethereum_SpokePool.ts +++ b/test/chain-specific-spokepools/Ethereum_SpokePool.ts @@ -62,10 +62,10 @@ describe("Ethereum Spoke Pool", function () { }); it("Bridge tokens to hub pool correctly sends tokens to hub pool", async function () { - const { leafs, tree } = await constructSingleRelayerRefundTree(dai.address, await spokePool.callStatic.chainId()); + const { leaves, tree } = await constructSingleRelayerRefundTree(dai.address, await spokePool.callStatic.chainId()); await spokePool.connect(owner).relayRootBundle(tree.getHexRoot(), mockTreeRoot); await expect(() => - spokePool.connect(relayer).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0])) + spokePool.connect(relayer).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0])) ).to.changeTokenBalances(dai, [spokePool, hubPool], [amountToReturn.mul(-1), amountToReturn]); }); }); diff --git a/test/chain-specific-spokepools/Optimism_SpokePool.ts b/test/chain-specific-spokepools/Optimism_SpokePool.ts index 51d1f246e..3c1195e38 100644 --- a/test/chain-specific-spokepools/Optimism_SpokePool.ts +++ b/test/chain-specific-spokepools/Optimism_SpokePool.ts @@ -96,35 +96,41 @@ describe("Optimism Spoke Pool", function () { }); it("Bridge tokens to hub pool correctly calls the Standard L2 Bridge for ERC20", async function () { - const { leafs, tree } = await constructSingleRelayerRefundTree(l2Dai, await optimismSpokePool.callStatic.chainId()); + const { leaves, tree } = await constructSingleRelayerRefundTree( + l2Dai, + await optimismSpokePool.callStatic.chainId() + ); crossDomainMessenger.xDomainMessageSender.returns(owner.address); await optimismSpokePool.connect(crossDomainMessenger.wallet).relayRootBundle(tree.getHexRoot(), mockTreeRoot); - await optimismSpokePool.connect(relayer).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0])); + await optimismSpokePool.connect(relayer).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0])); // This should have sent tokens back to L1. Check the correct methods on the gateway are correctly called. expect(l2StandardBridge.withdrawTo).to.have.been.calledOnce; expect(l2StandardBridge.withdrawTo).to.have.been.calledWith(l2Dai, hubPool.address, amountToReturn, 5000000, "0x"); }); it("Bridge tokens to hub pool correctly calls an alternative L2 Gateway router", async function () { - const { leafs, tree } = await constructSingleRelayerRefundTree(l2Dai, await optimismSpokePool.callStatic.chainId()); + const { leaves, tree } = await constructSingleRelayerRefundTree( + l2Dai, + await optimismSpokePool.callStatic.chainId() + ); crossDomainMessenger.xDomainMessageSender.returns(owner.address); await optimismSpokePool.connect(crossDomainMessenger.wallet).relayRootBundle(tree.getHexRoot(), mockTreeRoot); const altL2Bridge = await createFake("L2StandardBridge"); await optimismSpokePool.connect(crossDomainMessenger.wallet).setTokenBridge(l2Dai, altL2Bridge.address); - await optimismSpokePool.connect(relayer).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0])); + await optimismSpokePool.connect(relayer).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0])); // This should have sent tokens back to L1. Check the correct methods on the gateway are correctly called. expect(altL2Bridge.withdrawTo).to.have.been.calledOnce; expect(altL2Bridge.withdrawTo).to.have.been.calledWith(l2Dai, hubPool.address, amountToReturn, 5000000, "0x"); }); it("Bridge ETH to hub pool correctly calls the Standard L2 Bridge for WETH, including unwrap", async function () { - const { leafs, tree } = await constructSingleRelayerRefundTree( + const { leaves, tree } = await constructSingleRelayerRefundTree( l2Weth.address, await optimismSpokePool.callStatic.chainId() ); crossDomainMessenger.xDomainMessageSender.returns(owner.address); await optimismSpokePool.connect(crossDomainMessenger.wallet).relayRootBundle(tree.getHexRoot(), mockTreeRoot); - await optimismSpokePool.connect(relayer).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0])); + await optimismSpokePool.connect(relayer).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0])); // When sending l2Weth we should see two differences from the previous test: 1) there should be a call to l2WETH to // unwrap l2WETH to l2ETH. 2) the address in the l2StandardBridge that is withdrawn should no longer be l2WETH but diff --git a/test/chain-specific-spokepools/Polygon_SpokePool.ts b/test/chain-specific-spokepools/Polygon_SpokePool.ts index b49eaaf39..5b25e3940 100644 --- a/test/chain-specific-spokepools/Polygon_SpokePool.ts +++ b/test/chain-specific-spokepools/Polygon_SpokePool.ts @@ -129,7 +129,7 @@ describe("Polygon Spoke Pool", function () { }); it("Bridge tokens to hub pool correctly sends tokens through the PolygonTokenBridger", async function () { - const { leafs, tree } = await constructSingleRelayerRefundTree( + const { leaves, tree } = await constructSingleRelayerRefundTree( dai.address, await polygonSpokePool.callStatic.chainId() ); @@ -142,7 +142,7 @@ describe("Polygon Spoke Pool", function () { const bridger = await polygonSpokePool.polygonTokenBridger(); // Checks that there's a burn event from the bridger. - await expect(polygonSpokePool.connect(relayer).executeRelayerRefundRoot(0, leafs[0], tree.getHexProof(leafs[0]))) + await expect(polygonSpokePool.connect(relayer).executeRelayerRefundRoot(0, leaves[0], tree.getHexProof(leaves[0]))) .to.emit(dai, "Transfer") .withArgs(bridger, ZERO_ADDRESS, amountToReturn); }); diff --git a/test/gas-analytics/HubPool.RootExecution.ts b/test/gas-analytics/HubPool.RootExecution.ts index 8463ca5d6..9d6648394 100644 --- a/test/gas-analytics/HubPool.RootExecution.ts +++ b/test/gas-analytics/HubPool.RootExecution.ts @@ -4,7 +4,7 @@ import { deployErc20 } from "./utils"; import * as consts from "../constants"; import { ZERO_ADDRESS } from "@uma/common"; import { hubPoolFixture, enableTokensForLP } from "../fixtures/HubPool.Fixture"; -import { buildPoolRebalanceLeafTree, buildPoolRebalanceLeafs, PoolRebalanceLeaf } from "../MerkleLib.utils"; +import { buildPoolRebalanceLeafTree, buildPoolRebalanceLeaves, PoolRebalanceLeaf } from "../MerkleLib.utils"; import { MerkleTree } from "../../utils/MerkleTree"; require("dotenv").config(); @@ -41,7 +41,7 @@ async function constructSimpleTree(_destinationChainIds: number[], _l1Tokens: Co _l1TokenAddresses[i].push(_l1Tokens[j].address); } } - const leaves = buildPoolRebalanceLeafs( + const leaves = buildPoolRebalanceLeaves( _destinationChainIds, _l1TokenAddresses, _bundleLpFeeAmounts, @@ -117,7 +117,7 @@ describe("Gas Analytics: HubPool Root Bundle Execution", function () { const initTree = await constructSimpleTree([...destinationChainIds], [...l1Tokens]); await hubPool.connect(dataWorker).proposeRootBundle( - destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leafs. + destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leaves. REFUND_CHAIN_COUNT, // poolRebalanceLeafCount. There is exactly one leaf in the bundle. initTree.tree.getHexRoot(), // poolRebalanceRoot. Generated from the merkle tree constructed before. createRandomBytes32(), @@ -139,7 +139,7 @@ describe("Gas Analytics: HubPool Root Bundle Execution", function () { it("Simple proposal", async function () { const initiateTxn = await hubPool.connect(dataWorker).proposeRootBundle( - destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leafs. + destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leaves. REFUND_CHAIN_COUNT, // poolRebalanceLeafCount. There is exactly one leaf in the bundle. createRandomBytes32(), // poolRebalanceRoot. Generated from the merkle tree constructed before. createRandomBytes32(), // Not relevant for this test. @@ -152,7 +152,7 @@ describe("Gas Analytics: HubPool Root Bundle Execution", function () { const leafIndexToExecute = 0; await hubPool.connect(dataWorker).proposeRootBundle( - [consts.mockBundleEvaluationBlockNumbers[0]], // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leafs. + [consts.mockBundleEvaluationBlockNumbers[0]], // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leaves. 1, // poolRebalanceLeafCount. There is exactly one leaf in the bundle. tree.getHexRoot(), // poolRebalanceRoot. Generated from the merkle tree constructed before. consts.mockRelayerRefundRoot, // Not relevant for this test. @@ -170,7 +170,7 @@ describe("Gas Analytics: HubPool Root Bundle Execution", function () { }); it("Executing all leaves", async function () { await hubPool.connect(dataWorker).proposeRootBundle( - destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leafs. + destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leaves. REFUND_CHAIN_COUNT, // poolRebalanceLeafCount. Execute all leaves tree.getHexRoot(), // poolRebalanceRoot. Generated from the merkle tree constructed before. consts.mockRelayerRefundRoot, // Not relevant for this test. @@ -194,7 +194,7 @@ describe("Gas Analytics: HubPool Root Bundle Execution", function () { it("Executing all leaves using multicall", async function () { await hubPool.connect(dataWorker).proposeRootBundle( - destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leafs. + destinationChainIds, // bundleEvaluationBlockNumbers used by bots to construct bundles. Length must equal the number of leaves. REFUND_CHAIN_COUNT, // poolRebalanceLeafCount. Execute all leaves tree.getHexRoot(), // poolRebalanceRoot. Generated from the merkle tree constructed before. consts.mockRelayerRefundRoot, // Not relevant for this test. diff --git a/test/gas-analytics/SpokePool.RelayerRefundRootExecution.ts b/test/gas-analytics/SpokePool.RelayerRefundRootExecution.ts index 848843641..0d586c8d9 100644 --- a/test/gas-analytics/SpokePool.RelayerRefundRootExecution.ts +++ b/test/gas-analytics/SpokePool.RelayerRefundRootExecution.ts @@ -12,7 +12,7 @@ import { import { deployErc20, warmSpokePool } from "./utils"; import * as consts from "../constants"; import { spokePoolFixture } from "../fixtures/SpokePool.Fixture"; -import { RelayerRefundLeaf, buildRelayerRefundLeafs, buildRelayerRefundTree } from "../MerkleLib.utils"; +import { RelayerRefundLeaf, buildRelayerRefundLeaves, buildRelayerRefundTree } from "../MerkleLib.utils"; import { MerkleTree } from "../../utils/MerkleTree"; require("dotenv").config(); @@ -58,7 +58,7 @@ async function constructSimpleTree( _refundAddresses[i].push(refundAddresses[j]); } } - const leaves = buildRelayerRefundLeafs( + const leaves = buildRelayerRefundLeaves( _destinationChainIds, _amountsToReturn, _l2Tokens, From 4849f3a09bdd4fd20b983ee1af406fccbeee7df6 Mon Sep 17 00:00:00 2001 From: chrismaree Date: Fri, 18 Mar 2022 07:50:52 +0200 Subject: [PATCH 2/3] nit Signed-off-by: chrismaree --- test/HubPool.Admin.ts | 2 +- test/HubPool.ProposeRootBundle.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/HubPool.Admin.ts b/test/HubPool.Admin.ts index b3d08211a..b1a9780b1 100644 --- a/test/HubPool.Admin.ts +++ b/test/HubPool.Admin.ts @@ -136,7 +136,7 @@ describe("HubPool Admin functions", function () { await seedWallet(owner, [], weth, totalBond); await weth.approve(hubPool.address, totalBond); await hubPool.proposeRootBundle([1, 2, 3], 5, mockTreeRoot, mockTreeRoot, mockSlowRelayRoot); - await expect(hubPool.setBond(usdc.address, "1")).to.be.revertedWith("proposal has unclaimed leaves"); + await expect(hubPool.setBond(usdc.address, "1")).to.be.revertedWith("Proposal has unclaimed leaves"); }); it("Cannot change bond token to unwhitelisted token", async function () { await expect(hubPool.setBond(randomAddress(), "1")).to.be.revertedWith("Not on whitelist"); diff --git a/test/HubPool.ProposeRootBundle.ts b/test/HubPool.ProposeRootBundle.ts index a28139780..3d7aaf4a9 100644 --- a/test/HubPool.ProposeRootBundle.ts +++ b/test/HubPool.ProposeRootBundle.ts @@ -60,7 +60,7 @@ describe("HubPool Root Bundle Proposal", function () { consts.mockRelayerRefundRoot, consts.mockSlowRelayRoot ) - ).to.be.revertedWith("proposal has unclaimed leaves"); + ).to.be.revertedWith("Proposal has unclaimed leaves"); }); it("Cannot propose while paused", async function () { From 813cfeef126484e0ac5b7fb91225560c5edbff7c Mon Sep 17 00:00:00 2001 From: chrismaree Date: Fri, 18 Mar 2022 08:01:11 +0200 Subject: [PATCH 3/3] nit Signed-off-by: chrismaree --- contracts/HubPool.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/HubPool.sol b/contracts/HubPool.sol index 686ace17d..b94f2279d 100644 --- a/contracts/HubPool.sol +++ b/contracts/HubPool.sol @@ -361,7 +361,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { } /** - * @notice Sets identifier for root bundle disputes.. Callable only by owner. + * @notice Sets identifier for root bundle disputes. Callable only by owner. * @param newIdentifier New identifier. */ function setIdentifier(bytes32 newIdentifier) public override onlyOwner noActiveRequests nonReentrant {