From ffa22482526b8617de8d5d79cd8a1e7600a135fe Mon Sep 17 00:00:00 2001 From: Maxime Date: Wed, 30 Oct 2024 16:57:31 +0000 Subject: [PATCH] fix: solhint errors --- src/HypLSP8.sol | 31 ++++++++---------- src/HypLSP8Collateral.sol | 27 +++++++-------- test/HypLSP8.t.sol | 55 +++++++------------------------ test/LSP8Mock.sol | 69 ++++++++++++++------------------------- 4 files changed, 61 insertions(+), 121 deletions(-) diff --git a/src/HypLSP8.sol b/src/HypLSP8.sol index de65dc9..de265ea 100644 --- a/src/HypLSP8.sol +++ b/src/HypLSP8.sol @@ -3,20 +3,19 @@ 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. @@ -24,24 +23,20 @@ contract HypLSP8 is LSP8IdentifiableDigitalAssetInitAbstract, TokenRouter { * @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 @@ -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 @@ -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, ""); } } diff --git a/src/HypLSP8Collateral.sol b/src/HypLSP8Collateral.sol index c8b489e..bd155ef 100644 --- a/src/HypLSP8Collateral.sol +++ b/src/HypLSP8Collateral.sol @@ -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. @@ -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); } @@ -44,9 +40,7 @@ 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); } @@ -54,9 +48,7 @@ contract HypLSP8Collateral is TokenRouter { * @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 } @@ -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, ""); } } diff --git a/test/HypLSP8.t.sol b/test/HypLSP8.t.sol index 2cde431..f66f4a0 100644 --- a/test/HypLSP8.t.sol +++ b/test/HypLSP8.t.sol @@ -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; @@ -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); @@ -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); } } @@ -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); } } diff --git a/test/LSP8Mock.sol b/test/LSP8Mock.sol index 90be273..9a5815a 100644 --- a/test/LSP8Mock.sol +++ b/test/LSP8Mock.sol @@ -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); } @@ -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( @@ -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]); } }