Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions contracts/HubPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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;
Expand Down Expand Up @@ -222,7 +222,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");
_;
}

Expand Down Expand Up @@ -289,8 +289,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.
*/
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -477,7 +477,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.
Expand Down Expand Up @@ -580,12 +580,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.
Expand Down Expand Up @@ -639,7 +639,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.
Expand Down Expand Up @@ -692,6 +692,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
rootBundleProposal.unclaimedPoolRebalanceLeafCount--;

// Relay each L1 token to destination chain.

// Note: if any of the keccak256(l1Tokens, chainId) combinations are not mapped to a destination token address,
// then this internal method will revert. In this case the admin will have to associate a destination token
// with each l1 token. If the destination token mapping was missing at the time of the proposal, we assume
Expand Down Expand Up @@ -724,8 +725,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);

Expand Down Expand Up @@ -777,8 +778,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
// Set reward to 0, since we'll settle proposer reward payouts directly from this contract after a root
// proposal has passed the challenge period.
0,
// Set the Optimistic oracle proposer bond for the price request. We can assume that
// bondAmount > finalFee.
// Set the Optimistic oracle proposer bond for the request. We can assume that bondAmount > finalFee.
bondAmount - finalFee,
// Set the Optimistic oracle liveness for the price request.
liveness,
Expand Down Expand Up @@ -982,7 +982,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;
Expand Down Expand Up @@ -1029,7 +1029,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) {
Expand Down Expand Up @@ -1084,7 +1084,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();
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/HubPoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.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;
Expand Down
2 changes: 1 addition & 1 deletion contracts/Polygon_SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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() {
Expand Down
7 changes: 4 additions & 3 deletions contracts/SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract contract SpokePool is SpokePoolInterface, Testable, Lockable, MultiCall
uint32 public numberOfDeposits;

// Origin token to destination token routings can be turned on or off, which can enable or disable deposits.

mapping(address => mapping(uint256 => bool)) public enabledDepositRoutes;

// Stores collection of merkle roots that can be published to this contract from the HubPool, which are referenced
Expand All @@ -56,7 +57,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;
}
Expand Down Expand Up @@ -279,7 +280,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);
Expand Down Expand Up @@ -337,7 +338,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,
Expand Down
4 changes: 2 additions & 2 deletions contracts/SpokePoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// is 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;
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/HubPool.Admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 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");
Expand Down
Loading