Skip to content

Commit

Permalink
fix: solhint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
skimaharvey committed Oct 30, 2024
1 parent 92f3d4a commit ffa2248
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 121 deletions.
31 changes: 14 additions & 17 deletions src/HypLSP8.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,40 @@ pragma solidity >=0.8.19;

import { TokenRouter } from "@hyperlane-xyz/core/contracts/token/libs/TokenRouter.sol";

import {LSP8IdentifiableDigitalAssetInitAbstract} from "@lukso/lsp8-contracts/contracts/LSP8IdentifiableDigitalAssetInitAbstract.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) {}
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 {
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);
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
)
function balanceOf(address _account)
public
view
virtual
Expand All @@ -55,9 +50,7 @@ contract HypLSP8 is LSP8IdentifiableDigitalAssetInitAbstract, TokenRouter {
* @dev Asserts `msg.sender` is owner and burns `_tokenId`.
* @inheritdoc TokenRouter
*/
function _transferFromSender(
uint256 _tokenId
) internal virtual override returns (bytes memory) {
function _transferFromSender(uint256 _tokenId) internal virtual override returns (bytes memory) {
require(tokenOwnerOf(bytes32(_tokenId)) == msg.sender, "!owner");
_burn(bytes32(_tokenId), "");
return bytes(""); // no metadata
Expand All @@ -71,7 +64,11 @@ contract HypLSP8 is LSP8IdentifiableDigitalAssetInitAbstract, TokenRouter {
address _recipient,
uint256 _tokenId,
bytes calldata // no metadata
) internal virtual override {
)
internal
virtual
override
{
_mint(_recipient, bytes32(_tokenId), true, "");
}
}
27 changes: 11 additions & 16 deletions src/HypLSP8Collateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ 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 { TokenMessage } from "@hyperlane-xyz/core/contracts/token/libs/TokenMessage.sol";

import {ILSP8IdentifiableDigitalAsset} from "@lukso/lsp8-contracts/contracts/ILSP8IdentifiableDigitalAsset.sol";
import { ILSP8IdentifiableDigitalAsset } from "@lukso/lsp8-contracts/contracts/ILSP8IdentifiableDigitalAsset.sol";

/**
* @title Hyperlane LSP8 Token Collateral that wraps an existing LSP8 with remote transfer functionality.
Expand All @@ -25,14 +25,10 @@ contract HypLSP8Collateral is TokenRouter {
/**
* @notice Initializes the Hyperlane router
* @param _hook The post-dispatch hook contract.
@param _interchainSecurityModule The interchain security module contract.
@param _owner The this contract.
* @param _interchainSecurityModule The interchain security module contract.
* @param _owner The this contract.
*/
function initialize(
address _hook,
address _interchainSecurityModule,
address _owner
) public virtual initializer {
function initialize(address _hook, address _interchainSecurityModule, address _owner) public virtual initializer {
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

Expand All @@ -44,19 +40,15 @@ contract HypLSP8Collateral is TokenRouter {
* @dev Returns the balance of `_account` for `wrappedToken`.
* @inheritdoc TokenRouter
*/
function balanceOf(
address _account
) external view override returns (uint256) {
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) {
function _transferFromSender(uint256 _tokenId) internal virtual override returns (bytes memory) {
wrappedToken.transfer(msg.sender, address(this), bytes32(_tokenId), true, "");
return bytes(""); // no metadata
}
Expand All @@ -69,7 +61,10 @@ contract HypLSP8Collateral is TokenRouter {
address _recipient,
uint256 _tokenId,
bytes calldata // no metadata
) internal override {
)
internal
override
{
wrappedToken.transfer(address(this), _recipient, bytes32(_tokenId), true, "");
}
}
55 changes: 12 additions & 43 deletions test/HypLSP8.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { HypLSP8 } from "../src/HypLSP8.sol";
import { HypLSP8Collateral } from "../src/HypLSP8Collateral.sol";
import { LSP8Mock } from "./LSP8Mock.sol";


abstract contract HypTokenTest is Test {
using TypeCasts for address;

Expand Down Expand Up @@ -74,19 +73,13 @@ abstract contract HypTokenTest is Test {
function _processTransfers(address _recipient, bytes32 _tokenId) internal {
vm.prank(address(remoteMailbox));
remoteToken.handle(
ORIGIN,
address(localToken).addressToBytes32(),
abi.encodePacked(_recipient.addressToBytes32(), _tokenId)
ORIGIN, address(localToken).addressToBytes32(), abi.encodePacked(_recipient.addressToBytes32(), _tokenId)
);
}

function _performRemoteTransfer(uint256 _msgValue, bytes32 _tokenId) internal {
vm.prank(ALICE);
localToken.transferRemote{ value: _msgValue }(
DESTINATION,
BOB.addressToBytes32(),
uint256(_tokenId)
);
localToken.transferRemote{ value: _msgValue }(DESTINATION, BOB.addressToBytes32(), uint256(_tokenId));

_processTransfers(BOB, _tokenId);
assertEq(remoteToken.balanceOf(BOB), 1);
Expand Down Expand Up @@ -146,29 +139,20 @@ contract HypLSP8Test is HypTokenTest {
vm.prank(OWNER);
remoteToken.enrollRemoteRouter(DESTINATION, address(remoteToken).addressToBytes32());

_performRemoteTransfer(25000, TOKEN_ID);
_performRemoteTransfer(25_000, TOKEN_ID);
assertEq(lsp8Token.balanceOf(ALICE), 0);
}

function testRemoteTransfer_revert_unauthorizedOperator() public {
vm.prank(OWNER);
vm.expectRevert("!owner");
localToken.transferRemote{ value: 25000 }(
DESTINATION,
BOB.addressToBytes32(),
uint256(TOKEN_ID)
);
localToken.transferRemote{ value: 25_000 }(DESTINATION, BOB.addressToBytes32(), uint256(TOKEN_ID));
}

function testRemoteTransfer_revert_invalidTokenId() public {
bytes32 invalidTokenId = bytes32(uint256(999));
vm.expectRevert(
abi.encodeWithSignature(
"LSP8NonExistentTokenId(bytes32)",
invalidTokenId
)
);
_performRemoteTransfer(25000, invalidTokenId);
vm.expectRevert(abi.encodeWithSignature("LSP8NonExistentTokenId(bytes32)", invalidTokenId));
_performRemoteTransfer(25_000, invalidTokenId);
}
}

Expand Down Expand Up @@ -213,37 +197,22 @@ contract HypLSP8CollateralTest is HypTokenTest {
function testRemoteTransfer() public {
vm.prank(ALICE);
localPrimaryToken.authorizeOperator(address(lsp8Collateral), TOKEN_ID, "");
_performRemoteTransfer(25000, TOKEN_ID);
_performRemoteTransfer(25_000, TOKEN_ID);

assertEq(localPrimaryToken.tokenOwnerOf(TOKEN_ID), address(lsp8Collateral));
}

function testRemoteTransfer_revert_unauthorized() public {


vm.expectRevert(
abi.encodeWithSignature(
"LSP8NotTokenOperator(bytes32,address)",
TOKEN_ID,
address(lsp8Collateral)
)
);
vm.prank(BOB);
localToken.transferRemote{ value: 25000 }(
DESTINATION,
BOB.addressToBytes32(),
uint256(TOKEN_ID)
abi.encodeWithSignature("LSP8NotTokenOperator(bytes32,address)", TOKEN_ID, address(lsp8Collateral))
);
vm.prank(BOB);
localToken.transferRemote{ value: 25_000 }(DESTINATION, BOB.addressToBytes32(), uint256(TOKEN_ID));
}

function testRemoteTransfer_revert_invalidTokenId() public {
bytes32 invalidTokenId = bytes32(uint256(999));
vm.expectRevert(
abi.encodeWithSignature(
"LSP8NonExistentTokenId(bytes32)",
invalidTokenId
)
);
_performRemoteTransfer(25000, invalidTokenId);
vm.expectRevert(abi.encodeWithSignature("LSP8NonExistentTokenId(bytes32)", invalidTokenId));
_performRemoteTransfer(25_000, invalidTokenId);
}
}
69 changes: 24 additions & 45 deletions test/LSP8Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ contract LSP8Mock is LSP8IdentifiableDigitalAsset {
string memory name_,
string memory symbol_,
address owner_
) LSP8IdentifiableDigitalAsset(name_, symbol_, owner_, 0, 0) {}
)
LSP8IdentifiableDigitalAsset(name_, symbol_, owner_, 0, 0)
{ }

function mint(
address to,
bytes32 tokenId,
bool force,
bytes memory data
) public {
function mint(address to, bytes32 tokenId, bool force, bytes memory data) public {
_mint(to, tokenId, force, data);
}

Expand All @@ -24,59 +21,40 @@ contract LSP8Mock is LSP8IdentifiableDigitalAsset {
bytes32[] memory tokenIds,
bool[] memory force,
bytes[] memory data
) public {
)
public
{
require(
to.length == tokenIds.length &&
tokenIds.length == force.length &&
force.length == data.length,
to.length == tokenIds.length && tokenIds.length == force.length && force.length == data.length,
"LSP8Mock: array length mismatch"
);

for(uint256 i = 0; i < to.length; i++) {
for (uint256 i = 0; i < to.length; i++) {
_mint(to[i], tokenIds[i], force[i], data[i]);
}
}

function mintIdRange(
address to,
uint256 startId,
uint256 amount,
bool force,
bytes memory data
) public {
for(uint256 i = 0; i < amount; i++) {
function mintIdRange(address to, uint256 startId, uint256 amount, bool force, bytes memory data) public {
for (uint256 i = 0; i < amount; i++) {
bytes32 tokenId = bytes32(startId + i);
_mint(to, tokenId, force, data);
}
}

function burn(
bytes32 tokenId,
bytes memory data
) public {
function burn(bytes32 tokenId, bytes memory data) public {
_burn(tokenId, data);
}

function burnBatch(
bytes32[] memory tokenIds,
bytes[] memory data
) public {
require(
tokenIds.length == data.length,
"LSP8Mock: array length mismatch"
);
function burnBatch(bytes32[] memory tokenIds, bytes[] memory data) public {
require(tokenIds.length == data.length, "LSP8Mock: array length mismatch");

for(uint256 i = 0; i < tokenIds.length; i++) {
for (uint256 i = 0; i < tokenIds.length; i++) {
_burn(tokenIds[i], data[i]);
}
}

function setData(
bytes32 tokenId,
bytes32 dataKey,
bytes memory dataValue
) public {
_setData( dataKey, dataValue);
function setData(bytes32 tokenId, bytes32 dataKey, bytes memory dataValue) public {
_setData(dataKey, dataValue);
}

function transferBatch(
Expand All @@ -85,16 +63,17 @@ contract LSP8Mock is LSP8IdentifiableDigitalAsset {
bytes32[] memory tokenIds,
bool[] memory force,
bytes[] memory data
) public override {
)
public
override
{
require(
from.length == to.length &&
to.length == tokenIds.length &&
tokenIds.length == force.length &&
force.length == data.length,
from.length == to.length && to.length == tokenIds.length && tokenIds.length == force.length
&& force.length == data.length,
"LSP8Mock: array length mismatch"
);

for(uint256 i = 0; i < from.length; i++) {
for (uint256 i = 0; i < from.length; i++) {
transfer(from[i], to[i], tokenIds[i], force[i], data[i]);
}
}
Expand Down

0 comments on commit ffa2248

Please sign in to comment.