feat: support xerc20 and xerc20Lockbox in CLI (#3753)
### Description - Supports xERC20 and xERC20Lockbox in CLI and UI ### Drive-by changes - Rename XERC20Collateral to XERC20 ### Backward compatibility - Yes ### Testing - Manualpull/3854/head
parent
b6b26e2bb8
commit
babe816f86
@ -0,0 +1,7 @@ |
||||
--- |
||||
'@hyperlane-xyz/cli': minor |
||||
'@hyperlane-xyz/sdk': minor |
||||
'@hyperlane-xyz/core': minor |
||||
--- |
||||
|
||||
Support xERC20 and xERC20 Lockbox in SDK and CLI |
@ -1,2 +1,3 @@ |
||||
contracts/mock |
||||
contracts/test |
||||
contracts/interfaces/avs/vendored |
||||
|
@ -0,0 +1,54 @@ |
||||
// SPDX-License-Identifier: MIT OR Apache-2.0 |
||||
pragma solidity >=0.8.0; |
||||
|
||||
import {IXERC20Lockbox} from "../interfaces/IXERC20Lockbox.sol"; |
||||
import {IXERC20, IERC20} from "../interfaces/IXERC20.sol"; |
||||
import {HypERC20Collateral} from "../HypERC20Collateral.sol"; |
||||
|
||||
contract HypXERC20Lockbox is HypERC20Collateral { |
||||
uint256 constant MAX_INT = 2 ** 256 - 1; |
||||
|
||||
IXERC20Lockbox public immutable lockbox; |
||||
IXERC20 public immutable xERC20; |
||||
|
||||
constructor( |
||||
address _lockbox, |
||||
address _mailbox |
||||
) HypERC20Collateral(address(IXERC20Lockbox(_lockbox).ERC20()), _mailbox) { |
||||
lockbox = IXERC20Lockbox(_lockbox); |
||||
xERC20 = lockbox.XERC20(); |
||||
|
||||
// grant infinite approvals to lockbox |
||||
require( |
||||
IERC20(wrappedToken).approve(_lockbox, MAX_INT), |
||||
"erc20 lockbox approve failed" |
||||
); |
||||
require( |
||||
xERC20.approve(_lockbox, MAX_INT), |
||||
"xerc20 lockbox approve failed" |
||||
); |
||||
} |
||||
|
||||
function _transferFromSender( |
||||
uint256 _amount |
||||
) internal override returns (bytes memory) { |
||||
// transfer erc20 from sender |
||||
super._transferFromSender(_amount); |
||||
// convert erc20 to xERC20 |
||||
lockbox.deposit(_amount); |
||||
// burn xERC20 |
||||
xERC20.burn(address(this), _amount); |
||||
return bytes(""); |
||||
} |
||||
|
||||
function _transferTo( |
||||
address _recipient, |
||||
uint256 _amount, |
||||
bytes calldata /*metadata*/ |
||||
) internal override { |
||||
// mint xERC20 |
||||
xERC20.mint(address(this), _amount); |
||||
// convert xERC20 to erc20 |
||||
lockbox.withdrawTo(_recipient, _amount); |
||||
} |
||||
} |
@ -0,0 +1,61 @@ |
||||
// SPDX-License-Identifier: UNLICENSED |
||||
pragma solidity >=0.8.4 <0.9.0; |
||||
|
||||
// adapted from https://github.com/defi-wonderland/xERC20 |
||||
|
||||
import {IXERC20} from "./IXERC20.sol"; |
||||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
||||
|
||||
interface IXERC20Lockbox { |
||||
/** |
||||
* @notice The XERC20 token of this contract |
||||
*/ |
||||
function XERC20() external returns (IXERC20); |
||||
|
||||
/** |
||||
* @notice The ERC20 token of this contract |
||||
*/ |
||||
function ERC20() external returns (IERC20); |
||||
|
||||
/** |
||||
* @notice Deposit ERC20 tokens into the lockbox |
||||
* |
||||
* @param _amount The amount of tokens to deposit |
||||
*/ |
||||
|
||||
function deposit(uint256 _amount) external; |
||||
|
||||
/** |
||||
* @notice Deposit ERC20 tokens into the lockbox, and send the XERC20 to a user |
||||
* |
||||
* @param _user The user to send the XERC20 to |
||||
* @param _amount The amount of tokens to deposit |
||||
*/ |
||||
|
||||
function depositTo(address _user, uint256 _amount) external; |
||||
|
||||
/** |
||||
* @notice Deposit the native asset into the lockbox, and send the XERC20 to a user |
||||
* |
||||
* @param _user The user to send the XERC20 to |
||||
*/ |
||||
|
||||
function depositNativeTo(address _user) external payable; |
||||
|
||||
/** |
||||
* @notice Withdraw ERC20 tokens from the lockbox |
||||
* |
||||
* @param _amount The amount of tokens to withdraw |
||||
*/ |
||||
|
||||
function withdraw(uint256 _amount) external; |
||||
|
||||
/** |
||||
* @notice Withdraw ERC20 tokens from the lockbox |
||||
* |
||||
* @param _user The user to withdraw to |
||||
* @param _amount The amount of tokens to withdraw |
||||
*/ |
||||
|
||||
function withdrawTo(address _user, uint256 _amount) external; |
||||
} |
Loading…
Reference in new issue