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

Yield-earning Warp Routes with ERC4626 #3076

Merged
merged 36 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b88739e
Add 4626 mocks
ltyu Dec 18, 2023
2a1c329
Add HypERC20CollateralVaultDeposit and test
ltyu Dec 18, 2023
da5da9b
Add virtual to allow inheritance
ltyu Dec 18, 2023
c901ac1
Add _transferTo logic
ltyu Dec 18, 2023
fbda4e7
Add sweep and tests
ltyu Dec 18, 2023
63bc6f9
Add mint
ltyu Dec 18, 2023
0dd7526
Add virtual to override
ltyu Dec 18, 2023
c484626
Update tests to use fuzzer
ltyu Dec 18, 2023
fcc63a8
Add more sweep test
ltyu Dec 18, 2023
8926218
Add natspec. Move into internal function
ltyu Dec 18, 2023
eb7175a
Remove console
ltyu Dec 18, 2023
af45235
Add event
ltyu Dec 18, 2023
28e3dff
Add fuzzing parameters
ltyu Dec 18, 2023
e2025e9
Merge branch 'main' into yield-warp-routes
ltyu Dec 18, 2023
b4dcc0f
forge install: solmate
ltyu Dec 18, 2023
804e855
Merge branch 'main' into yield-warp-routes
ltyu Dec 19, 2023
ef3c6ce
Update comments
ltyu Dec 19, 2023
f95c8a9
Merge branch 'main' into yield-warp-routes
ltyu Dec 19, 2023
17095e3
Merge branch 'yield-warp-routes' of https://github.com/ltyu/hyperlane…
ltyu Dec 19, 2023
0f505b8
Revert gitmodule changes
ltyu Dec 19, 2023
2d5ae90
Revert lib changes
ltyu Dec 19, 2023
9f8b263
Update to follow CEI
ltyu Jan 2, 2024
0686f78
Update solidity/contracts/token/HypERC20CollateralVaultDeposit.sol
ltyu Jan 2, 2024
50c517b
Update according to comments: withdraw directly to recipient, remove …
ltyu Jan 2, 2024
62f56e7
Update tests
ltyu Jan 2, 2024
4bc3e44
Update according to comments: move max approve to constructor
ltyu Jan 2, 2024
fb40a64
Add msg.value check into AbstractMessageIdAuthHook
ltyu Jan 10, 2024
65dceff
Merge branch 'main' into yield-warp-routes
ltyu Jan 14, 2024
d34a608
Merge branch 'main' into yield-warp-routes
ltyu Jan 17, 2024
30011be
Use bound. Move duplicate calls to helper functions
ltyu Jan 18, 2024
eed40f8
Merge branch 'main' into yield-warp-routes
ltyu Jan 18, 2024
9102f9e
Update variable names
ltyu Jan 18, 2024
ee594ae
Merge branch 'yield-warp-routes' of https://github.com/ltyu/hyperlane…
ltyu Jan 18, 2024
8b9a772
Merge branch 'main' into yield-warp-routes
ltyu Mar 13, 2024
e03eaaa
Fix test
ltyu Mar 13, 2024
e9ed058
Merge branch 'main' into yield-warp-routes
ltyu Mar 13, 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
4 changes: 4 additions & 0 deletions solidity/contracts/hooks/libs/AbstractMessageIdAuthHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ abstract contract AbstractMessageIdAuthHook is
message.destination() == destinationDomain,
"AbstractMessageIdAuthHook: invalid destination domain"
);
require(
metadata.msgValue(0) < 2 ** 255,
ltyu marked this conversation as resolved.
Show resolved Hide resolved
"AbstractMessageIdAuthHook: msgValue must be less than 2 ** 255"
);
bytes memory payload = abi.encodeCall(
AbstractMessageIdAuthorizedIsm.verifyMessageId,
id
Expand Down
8 changes: 8 additions & 0 deletions solidity/contracts/test/ERC20Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ contract ERC20Test is ERC20 {
function decimals() public view override returns (uint8) {
return _decimals;
}

function mint(uint256 amount) public {
_mint(msg.sender, amount);
}

function mintTo(address account, uint256 amount) public {
_mint(account, amount);
}
}
13 changes: 13 additions & 0 deletions solidity/contracts/test/ERC4626/ERC4626Test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC20.sol";

contract ERC4626Test is ERC4626 {
constructor(
address _asset,
string memory _name,
string memory _symbol
) ERC4626(IERC20(_asset)) ERC20(_name, _symbol) {}
}
2 changes: 1 addition & 1 deletion solidity/contracts/token/HypERC20Collateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract HypERC20Collateral is TokenRouter {
*/
function _transferFromSender(
uint256 _amount
) internal override returns (bytes memory) {
) internal virtual override returns (bytes memory) {
wrappedToken.safeTransferFrom(msg.sender, address(this), _amount);
return bytes(""); // no metadata
}
Expand Down
82 changes: 82 additions & 0 deletions solidity/contracts/token/HypERC20CollateralVaultDeposit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import {HypERC20Collateral} from "./HypERC20Collateral.sol";

/**
* @title Hyperlane ERC20 Token Collateral with deposits collateral to a vault
* @author ltyu
*/
contract HypERC20CollateralVaultDeposit is HypERC20Collateral {
// Address of the ERC4626 compatible vault
ERC4626 public immutable vault;

// Internal balance of total asset deposited
uint256 public assetDeposited;
ltyu marked this conversation as resolved.
Show resolved Hide resolved

event ExcessSharesSwept(uint256 amount, uint256 assetsRedeemed);

constructor(
ERC4626 _vault,
address _mailbox
) HypERC20Collateral(_vault.asset(), _mailbox) {
vault = _vault;
wrappedToken.approve(address(vault), type(uint256).max);
}
Comment on lines +19 to +25

Check warning

Code scanning / Slither

Unused return Medium


/**
* @dev Transfers `_amount` of `wrappedToken` from `msg.sender` to this contract, and deposit into vault
* @inheritdoc HypERC20Collateral
*/
function _transferFromSender(
uint256 _amount
) internal override returns (bytes memory metadata) {
metadata = super._transferFromSender(_amount);
_depositIntoVault(_amount);
}

/**
* @dev Deposits into the vault and increment assetDeposited
* @param _amount amount to deposit into vault
*/
function _depositIntoVault(uint256 _amount) internal {
assetDeposited += _amount;
ltyu marked this conversation as resolved.
Show resolved Hide resolved
vault.deposit(_amount, address(this));
}
Comment on lines +42 to +45

Check warning

Code scanning / Slither

Unused return Medium


/**
* @dev Transfers `_amount` of `wrappedToken` from this contract to `_recipient`, and withdraws from vault
* @inheritdoc HypERC20Collateral
*/
function _transferTo(
address _recipient,
uint256 _amount,
bytes calldata
) internal virtual override {
_withdrawFromVault(_amount, _recipient);
}

/**
* @dev Withdraws from the vault and decrement assetDeposited
* @param _amount amount to withdraw from vault
* @param _recipient address to deposit withdrawn underlying to
*/
function _withdrawFromVault(uint256 _amount, address _recipient) internal {
assetDeposited -= _amount;
vault.withdraw(_amount, _recipient, address(this));
}
Comment on lines +64 to +67

Check warning

Code scanning / Slither

Unused return Medium


/**
* @notice Allows the owner to redeem excess shares
*/
function sweep() external onlyOwner {
uint256 excessShares = vault.maxRedeem(address(this)) -
vault.convertToShares(assetDeposited);
uint256 assetsRedeemed = vault.redeem(
excessShares,
owner(),
address(this)
);
emit ExcessSharesSwept(excessShares, assetsRedeemed);
}
Comment on lines +72 to +81

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low

}
4 changes: 3 additions & 1 deletion solidity/test/isms/OPStackIsm.t.sol
yorhodes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ contract OPStackIsmTest is Test {
.overrideMsgValue(uint256(2 ** 255 + 1));

l1Mailbox.updateLatestDispatchedId(messageId);
vm.expectRevert("OPStackHook: msgValue must be less than 2 ** 255");
vm.expectRevert(
"AbstractMessageIdAuthHook: msgValue must be less than 2 ** 255"
);
opHook.postDispatch(excessValueMetadata, encodedMessage);
}

Expand Down
16 changes: 15 additions & 1 deletion solidity/test/token/HypERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ abstract contract HypTokenTest is Test {
);
}

function _handleLocalTransfer(uint256 _transferAmount) internal {
vm.prank(address(localMailbox));
localToken.handle(
DESTINATION,
address(remoteToken).addressToBytes32(),
abi.encodePacked(ALICE.addressToBytes32(), _transferAmount)
);
}

function _mintAndApprove(uint256 _amount, address _account) internal {
primaryToken.mint(_amount);
primaryToken.approve(_account, _amount);
}

function _setCustomGasConfig() internal {
localToken.setHook(address(igp));

Expand Down Expand Up @@ -153,7 +167,7 @@ abstract contract HypTokenTest is Test {
_performRemoteTransferAndGas(_msgValue, _amount, _gasOverhead);
}

function testBenchmark_overheadGasUsage() public {
function testBenchmark_overheadGasUsage() public virtual {
vm.prank(address(localMailbox));

uint256 gasBefore = gasleft();
Expand Down
Loading
Loading