-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Connext xERC20 and Circle FiatToken collateral (#3618)
### Description - Implement XERC20 Collateral contract - Implement FiatToken Collateral contract ### Drive-by - Move vault collateral extension into token extensions folder ### Related issues - Fixes #3486 ### Backward compatibility - Yes ### Testing - Unit tests
- Loading branch information
Showing
16 changed files
with
310 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@hyperlane-xyz/cli': minor | ||
'@hyperlane-xyz/sdk': minor | ||
'@hyperlane-xyz/core': minor | ||
--- | ||
|
||
Implement XERC20 and FiatToken collateral warp routes |
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
2 changes: 1 addition & 1 deletion
2
.../token/HypERC20CollateralVaultDeposit.sol → ...nsions/HypERC20CollateralVaultDeposit.sol
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
32 changes: 32 additions & 0 deletions
32
solidity/contracts/token/extensions/HypFiatTokenCollateral.sol
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
pragma solidity >=0.8.0; | ||
|
||
import {IFiatToken} from "../interfaces/IFiatToken.sol"; | ||
import {HypERC20Collateral} from "../HypERC20Collateral.sol"; | ||
|
||
// see https://github.com/circlefin/stablecoin-evm/blob/master/doc/tokendesign.md#issuing-and-destroying-tokens | ||
contract HypFiatTokenCollateral is HypERC20Collateral { | ||
constructor( | ||
address _fiatToken, | ||
address _mailbox | ||
) HypERC20Collateral(_fiatToken, _mailbox) {} | ||
|
||
function _transferFromSender( | ||
uint256 _amount | ||
) internal override returns (bytes memory metadata) { | ||
// transfer amount to address(this) | ||
metadata = super._transferFromSender(_amount); | ||
// burn amount of address(this) balance | ||
IFiatToken(address(wrappedToken)).burn(_amount); | ||
} | ||
|
||
function _transferTo( | ||
address _recipient, | ||
uint256 _amount, | ||
bytes calldata /*metadata*/ | ||
) internal override { | ||
require( | ||
IFiatToken(address(wrappedToken)).mint(_recipient, _amount), | ||
"FiatToken mint failed" | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
solidity/contracts/token/extensions/HypXERC20Collateral.sol
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pragma solidity >=0.8.0; | ||
|
||
import {IXERC20} from "../interfaces/IXERC20.sol"; | ||
import {HypERC20Collateral} from "../HypERC20Collateral.sol"; | ||
|
||
contract HypXERC20Collateral is HypERC20Collateral { | ||
constructor( | ||
address _xerc20, | ||
address _mailbox | ||
) HypERC20Collateral(_xerc20, _mailbox) {} | ||
|
||
function _transferFromSender( | ||
uint256 _amountOrId | ||
) internal override returns (bytes memory metadata) { | ||
IXERC20(address(wrappedToken)).burn(msg.sender, _amountOrId); | ||
return ""; | ||
} | ||
|
||
function _transferTo( | ||
address _recipient, | ||
uint256 _amountOrId, | ||
bytes calldata /*metadata*/ | ||
) internal override { | ||
IXERC20(address(wrappedToken)).mint(_recipient, _amountOrId); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.0; | ||
|
||
// adapted from https://github.com/circlefin/stablecoin-evm | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
interface IFiatToken is IERC20 { | ||
/** | ||
* @notice Allows a minter to burn some of its own tokens. | ||
* @dev The caller must be a minter, must not be blacklisted, and the amount to burn | ||
* should be less than or equal to the account's balance. | ||
* @param _amount the amount of tokens to be burned. | ||
*/ | ||
function burn(uint256 _amount) external; | ||
|
||
/** | ||
* @notice Mints fiat tokens to an address. | ||
* @param _to The address that will receive the minted tokens. | ||
* @param _amount The amount of tokens to mint. Must be less than or equal | ||
* to the minterAllowance of the caller. | ||
* @return True if the operation was successful. | ||
*/ | ||
function mint(address _to, uint256 _amount) external returns (bool); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.0; | ||
|
||
// adapted from https://github.com/defi-wonderland/xERC20 | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
interface IXERC20 is IERC20 { | ||
/** | ||
* @notice Mints tokens for a user | ||
* @dev Can only be called by a minter | ||
* @param _user The address of the user who needs tokens minted | ||
* @param _amount The amount of tokens being minted | ||
*/ | ||
function mint(address _user, uint256 _amount) external; | ||
|
||
/** | ||
* @notice Burns tokens for a user | ||
* @dev Can only be called by a minter | ||
* @param _user The address of the user who needs tokens burned | ||
* @param _amount The amount of tokens being burned | ||
*/ | ||
function burn(address _user, uint256 _amount) external; | ||
} |
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
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.