-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use @openzeppelin/[email protected] contracts in contracts we can u…
…pgrade Imports an [aliased npm package](https://forum.openzeppelin.com/t/coexist-of-v5-and-v4-contracts/38030/5) so we can use multiple oz libraries in the same solidity contracts. This way we get access to new and improved contracts. I make changes to all contracts that we can upgrade, such as SpokePools and NOT the HubPool. For example, I can use the new SafeERC20 method `forceApprove` instead of `safeIncreaseAllowance` which ensures [compatibility with tokens like USDT](OpenZeppelin/openzeppelin-contracts#4231) that make sure all approvals are set to 0 before granting a new approval. This hasn't been an issue so far because we always safeIncreaseAllowance to some number and use the complete allowance, but its worth safety checking. Other changes: - Moved `MerkleDistributor` out of uma/core into this repo to reduce dependency on this external repo - Replaced isCode() call with now [recommended](OpenZeppelin/openzeppelin-contracts#3945) explicit .code.length check - Explicitly set SpokePoolVerifier pragma to 0.8.19 and removed the overrides in hardhat.config.ts - Removed unused import in PolygonERC20Test
- Loading branch information
1 parent
f56146a
commit a484de3
Showing
56 changed files
with
456 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | |
* @custom:security-contact [email protected] | ||
*/ | ||
contract Ethereum_SpokePool is SpokePool, OwnableUpgradeable { | ||
using SafeERC20Upgradeable for IERC20Upgradeable; | ||
using SafeERC20 for IERC20; | ||
|
||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor( | ||
|
@@ -35,7 +35,7 @@ contract Ethereum_SpokePool is SpokePool, OwnableUpgradeable { | |
**************************************/ | ||
|
||
function _bridgeTokensToHubPool(uint256 amountToReturn, address l2TokenAddress) internal override { | ||
IERC20Upgradeable(l2TokenAddress).safeTransfer(hubPool, amountToReturn); | ||
IERC20(l2TokenAddress).safeTransfer(hubPool, amountToReturn); | ||
} | ||
|
||
// The SpokePool deployed to the same network as the HubPool must be owned by the HubPool. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ pragma solidity ^0.8.0; | |
import "./Lockable.sol"; | ||
import "./external/interfaces/WETH9Interface.sol"; | ||
|
||
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; | ||
import "@openzeppelin/contracts5/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts5/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
// Polygon Registry contract that stores their addresses. | ||
interface PolygonRegistry { | ||
|
@@ -18,7 +18,7 @@ interface PolygonERC20Predicate { | |
} | ||
|
||
// ERC20s (on polygon) compatible with polygon's bridge have a withdraw method. | ||
interface PolygonIERC20Upgradeable is IERC20Upgradeable { | ||
interface PolygonIERC20Upgradeable is IERC20 { | ||
function withdraw(uint256 amount) external; | ||
} | ||
|
||
|
@@ -40,8 +40,8 @@ interface MaticToken { | |
* @custom:security-contact [email protected] | ||
*/ | ||
contract PolygonTokenBridger is Lockable { | ||
using SafeERC20Upgradeable for PolygonIERC20Upgradeable; | ||
using SafeERC20Upgradeable for IERC20Upgradeable; | ||
using SafeERC20 for PolygonIERC20Upgradeable; | ||
using SafeERC20 for IERC20; | ||
|
||
// Gas token for Polygon. | ||
MaticToken public constant MATIC = MaticToken(0x0000000000000000000000000000000000001010); | ||
|
@@ -121,7 +121,7 @@ contract PolygonTokenBridger is Lockable { | |
* @notice Called by someone to send tokens to the destination, which should be set to the HubPool. | ||
* @param token Token to send to destination. | ||
*/ | ||
function retrieve(IERC20Upgradeable token) public nonReentrant onlyChainId(l1ChainId) { | ||
function retrieve(IERC20 token) public nonReentrant onlyChainId(l1ChainId) { | ||
if (address(token) == address(l1Weth)) { | ||
// For WETH, there is a pre-deposit step to ensure any ETH that has been sent to the contract is captured. | ||
//slither-disable-next-line arbitrary-send-eth | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ interface IFxMessageProcessor { | |
* @custom:security-contact [email protected] | ||
*/ | ||
contract Polygon_SpokePool is IFxMessageProcessor, SpokePool, CircleCCTPAdapter { | ||
using SafeERC20Upgradeable for PolygonIERC20Upgradeable; | ||
using SafeERC20 for PolygonIERC20Upgradeable; | ||
|
||
// Address of FxChild which sends and receives messages to and from L1. | ||
address public fxChild; | ||
|
@@ -241,10 +241,7 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool, CircleCCTPAdapter | |
if (_isCCTPEnabled() && l2TokenAddress == address(usdcToken)) { | ||
_transferUsdc(hubPool, amountToReturn); | ||
} else { | ||
PolygonIERC20Upgradeable(l2TokenAddress).safeIncreaseAllowance( | ||
address(polygonTokenBridger), | ||
amountToReturn | ||
); | ||
PolygonIERC20Upgradeable(l2TokenAddress).forceApprove(address(polygonTokenBridger), amountToReturn); | ||
// Note: WrappedNativeToken is WMATIC on matic, so this tells the tokenbridger that this is an unwrappable native token. | ||
polygonTokenBridger.send(PolygonIERC20Upgradeable(l2TokenAddress), amountToReturn); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ interface IL2GatewayRouterExtended is IL2GatewayRouter { | |
* @custom:security-contact [email protected] | ||
*/ | ||
contract Scroll_SpokePool is SpokePool { | ||
using SafeERC20Upgradeable for IERC20Upgradeable; | ||
using SafeERC20 for IERC20; | ||
|
||
/** | ||
* @notice The address of the official l2GatewayRouter contract for Scroll for bridging tokens from L2 -> L1 | ||
|
@@ -99,7 +99,7 @@ contract Scroll_SpokePool is SpokePool { | |
// Tokens with a custom ERC20 gateway require an approval in order to withdraw. | ||
address erc20Gateway = l2GatewayRouter.getERC20Gateway(l2TokenAddress); | ||
if (erc20Gateway != l2GatewayRouter.defaultERC20Gateway()) { | ||
IERC20Upgradeable(l2TokenAddress).safeIncreaseAllowance(erc20Gateway, amountToReturn); | ||
IERC20(l2TokenAddress).forceApprove(erc20Gateway, amountToReturn); | ||
} | ||
|
||
// The scroll bridge handles arbitrary ERC20 tokens and is mindful of the official WETH address on-chain. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
// NOTE: Linea and Arbitrum only support 0.8.19, so keep this contract at 19 so create2 addressses for all chains are | ||
// the same. | ||
pragma solidity ^0.8.19; | ||
|
||
import "@openzeppelin/contracts/utils/Address.sol"; | ||
import "./interfaces/V3SpokePoolInterface.sol"; | ||
|
||
/** | ||
|
@@ -13,8 +14,6 @@ import "./interfaces/V3SpokePoolInterface.sol"; | |
* @custom:security-contact [email protected] | ||
*/ | ||
contract SpokePoolVerifier { | ||
using Address for address; | ||
|
||
error InvalidMsgValue(); | ||
error InvalidSpokePool(); | ||
|
||
|
@@ -54,7 +53,7 @@ contract SpokePoolVerifier { | |
bytes memory message | ||
) external payable { | ||
if (msg.value != inputAmount) revert InvalidMsgValue(); | ||
if (!address(spokePool).isContract()) revert InvalidSpokePool(); | ||
if (address(spokePool).code.length == 0) revert InvalidSpokePool(); | ||
// Set msg.sender as the depositor so that msg.sender can speed up the deposit. | ||
spokePool.depositV3{ value: msg.value }( | ||
msg.sender, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.