-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e2d323
commit 4ee4240
Showing
4 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
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,79 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity >=0.8.19; | ||
|
||
import { TokenRouter } from "@hyperlane-xyz/core/contracts/token/libs/TokenRouter.sol"; | ||
|
||
import { ILSP8IdentifiableDigitalAsset } from "@lukso/lsp8-contracts/contracts/ILSP8IdentifiableDigitalAsset.sol"; | ||
|
||
import {LSP8IdentifiableDigitalAssetInitAbstract} from "@lukso/lsp8-contracts/contracts/LSP8IdentifiableDigitalAssetInitAbstract.sol"; | ||
|
||
import { _LSP4_TOKEN_TYPE_TOKEN } from "@lukso/lsp4-contracts/contracts/LSP4Constants.sol"; | ||
|
||
import { _LSP8_TOKENID_FORMAT_NUMBER } from "@lukso/lsp8-contracts/contracts/LSP8Constants.sol"; | ||
|
||
|
||
|
||
/** | ||
* @title Hyperlane LSP8 Token Router that extends LSP8 with remote transfer functionality. | ||
* @author Abacus Works | ||
*/ | ||
contract HypLSP8 is LSP8IdentifiableDigitalAssetInitAbstract, TokenRouter { | ||
constructor(address _mailbox) TokenRouter(_mailbox) {} | ||
|
||
/** | ||
* @notice Initializes the Hyperlane router, LSP8 metadata, and mints initial supply to deployer. | ||
* @param _mintAmount The amount of NFTs to mint to `msg.sender`. | ||
* @param _name The name of the token. | ||
* @param _symbol The symbol of the token. | ||
*/ | ||
function initialize( | ||
uint256 _mintAmount, | ||
string memory _name, | ||
string memory _symbol | ||
) external initializer { | ||
address owner = msg.sender; | ||
_transferOwnership(owner); | ||
|
||
LSP8IdentifiableDigitalAssetInitAbstract._initialize(_name, _symbol, owner, _LSP4_TOKEN_TYPE_TOKEN, _LSP8_TOKENID_FORMAT_NUMBER); | ||
|
||
for (uint256 i = 0; i < _mintAmount; i++) { | ||
_mint(owner, bytes32(i), true, ""); | ||
} | ||
} | ||
|
||
function balanceOf( | ||
address _account | ||
) | ||
public | ||
view | ||
virtual | ||
override(TokenRouter, LSP8IdentifiableDigitalAssetInitAbstract, ILSP8IdentifiableDigitalAsset) | ||
returns (uint256) | ||
{ | ||
return LSP8IdentifiableDigitalAssetInitAbstract.balanceOf(_account); | ||
} | ||
|
||
/** | ||
* @dev Asserts `msg.sender` is owner and burns `_tokenId`. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferFromSender( | ||
uint256 _tokenId | ||
) internal virtual override returns (bytes memory) { | ||
require(ownerOf(_tokenId) == msg.sender, "!owner"); | ||
_burn(_tokenId, ""); | ||
return bytes(""); // no metadata | ||
} | ||
|
||
/** | ||
* @dev Mints `_tokenId` to `_recipient`. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferTo( | ||
address _recipient, | ||
uint256 _tokenId, | ||
bytes calldata // no metadata | ||
) internal virtual override { | ||
_mint(_recipient, _tokenId, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity >=0.8.19; | ||
|
||
import { TokenRouter } from "@hyperlane-xyz/core/contracts/token/libs/TokenRouter.sol"; | ||
|
||
import {TokenMessage} from "@hyperlane-xyz/core/contracts/token/libs/TokenMessage.sol"; | ||
|
||
import {ILSP8IdentifiableDigitalAsset} from "@lukso/lsp8-contracts/contracts/ILSP8IdentifiableDigitalAsset.sol"; | ||
|
||
/** | ||
* @title Hyperlane LSP8 Token Collateral that wraps an existing LSP8 with remote transfer functionality. | ||
* @author Abacus Works | ||
*/ | ||
contract HypLSP8Collateral is TokenRouter { | ||
ILSP8IdentifiableDigitalAsset public immutable wrappedToken; | ||
|
||
/** | ||
* @notice Constructor | ||
* @param lsp8 Address of the token to keep as collateral | ||
*/ | ||
constructor(address lsp8, address _mailbox) TokenRouter(_mailbox) { | ||
wrappedToken = ILSP8IdentifiableDigitalAsset(lsp8); | ||
} | ||
|
||
/** | ||
* @notice Initializes the Hyperlane router | ||
* @param _hook The post-dispatch hook contract. | ||
@param _interchainSecurityModule The interchain security module contract. | ||
@param _owner The this contract. | ||
*/ | ||
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 ILSP8IdentifiableDigitalAsset(wrappedToken).tokenOwnerOf(bytes32(_tokenId)); | ||
} | ||
|
||
/** | ||
* @dev Returns the balance of `_account` for `wrappedToken`. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function balanceOf( | ||
address _account | ||
) external view override returns (uint256) { | ||
return ILSP8IdentifiableDigitalAsset(wrappedToken).balanceOf(_account); | ||
} | ||
|
||
/** | ||
* @dev Transfers `_tokenId` of `wrappedToken` from `msg.sender` to this contract. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferFromSender( | ||
uint256 _tokenId | ||
) internal virtual override returns (bytes memory) { | ||
wrappedToken.transfer(msg.sender, address(this), bytes32(_tokenId), true, ""); | ||
return bytes(""); // no metadata | ||
} | ||
|
||
/** | ||
* @dev Transfers `_tokenId` of `wrappedToken` from this contract to `_recipient`. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferTo( | ||
address _recipient, | ||
uint256 _tokenId, | ||
bytes calldata // no metadata | ||
) internal override { | ||
wrappedToken.transfer(address(this), _recipient, bytes32(_tokenId), true, ""); | ||
} | ||
} |