-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create
HypLSP7Collateral
+ adjusted version of HypERC20
whe…
…n bridging an LSP7 from LUKSO to Ethereum
- Loading branch information
Showing
4 changed files
with
126 additions
and
26 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,31 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.19; | ||
|
||
// modules | ||
import { HypERC20 } from "@hyperlane-xyz/core/contracts/token/HypERC20.sol"; | ||
import { TokenRouter } from "@hyperlane-xyz/core/contracts/token/libs/TokenRouter.sol"; | ||
|
||
// libraries | ||
import { TypeCasts } from "@hyperlane-xyz/core/contracts/libs/TypeCasts.sol"; | ||
import { TokenMessageForLSP7 } from "./TokenMessageForLSP7.sol"; | ||
|
||
contract HypERC20ForLSP7 is HypERC20 { | ||
constructor(uint8 __decimals, address _mailbox) HypERC20(__decimals, _mailbox) { } | ||
|
||
/** | ||
* @dev Mints tokens to recipient when router receives transfer message. | ||
* @dev Emits `ReceivedTransferRemote` event on the destination chain. | ||
* @param _origin The identifier of the origin chain. | ||
* @param _message The encoded remote transfer message containing the recipient address and amount. | ||
* | ||
* @dev This function is overriden to extract the right params and calldata slices | ||
* from a transfer message coming from LSP7, via the modified library `TokenMessageForLSP7`. | ||
*/ | ||
function _handle(uint32 _origin, bytes32, bytes calldata _message) internal virtual override(TokenRouter) { | ||
bytes32 recipient = TokenMessageForLSP7.recipient(_message); | ||
uint256 amount = TokenMessageForLSP7.amount(_message); | ||
bytes calldata metadata = TokenMessageForLSP7.metadata(_message); | ||
_transferTo(TypeCasts.bytes32ToAddress(recipient), amount, metadata); | ||
emit ReceivedTransferRemote(_origin, recipient, amount); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.19; | ||
|
||
// Interfaces | ||
import { ILSP7DigitalAsset as ILSP7 } from "@lukso/lsp7-contracts/contracts/ILSP7DigitalAsset.sol"; | ||
|
||
// Modules | ||
import { TokenRouter } from "@hyperlane-xyz/core/contracts/token/libs/TokenRouter.sol"; | ||
|
||
contract HypLSP7Collateral is TokenRouter { | ||
ILSP7 public immutable wrappedToken; | ||
|
||
/** | ||
* @notice Constructor | ||
* @param lsp7_ Address of the token to keep as collateral | ||
*/ | ||
constructor(address lsp7_, address mailbox_) TokenRouter(mailbox_) { | ||
wrappedToken = ILSP7(lsp7_); | ||
} | ||
|
||
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) { | ||
return wrappedToken.balanceOf(_account); | ||
} | ||
|
||
/** | ||
* @dev Transfers `_amount` of `wrappedToken` from `msg.sender` to this contract. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferFromSender(uint256 _amount) internal virtual override returns (bytes memory) { | ||
wrappedToken.transfer(msg.sender, address(this), _amount, true, ""); | ||
return bytes(""); // no metadata | ||
} | ||
|
||
/** | ||
* @dev Transfers `_amount` of `wrappedToken` from this contract to `_recipient`. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferTo( | ||
address _recipient, | ||
uint256 _amount, | ||
bytes calldata // no metadata | ||
) | ||
internal | ||
virtual | ||
override | ||
{ | ||
wrappedToken.transfer(address(this), _recipient, _amount, true, ""); | ||
} | ||
} |
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