Skip to content

Commit

Permalink
feat: HypLSP8 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
skimaharvey committed Oct 23, 2024
1 parent 6e2d323 commit 4ee4240
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
Binary file added lukso-lsp8-contracts-0.16.0-rc-0.tgz
Binary file not shown.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"@erc725/smart-contracts-v8": "erc725-smart-contracts-v8-rc0.tgz",
"@hyperlane-xyz/core": "^5.3.0",
"@lukso/lsp4-contracts": "lukso-lsp4-contracts-0.16.0-rc.0.tgz",
"@lukso/lsp7-contracts": "lukso-lsp7-contracts-0.16.0-rc.0.tgz"
"@lukso/lsp7-contracts": "lukso-lsp7-contracts-0.16.0-rc.0.tgz",
"@lukso/lsp8-contracts": "lukso-lsp8-contracts-0.16.0-rc-0.tgz"

},
"devDependencies": {
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
Expand Down
79 changes: 79 additions & 0 deletions src/HypLSP8.sol
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, "");
}
}
75 changes: 75 additions & 0 deletions src/HypLSP8Collateral.sol
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, "");
}
}

0 comments on commit 4ee4240

Please # to comment.