Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgradable warp routes #3474

Merged
merged 22 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9ee018c
Add deployAdminAndProxyContracts(). Update CollateralVault and Native…
ltyu Mar 21, 2024
4bd2d7d
Add routerContractNameConstant for backwards compatibility, refactor …
ltyu Mar 25, 2024
69bb682
Update tests for NativeScaled and ERC20
ltyu Mar 25, 2024
1bbf245
Saving work to switch over to another task rq
ltyu Mar 25, 2024
dd3c182
Add init, update unit tests
ltyu Mar 25, 2024
b5b7d8d
Clean up code
ltyu Mar 26, 2024
ce8c0a3
Merge branch 'main' into upgradable-warp-routes
ltyu Mar 26, 2024
74c3549
Remove routerContractNameConstant. Add router() logic for dependent c…
ltyu Mar 26, 2024
a0a5d3f
Merge branch 'main' into upgradable-warp-routes
ltyu Mar 26, 2024
78a9268
Remove RouterKey from class input type
ltyu Mar 26, 2024
05790e3
Merge branch 'main' into upgradable-warp-routes
ltyu Mar 26, 2024
27ad190
Fix according to PR review
ltyu Mar 27, 2024
ff3ce9a
Merge branch 'main' into upgradable-warp-routes
ltyu Mar 27, 2024
3d48777
Update to use deployContractWithName()
ltyu Mar 28, 2024
901e6c1
Fix typing
ltyu Mar 28, 2024
868e605
Merge branch 'main' into upgradable-warp-routes
ltyu Mar 28, 2024
2439dbb
Fix typing
ltyu Mar 28, 2024
d383bf0
Merge branch 'upgradable-warp-routes' of https://github.com/hyperlane…
ltyu Mar 28, 2024
073f1ea
Remove unused change
ltyu Mar 28, 2024
80bdc6d
Merge branch 'main' into upgradable-warp-routes
ltyu Mar 30, 2024
5041ac7
Add check for object
ltyu Mar 31, 2024
d8de904
Merge branch 'upgradable-warp-routes' of https://github.com/hyperlane…
ltyu Mar 31, 2024
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
6 changes: 5 additions & 1 deletion solidity/contracts/token/HypERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ contract HypERC20 is ERC20Upgradeable, TokenRouter {
function initialize(
uint256 _totalSupply,
string memory _name,
string memory _symbol
string memory _symbol,
address _hook,
address _interchainSecurityModule,
ltyu marked this conversation as resolved.
Show resolved Hide resolved
address _owner
) external initializer {
// Initialize ERC20 metadata
__ERC20_init(_name, _symbol);
_mint(msg.sender, _totalSupply);
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

function decimals() public view override returns (uint8) {
Expand Down
8 changes: 8 additions & 0 deletions solidity/contracts/token/HypERC20Collateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ contract HypERC20Collateral is TokenRouter {
wrappedToken = IERC20(erc20);
}

function initialize(
address _hook,
address _interchainSecurityModule,
address _owner
) public virtual initializer {
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

function balanceOf(
address _account
) external view override returns (uint256) {
Expand Down
8 changes: 8 additions & 0 deletions solidity/contracts/token/HypERC20CollateralVaultDeposit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@
address _mailbox
) HypERC20Collateral(_vault.asset(), _mailbox) {
vault = _vault;
}

function initialize(
address _hook,
address _interchainSecurityModule,
address _owner
) public override initializer {
wrappedToken.approve(address(vault), type(uint256).max);
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

Check warning

Code scanning / Slither

Unused return Medium


/**
* @dev Transfers `_amount` of `wrappedToken` from `msg.sender` to this contract, and deposit into vault
Expand Down
6 changes: 5 additions & 1 deletion solidity/contracts/token/HypERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ contract HypERC721 is ERC721EnumerableUpgradeable, TokenRouter {
function initialize(
uint256 _mintAmount,
string memory _name,
string memory _symbol
string memory _symbol,
address _hook,
address _interchainSecurityModule,
address _owner
) external initializer {
address owner = msg.sender;
_transferOwnership(owner);
ltyu marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -32,6 +35,7 @@ contract HypERC721 is ERC721EnumerableUpgradeable, TokenRouter {
for (uint256 i = 0; i < _mintAmount; i++) {
_safeMint(owner, i);
}
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

function balanceOf(
Expand Down
8 changes: 8 additions & 0 deletions solidity/contracts/token/HypERC721Collateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ contract HypERC721Collateral is TokenRouter {
wrappedToken = IERC721(erc721);
}

function initialize(
address _hook,
address _interchainSecurityModule,
address _owner
) public virtual initializer {
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

function ownerOf(uint256 _tokenId) external view returns (address) {
return IERC721(wrappedToken).ownerOf(_tokenId);
}
Expand Down
8 changes: 8 additions & 0 deletions solidity/contracts/token/HypNative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ contract HypNative is TokenRouter {

constructor(address _mailbox) TokenRouter(_mailbox) {}

function initialize(
address _hook,
address _interchainSecurityModule,
address _owner
) public initializer {
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

/**
* @inheritdoc TokenRouter
* @dev uses (`msg.value` - `_amount`) as interchain gas payment and `msg.sender` as refund address.
Expand Down
51 changes: 44 additions & 7 deletions solidity/test/token/HypERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pragma solidity ^0.8.13;
@@@@@@@@@ @@@@@@@@*/

import "forge-std/Test.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import {TypeCasts} from "../../contracts/libs/TypeCasts.sol";
import {TestMailbox} from "../../contracts/test/TestMailbox.sol";
Expand All @@ -40,6 +41,7 @@ abstract contract HypTokenTest is Test {
string internal constant SYMBOL = "HYP";
address internal constant ALICE = address(0x1);
address internal constant BOB = address(0x2);
address internal constant PROXY_ADMIN = address(0x37);

ERC20Test internal primaryToken;
TokenRouter internal localToken;
Expand Down Expand Up @@ -73,8 +75,24 @@ abstract contract HypTokenTest is Test {

REQUIRED_VALUE = noopHook.quoteDispatch("", "");

remoteToken = new HypERC20(DECIMALS, address(remoteMailbox));
remoteToken.initialize(TOTAL_SUPPLY, NAME, SYMBOL);
HypERC20 implementation = new HypERC20(
DECIMALS,
address(remoteMailbox)
);
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
address(implementation),
PROXY_ADMIN,
abi.encodeWithSelector(
HypERC20.initialize.selector,
TOTAL_SUPPLY,
NAME,
SYMBOL,
address(noopHook),
address(igp),
address(this)
)
);
remoteToken = HypERC20(address(proxy));
remoteToken.enrollRemoteRouter(
ORIGIN,
address(localToken).addressToBytes32()
Expand Down Expand Up @@ -188,10 +206,22 @@ contract HypERC20Test is HypTokenTest {
function setUp() public override {
super.setUp();

localToken = new HypERC20(DECIMALS, address(localMailbox));
erc20Token = HypERC20(address(localToken));

erc20Token.initialize(TOTAL_SUPPLY, NAME, SYMBOL);
HypERC20 implementation = new HypERC20(DECIMALS, address(localMailbox));
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
address(implementation),
PROXY_ADMIN,
abi.encodeWithSelector(
HypERC20.initialize.selector,
TOTAL_SUPPLY,
NAME,
SYMBOL,
address(address(noopHook)),
address(igp),
address(this)
)
);
localToken = HypERC20(address(proxy));
erc20Token = HypERC20(address(proxy));

erc20Token.enrollRemoteRouter(
DESTINATION,
Expand All @@ -204,7 +234,14 @@ contract HypERC20Test is HypTokenTest {

function testInitialize_revert_ifAlreadyInitialized() public {
vm.expectRevert("Initializable: contract is already initialized");
erc20Token.initialize(TOTAL_SUPPLY, NAME, SYMBOL);
erc20Token.initialize(
TOTAL_SUPPLY,
NAME,
SYMBOL,
address(address(noopHook)),
address(igp),
BOB
);
}

function testTotalSupply() public {
Expand Down
19 changes: 16 additions & 3 deletions solidity/test/token/HypERC20CollateralVaultDeposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pragma solidity ^0.8.13;
@@@@@@@@@ @@@@@@@@*/

import "forge-std/Test.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import {ERC4626Test} from "../../contracts/test/ERC4626/ERC4626Test.sol";
import {TypeCasts} from "../../contracts/libs/TypeCasts.sol";
import {HypTokenTest} from "./HypERC20.t.sol";
Expand All @@ -31,10 +33,21 @@ contract HypERC20CollateralVaultDepositTest is HypTokenTest {
super.setUp();
vault = new ERC4626Test(address(primaryToken), "Regular Vault", "RV");

localToken = new HypERC20CollateralVaultDeposit(
vault,
address(localMailbox)
HypERC20CollateralVaultDeposit implementation = new HypERC20CollateralVaultDeposit(
vault,
address(localMailbox)
);
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
address(implementation),
PROXY_ADMIN,
abi.encodeWithSelector(
HypERC20CollateralVaultDeposit.initialize.selector,
address(address(noopHook)),
address(igp),
address(this)
)
);
localToken = HypERC20CollateralVaultDeposit(address(proxy));
erc20CollateralVaultDeposit = HypERC20CollateralVaultDeposit(
address(localToken)
);
Expand Down
Loading
Loading