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
28 changes: 15 additions & 13 deletions contracts/HubPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
bool depositsEnabled
);
event ProposeRootBundle(
uint32 requestExpirationTimestamp,
uint64 unclaimedPoolRebalanceLeafCount,
uint32 challengePeriodEndTimestamp,
uint64 poolRebalanceLeafCount,
uint256[] bundleEvaluationBlockNumbers,
bytes32 indexed poolRebalanceRoot,
bytes32 indexed relayerRefundRoot,
Expand All @@ -159,10 +159,10 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
uint256 groupIndex,
uint256 indexed leafId,
uint256 indexed chainId,
address[] l1Token,
address[] l1Tokens,
uint256[] bundleLpFees,
int256[] netSendAmount,
int256[] runningBalance,
int256[] netSendAmounts,
int256[] runningBalances,
address indexed caller
);
event SpokePoolAdminFunctionTriggered(uint256 indexed chainId, bytes message);
Expand Down Expand Up @@ -558,11 +558,11 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
// technically valid but not useful. This could also potentially be enforced at the UMIP-level.
require(poolRebalanceLeafCount > 0, "Bundle must have at least 1 leaf");

uint32 requestExpirationTimestamp = uint32(getCurrentTime()) + liveness;
uint32 challengePeriodEndTimestamp = uint32(getCurrentTime()) + liveness;

delete rootBundleProposal; // Only one bundle of roots can be executed at a time.

rootBundleProposal.requestExpirationTimestamp = requestExpirationTimestamp;
rootBundleProposal.challengePeriodEndTimestamp = challengePeriodEndTimestamp;
rootBundleProposal.unclaimedPoolRebalanceLeafCount = poolRebalanceLeafCount;
rootBundleProposal.poolRebalanceRoot = poolRebalanceRoot;
rootBundleProposal.relayerRefundRoot = relayerRefundRoot;
Expand All @@ -573,7 +573,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
bondToken.safeTransferFrom(msg.sender, address(this), bondAmount);

emit ProposeRootBundle(
requestExpirationTimestamp,
challengePeriodEndTimestamp,
poolRebalanceLeafCount,
bundleEvaluationBlockNumbers,
poolRebalanceRoot,
Expand Down Expand Up @@ -610,7 +610,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
address[] memory l1Tokens,
bytes32[] memory proof
) public nonReentrant unpaused {
require(getCurrentTime() > rootBundleProposal.requestExpirationTimestamp, "Not passed liveness");
require(getCurrentTime() > rootBundleProposal.challengePeriodEndTimestamp, "Not passed liveness");

// Verify the leafId in the poolRebalanceLeaf has not yet been claimed.
require(!MerkleLib.isClaimed1D(rootBundleProposal.claimedBitMap, leafId), "Already claimed");
Expand Down Expand Up @@ -702,7 +702,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
*/
function disputeRootBundle() public nonReentrant zeroOptimisticOracleApproval {
uint32 currentTime = uint32(getCurrentTime());
require(currentTime <= rootBundleProposal.requestExpirationTimestamp, "Request passed liveness");
require(currentTime <= rootBundleProposal.challengePeriodEndTimestamp, "Request passed liveness");

// Request price from OO and dispute it.
uint256 finalFee = _getBondTokenFinalFee();
Expand Down Expand Up @@ -948,10 +948,12 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable {
// that will flow from L2 to L1. In this case, we can use it normally in the equation. However, if it is
// negative, then it is already counted in liquidReserves. This occurs if tokens are transferred directly to the
// contract. In this case, ignore it as it is captured in liquid reserves and has no meaning in the numerator.
PooledToken memory pooledToken = pooledTokens[l1Token]; // Note this is storage so the state can be modified.
uint256 flooredUtilizedReserves = pooledToken.utilizedReserves > 0 ? uint256(pooledToken.utilizedReserves) : 0;
PooledToken memory pooledL1Token = pooledTokens[l1Token];
uint256 flooredUtilizedReserves = pooledL1Token.utilizedReserves > 0
? uint256(pooledL1Token.utilizedReserves) // If positive: take the uint256 cast utilizedReserves.
: 0; // Else, if negative, then the is already captured in liquidReserves and should be ignored.
uint256 numerator = relayedAmount + flooredUtilizedReserves;
uint256 denominator = pooledToken.liquidReserves + flooredUtilizedReserves;
uint256 denominator = pooledL1Token.liquidReserves + flooredUtilizedReserves;

// If the denominator equals zero, return 1e18 (max utilization).
if (denominator == 0) return 1e18;
Expand Down
6 changes: 3 additions & 3 deletions contracts/HubPoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface HubPoolInterface {
// - Send funds from a SpokePool to Relayer as a refund for a relayed deposit
// - Send funds from a SpokePool to a deposit recipient to fulfill a "slow" relay
// Anyone can dispute this struct if the merkle roots contain invalid leaves before the
// requestExpirationTimestamp. Once the expiration timestamp is passed, executeRootBundle to execute a leaf
// challengePeriodEndTimestamp. Once the expiration timestamp is passed, executeRootBundle to execute a leaf
// from the poolRebalanceRoot on this contract and it will simultaneously publish the relayerRefundRoot and
// slowRelayRoot to a SpokePool. The latter two roots, once published to the SpokePool, contain
// leaves that can be executed on the SpokePool to pay relayers or recipients.
Expand All @@ -68,7 +68,7 @@ interface HubPoolInterface {
// of leaves are executed, a new root bundle can be proposed
uint8 unclaimedPoolRebalanceLeafCount;
// When root bundle challenge period passes and this root bundle becomes executable.
uint32 requestExpirationTimestamp;
uint32 challengePeriodEndTimestamp;
}

// Each whitelisted L1 token has an associated pooledToken struct that contains all information used to track the
Expand Down Expand Up @@ -131,7 +131,7 @@ interface HubPoolInterface {

function liquidityUtilizationCurrent(address l1Token) external returns (uint256);

function liquidityUtilizationPostRelay(address token, uint256 relayedAmount) external returns (uint256);
function liquidityUtilizationPostRelay(address l1Token, uint256 relayedAmount) external returns (uint256);

function sync(address l1Token) external;

Expand Down
7 changes: 4 additions & 3 deletions contracts/LpTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ contract LpTokenFactory is LpTokenFactoryInterface {
*/
function createLpToken(address l1Token) public returns (address) {
ExpandedERC20 lpToken = new ExpandedERC20(
_append("Across V2 ", IERC20Metadata(l1Token).name(), " LP Token"), // LP Token Name
_append("Av2-", IERC20Metadata(l1Token).symbol(), "-LP"), // LP Token Symbol
_concatenate("Across V2 ", IERC20Metadata(l1Token).name(), " LP Token"), // LP Token Name
_concatenate("Av2-", IERC20Metadata(l1Token).symbol(), "-LP"), // LP Token Symbol
IERC20Metadata(l1Token).decimals() // LP Token Decimals
);

lpToken.addMinter(msg.sender); // Set the caller as the LP Token's minter.
lpToken.addBurner(msg.sender); // Set the caller as the LP Token's burner.
lpToken.resetOwner(msg.sender); // Set the caller as the LP Token's owner.

return address(lpToken);
}

function _append(
function _concatenate(
string memory a,
string memory b,
string memory c
Expand Down
16 changes: 8 additions & 8 deletions contracts/Optimism_SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ contract Optimism_SpokePool is CrossDomainEnabled, SpokePool {
* ETH over the canonical token bridge instead of WETH.
* @inheritdoc SpokePool
*/
function executeSlowRelayRoot(
function executeSlowRelayLeaf(
address depositor,
address recipient,
address destinationToken,
Expand All @@ -86,9 +86,9 @@ contract Optimism_SpokePool is CrossDomainEnabled, SpokePool {
uint32 rootBundleId,
bytes32[] memory proof
) public override(SpokePool) nonReentrant {
if (destinationToken == address(weth)) _depositEthToWeth();
if (destinationToken == address(wrappedNativeToken)) _depositEthToWeth();

_executeSlowRelayRoot(
_executeSlowRelayLeaf(
depositor,
recipient,
destinationToken,
Expand All @@ -108,14 +108,14 @@ contract Optimism_SpokePool is CrossDomainEnabled, SpokePool {
* ETH over the canonical token bridge instead of WETH.
* @inheritdoc SpokePool
*/
function executeRelayerRefundRoot(
function executeRelayerRefundLeaf(
uint32 rootBundleId,
SpokePoolInterface.RelayerRefundLeaf memory relayerRefundLeaf,
bytes32[] memory proof
) public override(SpokePool) nonReentrant {
if (relayerRefundLeaf.l2TokenAddress == address(weth)) _depositEthToWeth();
if (relayerRefundLeaf.l2TokenAddress == address(wrappedNativeToken)) _depositEthToWeth();

_executeRelayerRefundRoot(rootBundleId, relayerRefundLeaf, proof);
_executeRelayerRefundLeaf(rootBundleId, relayerRefundLeaf, proof);
}

/**************************************
Expand All @@ -127,13 +127,13 @@ contract Optimism_SpokePool is CrossDomainEnabled, SpokePool {
// this logic inside a fallback method that executes when this contract receives ETH because ETH is an ERC20
// on the OVM.
function _depositEthToWeth() internal {
if (address(this).balance > 0) weth.deposit{ value: address(this).balance }();
if (address(this).balance > 0) wrappedNativeToken.deposit{ value: address(this).balance }();
}

function _bridgeTokensToHubPool(RelayerRefundLeaf memory relayerRefundLeaf) internal override {
// If the token being bridged is WETH then we need to first unwrap it to ETH and then send ETH over the
// canonical bridge. On Optimism, this is address 0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000.
if (relayerRefundLeaf.l2TokenAddress == address(weth)) {
if (relayerRefundLeaf.l2TokenAddress == address(wrappedNativeToken)) {
WETH9(relayerRefundLeaf.l2TokenAddress).withdraw(relayerRefundLeaf.amountToReturn); // Unwrap into ETH.
relayerRefundLeaf.l2TokenAddress = l2Eth; // Set the l2TokenAddress to ETH.
}
Expand Down
9 changes: 4 additions & 5 deletions contracts/Polygon_SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool {
* @param _polygonTokenBridger Token routing contract that sends tokens from here to HubPool. Changeable by Admin.
* @param _crossDomainAdmin Cross domain admin to set. Can be changed by admin.
* @param _hubPool Hub pool address to set. Can be changed by admin.
* @param _wmaticAddress Replaces _wethAddress for this network since MATIC is the gas token and sent via msg.value
* on Polygon.
* @param _wmaticAddress Replaces wrappedNativeToken for this network since MATIC is the native currency on polygon.
* @param _fxChild FxChild contract, changeable by Admin.
* @param timerAddress Timer address to set.
*/
Expand All @@ -83,7 +82,7 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool {
}

/********************************************************
* ARBITRUM-SPECIFIC CROSS-CHAIN ADMIN FUNCTIONS *
* POLYGON-SPECIFIC CROSS-CHAIN ADMIN FUNCTIONS *
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated but saw this comment issue.

********************************************************/

/**
Expand Down Expand Up @@ -138,11 +137,11 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool {
relayerRefundLeaf.amountToReturn
);

// Note: WETH is WMATIC on matic, so this tells the tokenbridger that this is an unwrappable native token.
// Note: WrappedNativeToken is WMATIC on matic, so this tells the tokenbridger that this is an unwrappable native token.
polygonTokenBridger.send(
PolygonIERC20(relayerRefundLeaf.l2TokenAddress),
relayerRefundLeaf.amountToReturn,
address(weth) == relayerRefundLeaf.l2TokenAddress
address(wrappedNativeToken) == relayerRefundLeaf.l2TokenAddress
);

emit PolygonTokensBridged(relayerRefundLeaf.l2TokenAddress, address(this), relayerRefundLeaf.amountToReturn);
Expand Down
Loading