From e469850a5f1fe7f2c90b203719e62fa7883e7689 Mon Sep 17 00:00:00 2001 From: Andres Adjimann Date: Wed, 27 Sep 2023 19:27:41 -0300 Subject: [PATCH 1/2] chore: linter and remove some test mocks --- packages/marketplace/.solhint.json | 4 +- .../contracts/exchange/Exchange.sol | 1 + .../contracts/exchange/ExchangeCore.sol | 124 +++++++------- .../contracts/exchange/ExchangeMeta.sol | 69 -------- .../contracts/exchange/OrderValidator.sol | 1 + .../contracts/exchange/WhiteList.sol | 1 + .../exchange/mocks/OrderValidatorTest.sol | 15 -- .../exchange/mocks/RaribleTestHelper.sol | 38 ----- .../exchange/mocks/TransferManagerTest.sol | 142 ---------------- .../contracts/lazy-mint/mocks/ERC1155Test.sol | 2 + .../contracts/lazy-mint/mocks/ERC721Test.sol | 1 + .../contracts/lib-order/LibOrder.sol | 3 + .../royalties-registry/RoyaltiesRegistry.sol | 1 + .../royalty-registry/RoyaltiesRegistryOld.sol | 158 ------------------ .../contracts/test/TestChainId.sol | 11 -- .../transfer-manager/TransferManager.sol | 1 + .../mocks/TransferExecutorTest.sol | 18 -- packages/marketplace/test/fixtures.ts | 2 +- 18 files changed, 81 insertions(+), 511 deletions(-) delete mode 100644 packages/marketplace/contracts/exchange/ExchangeMeta.sol delete mode 100644 packages/marketplace/contracts/exchange/mocks/OrderValidatorTest.sol delete mode 100644 packages/marketplace/contracts/exchange/mocks/RaribleTestHelper.sol delete mode 100644 packages/marketplace/contracts/exchange/mocks/TransferManagerTest.sol delete mode 100644 packages/marketplace/contracts/royalties-registry/mocks/royalty-registry/RoyaltiesRegistryOld.sol delete mode 100644 packages/marketplace/contracts/test/TestChainId.sol delete mode 100644 packages/marketplace/contracts/transfer-manager/mocks/TransferExecutorTest.sol diff --git a/packages/marketplace/.solhint.json b/packages/marketplace/.solhint.json index f89501544f..eefc61f7a4 100644 --- a/packages/marketplace/.solhint.json +++ b/packages/marketplace/.solhint.json @@ -10,6 +10,8 @@ ], "compiler-version": ["error", "^0.8.0"], "func-visibility": ["error", {"ignoreConstructors": true}], - "custom-errors": "off" + "custom-errors": "off", + "func-named-parameters": ["error", 7], + "reason-string": ["warn", {"maxLength": 64}] } } diff --git a/packages/marketplace/contracts/exchange/Exchange.sol b/packages/marketplace/contracts/exchange/Exchange.sol index e5d8124854..dbee094f80 100644 --- a/packages/marketplace/contracts/exchange/Exchange.sol +++ b/packages/marketplace/contracts/exchange/Exchange.sol @@ -39,6 +39,7 @@ contract Exchange is Initializable, AccessControlUpgradeable, ExchangeCore, Tran /// @param orderValidatorAddress address of the OrderValidator contract, that validates orders /// @param newNativeOrder bool to indicate of the contract accepts or doesn't native tokens, i.e. ETH or Matic /// @param newMetaNative same as =nativeOrder but for metaTransactions + // solhint-disable-next-line func-name-mixedcase function __Exchange_init( address admin, address newTrustedForwarder, diff --git a/packages/marketplace/contracts/exchange/ExchangeCore.sol b/packages/marketplace/contracts/exchange/ExchangeCore.sol index dc1a7b0555..a828b38d43 100644 --- a/packages/marketplace/contracts/exchange/ExchangeCore.sol +++ b/packages/marketplace/contracts/exchange/ExchangeCore.sol @@ -69,6 +69,7 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana /// @param newNativeOrder for orders with native token /// @param newMetaNative for meta orders with native token /// @dev initialize permissions for native token exchange + // solhint-disable-next-line func-name-mixedcase function __ExchangeCoreInitialize( bool newNativeOrder, bool newMetaNative, @@ -121,29 +122,35 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana /// @param direct purchase order function _directPurchase(address from, address buyer, LibDirectTransfer.Purchase calldata direct) internal { LibAsset.AssetType memory paymentAssetType = getPaymentAssetType(direct.paymentToken); - LibOrder.Order memory sellOrder = LibOrder.Order( - direct.sellOrderMaker, - LibAsset.Asset(LibAsset.AssetType(direct.nftAssetClass, direct.nftData), direct.sellOrderNftAmount), - address(0), - LibAsset.Asset(paymentAssetType, direct.sellOrderPaymentAmount), - direct.sellOrderSalt, - direct.sellOrderStart, - direct.sellOrderEnd, - direct.sellOrderDataType, - direct.sellOrderData - ); - - LibOrder.Order memory buyOrder = LibOrder.Order( - buyer, - LibAsset.Asset(paymentAssetType, direct.buyOrderPaymentAmount), - address(0), - LibAsset.Asset(LibAsset.AssetType(direct.nftAssetClass, direct.nftData), direct.buyOrderNftAmount), - 0, - 0, - 0, - getOtherOrderType(direct.sellOrderDataType), - direct.buyOrderData - ); + LibOrder.Order memory sellOrder = LibOrder.Order({ + maker: direct.sellOrderMaker, + makeAsset: LibAsset.Asset( + LibAsset.AssetType(direct.nftAssetClass, direct.nftData), + direct.sellOrderNftAmount + ), + taker: address(0), + takeAsset: LibAsset.Asset(paymentAssetType, direct.sellOrderPaymentAmount), + salt: direct.sellOrderSalt, + start: direct.sellOrderStart, + end: direct.sellOrderEnd, + dataType: direct.sellOrderDataType, + data: direct.sellOrderData + }); + + LibOrder.Order memory buyOrder = LibOrder.Order({ + maker: buyer, + makeAsset: LibAsset.Asset(paymentAssetType, direct.buyOrderPaymentAmount), + taker: address(0), + takeAsset: LibAsset.Asset( + LibAsset.AssetType(direct.nftAssetClass, direct.nftData), + direct.buyOrderNftAmount + ), + salt: 0, + start: 0, + end: 0, + dataType: getOtherOrderType(direct.sellOrderDataType), + data: direct.buyOrderData + }); orderValidator.verifyERC20Whitelist(direct.paymentToken); _validateFull(from, sellOrder, direct.sellOrderSignature); _matchAndTransfer(from, sellOrder, buyOrder); @@ -154,30 +161,32 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana /// @param direct struct with parameters for accept bid operation function _directAcceptBid(address from, LibDirectTransfer.AcceptBid calldata direct) internal { LibAsset.AssetType memory paymentAssetType = getPaymentAssetType(direct.paymentToken); - - LibOrder.Order memory buyOrder = LibOrder.Order( - direct.bidMaker, - LibAsset.Asset(paymentAssetType, direct.bidPaymentAmount), - address(0), - LibAsset.Asset(LibAsset.AssetType(direct.nftAssetClass, direct.nftData), direct.bidNftAmount), - direct.bidSalt, - direct.bidStart, - direct.bidEnd, - direct.bidDataType, - direct.bidData - ); - - LibOrder.Order memory sellOrder = LibOrder.Order( - address(0), - LibAsset.Asset(LibAsset.AssetType(direct.nftAssetClass, direct.nftData), direct.sellOrderNftAmount), - address(0), - LibAsset.Asset(paymentAssetType, direct.sellOrderPaymentAmount), - 0, - 0, - 0, - getOtherOrderType(direct.bidDataType), - direct.sellOrderData - ); + LibOrder.Order memory buyOrder = LibOrder.Order({ + maker: direct.bidMaker, + makeAsset: LibAsset.Asset(paymentAssetType, direct.bidPaymentAmount), + taker: address(0), + takeAsset: LibAsset.Asset(LibAsset.AssetType(direct.nftAssetClass, direct.nftData), direct.bidNftAmount), + salt: direct.bidSalt, + start: direct.bidStart, + end: direct.bidEnd, + dataType: direct.bidDataType, + data: direct.bidData + }); + + LibOrder.Order memory sellOrder = LibOrder.Order({ + maker: address(0), + makeAsset: LibAsset.Asset( + LibAsset.AssetType(direct.nftAssetClass, direct.nftData), + direct.sellOrderNftAmount + ), + taker: address(0), + takeAsset: LibAsset.Asset(paymentAssetType, direct.sellOrderPaymentAmount), + salt: 0, + start: 0, + end: 0, + dataType: getOtherOrderType(direct.bidDataType), + data: direct.sellOrderData + }); _validateFull(from, buyOrder, direct.bidSignature); _matchAndTransfer(from, sellOrder, buyOrder); @@ -441,17 +450,16 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana } // TODO: can we move this out so we don't need to pass from ? - emit Match( - from, - leftOrderKeyHash, - rightOrderKeyHash, - newFill, - fills[leftOrderKeyHash], - fills[rightOrderKeyHash], - orderLeft.makeAsset.value, - orderRight.makeAsset.value - ); - + emit Match({ + from: from, + leftHash: leftOrderKeyHash, + rightHash: rightOrderKeyHash, + newFill: newFill, + totalFillLeft: fills[leftOrderKeyHash], + totalFillRight: fills[rightOrderKeyHash], + valueLeft: orderLeft.makeAsset.value, + valueRight: orderRight.makeAsset.value + }); return newFill; } diff --git a/packages/marketplace/contracts/exchange/ExchangeMeta.sol b/packages/marketplace/contracts/exchange/ExchangeMeta.sol deleted file mode 100644 index 1399067968..0000000000 --- a/packages/marketplace/contracts/exchange/ExchangeMeta.sol +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; -import {ContextUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; -import {ERC2771HandlerUpgradeable} from "@sandbox-smart-contracts/dependency-metatx/contracts/ERC2771HandlerUpgradeable.sol"; -import {TransferManager, IRoyaltiesProvider} from "../transfer-manager/TransferManager.sol"; -import {IOrderValidator} from "../interfaces/IOrderValidator.sol"; -import {ExchangeCore} from "./ExchangeCore.sol"; - -/// @title Exchange contract with meta transactions -/// @notice Used to exchange assets, that is, tokens. -/// @dev Main functions are in ExchangeCore -/// @dev TransferManager is used to execute token transfers -contract ExchangeMeta is OwnableUpgradeable, ExchangeCore, TransferManager, ERC2771HandlerUpgradeable { - /// @notice ExchangeMeta contract initializer - /// @param newTrustedForwarder address for trusted forwarder that will execute meta transactions - /// @param newProtocolFeePrimary protocol fee applied for primary markets - /// @param newProtocolFeeSecondary protocol fee applied for secondary markets - /// @param newDefaultFeeReceiver market fee receiver - /// @param newRoyaltiesProvider registry for the different types of royalties - /// @param orderValidatorAddress address of the OrderValidator contract, that validates orders - /// @param newNativeOrder bool to indicate of the contract accepts or doesn't native tokens, i.e. ETH or Matic - /// @param newMetaNative same as =nativeOrder but for metaTransactions - function __Exchange_init( - address newTrustedForwarder, - uint256 newProtocolFeePrimary, - uint256 newProtocolFeeSecondary, - address newDefaultFeeReceiver, - IRoyaltiesProvider newRoyaltiesProvider, - IOrderValidator orderValidatorAddress, - bool newNativeOrder, - bool newMetaNative - ) external initializer { - __ERC2771Handler_init(newTrustedForwarder); - __Ownable_init(); - __TransferManager_init_unchained( - newProtocolFeePrimary, - newProtocolFeeSecondary, - newDefaultFeeReceiver, - newRoyaltiesProvider - ); - __ExchangeCoreInitialize(newNativeOrder, newMetaNative, orderValidatorAddress); - } - - function _msgSender() - internal - view - virtual - override(ContextUpgradeable, ERC2771HandlerUpgradeable) - returns (address) - { - return ERC2771HandlerUpgradeable._msgSender(); - } - - function _msgData() internal view override(ContextUpgradeable, ERC2771HandlerUpgradeable) returns (bytes calldata) { - return ERC2771HandlerUpgradeable._msgData(); - } - - /// @notice Change the address of the trusted forwarder for meta-transactions - /// @param newTrustedForwarder The new trustedForwarder - function setTrustedForwarder(address newTrustedForwarder) public virtual onlyOwner { - require(newTrustedForwarder != address(0), "address must be different from 0"); - - _setTrustedForwarder(newTrustedForwarder); - } -} diff --git a/packages/marketplace/contracts/exchange/OrderValidator.sol b/packages/marketplace/contracts/exchange/OrderValidator.sol index 7046c2db52..122c48e469 100644 --- a/packages/marketplace/contracts/exchange/OrderValidator.sol +++ b/packages/marketplace/contracts/exchange/OrderValidator.sol @@ -23,6 +23,7 @@ contract OrderValidator is IOrderValidator, Initializable, EIP712Upgradeable, Wh /// @param newPartners boolena to indicate that partner tokens are accepted by the exchange contract /// @param newOpen boolean to indicate that all assets are accepted by the exchange contract /// @param newErc20 boolean to activate the white list of ERC20 tokens + // solhint-disable-next-line func-name-mixedcase function __OrderValidator_init_unchained( bool newTsbOnly, bool newPartners, diff --git a/packages/marketplace/contracts/exchange/WhiteList.sol b/packages/marketplace/contracts/exchange/WhiteList.sol index 9a6631729d..436b5e620b 100644 --- a/packages/marketplace/contracts/exchange/WhiteList.sol +++ b/packages/marketplace/contracts/exchange/WhiteList.sol @@ -47,6 +47,7 @@ contract WhiteList is IWhiteList, OwnableUpgradeable, AccessControlUpgradeable { /// @param newPartners allows orders with partner token /// @param newOpen allows orders with any token /// @param newErc20List allows to pay orders with only whitelisted token + // solhint-disable-next-line func-name-mixedcase function __Whitelist_init(bool newTsbOnly, bool newPartners, bool newOpen, bool newErc20List) internal initializer { __Ownable_init(); __AccessControl_init_unchained(); diff --git a/packages/marketplace/contracts/exchange/mocks/OrderValidatorTest.sol b/packages/marketplace/contracts/exchange/mocks/OrderValidatorTest.sol deleted file mode 100644 index 5c124b5b5b..0000000000 --- a/packages/marketplace/contracts/exchange/mocks/OrderValidatorTest.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -import {OrderValidator, LibOrder} from "../OrderValidator.sol"; - -contract OrderValidatorTest is OrderValidator { - function __OrderValidatorTest_init(bool _tsbOnly, bool _partners, bool _open, bool _erc20) external initializer { - __OrderValidator_init_unchained(_tsbOnly, _partners, _open, _erc20); - } - - function validateOrderTest(LibOrder.Order calldata order, bytes calldata signature) external view { - return validate(order, signature, _msgSender()); - } -} diff --git a/packages/marketplace/contracts/exchange/mocks/RaribleTestHelper.sol b/packages/marketplace/contracts/exchange/mocks/RaribleTestHelper.sol deleted file mode 100644 index 8c57f93087..0000000000 --- a/packages/marketplace/contracts/exchange/mocks/RaribleTestHelper.sol +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -import {LibOrderData} from "../../lib-order/LibOrderData.sol"; -import {LibOrder} from "../../lib-order/LibOrder.sol"; -import {LibAsset} from "../../lib-asset/LibAsset.sol"; - -contract RaribleTestHelper { - function encode_SELL(LibOrderData.DataSell memory data) external pure returns (bytes memory) { - return abi.encode(data); - } - - function encode_BUY(LibOrderData.DataBuy memory data) external pure returns (bytes memory) { - return abi.encode(data); - } - - function encodeOriginFeeIntoUint(address account, uint96 value) external pure returns (uint256) { - return (uint256(value) << 160) + uint256(uint160(account)); - } - - function hashKey(LibOrder.Order calldata order) external pure returns (bytes32) { - return LibOrder.hashKey(order); - } - - function hashV2( - address maker, - LibAsset.Asset memory makeAsset, - LibAsset.Asset memory takeAsset, - uint256 salt, - bytes memory data - ) public pure returns (bytes32) { - return - keccak256( - abi.encode(maker, LibAsset.hash(makeAsset.assetType), LibAsset.hash(takeAsset.assetType), salt, data) - ); - } -} diff --git a/packages/marketplace/contracts/exchange/mocks/TransferManagerTest.sol b/packages/marketplace/contracts/exchange/mocks/TransferManagerTest.sol deleted file mode 100644 index a7353b69ee..0000000000 --- a/packages/marketplace/contracts/exchange/mocks/TransferManagerTest.sol +++ /dev/null @@ -1,142 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -import {TransferManager} from "../../transfer-manager/TransferManager.sol"; -import {TransferExecutor} from "../../transfer-manager/TransferExecutor.sol"; -import {LibDeal, LibPart, LibFeeSide} from "../../transfer-manager/lib/LibDeal.sol"; -import {IRoyaltiesProvider} from "../../interfaces/IRoyaltiesProvider.sol"; -import {LibOrderDataGeneric, LibOrderData, LibOrder} from "../libraries/LibOrderDataGeneric.sol"; - -contract TransferManagerTest is TransferManager, TransferExecutor { - struct ProtocolFeeSide { - LibFeeSide.FeeSide feeSide; - } - - function init____( - uint256 newProtocolFeePrimary, - uint256 newProtocolFeeSecondary, - address newCommunityWallet, - IRoyaltiesProvider newRoyaltiesProvider - ) external initializer { - __TransferManager_init_unchained( - newProtocolFeePrimary, - newProtocolFeeSecondary, - newCommunityWallet, - newRoyaltiesProvider - ); - } - - function getDealSide( - LibOrder.Order memory order, - LibOrderDataGeneric.GenericOrderData memory orderData - ) internal pure returns (LibDeal.DealSide memory dealSide) { - dealSide = LibDeal.DealSide(order.makeAsset, orderData.payouts, orderData.originFees, order.maker); - } - - function getDealData( - bytes4 makeMatchAssetClass, - bytes4 takeMatchAssetClass, - bytes4 leftDataType, - bytes4 rightDataType, - LibOrderDataGeneric.GenericOrderData memory leftOrderData, - LibOrderDataGeneric.GenericOrderData memory rightOrderData - ) internal pure returns (LibDeal.DealData memory dealData) { - dealData.feeSide = LibFeeSide.getFeeSide(makeMatchAssetClass, takeMatchAssetClass); - dealData.maxFeesBasePoint = getMaxFee( - leftDataType, - rightDataType, - leftOrderData, - rightOrderData, - dealData.feeSide - ); - } - - /** - @notice determines the max amount of fees for the match - @param dataTypeLeft data type of the left order - @param dataTypeRight data type of the right order - @param leftOrderData data of the left order - @param rightOrderData data of the right order - @param feeSide fee side of the match - @return max fee amount in base points - */ - function getMaxFee( - bytes4 dataTypeLeft, - bytes4 dataTypeRight, - LibOrderDataGeneric.GenericOrderData memory leftOrderData, - LibOrderDataGeneric.GenericOrderData memory rightOrderData, - LibFeeSide.FeeSide feeSide - ) internal pure returns (uint256) { - if ( - dataTypeLeft != LibOrderData.SELL && - dataTypeRight != LibOrderData.SELL && - dataTypeLeft != LibOrderData.BUY && - dataTypeRight != LibOrderData.BUY - ) { - return 0; - } - - uint256 matchFees = getSumFees(leftOrderData.originFees, rightOrderData.originFees); - uint256 maxFee; - if (feeSide == LibFeeSide.FeeSide.LEFT) { - maxFee = rightOrderData.maxFeesBasePoint; - require(dataTypeLeft == LibOrderData.BUY && dataTypeRight == LibOrderData.SELL, "wrong V3 type1"); - } else if (feeSide == LibFeeSide.FeeSide.RIGHT) { - maxFee = leftOrderData.maxFeesBasePoint; - require(dataTypeRight == LibOrderData.BUY && dataTypeLeft == LibOrderData.SELL, "wrong V3 type2"); - } else { - return 0; - } - require(maxFee > 0 && maxFee >= matchFees && maxFee <= 1000, "wrong maxFee"); - - return maxFee; - } - - /** - @notice calculates amount of fees for the match - @param originLeft origin fees of the left order - @param originRight origin fees of the right order - @return sum of all fees for the match (protcolFee + leftOrder.originFees + rightOrder.originFees) - */ - function getSumFees( - LibPart.Part[] memory originLeft, - LibPart.Part[] memory originRight - ) internal pure returns (uint256) { - uint256 result = 0; - - //adding left origin fees - for (uint256 i; i < originLeft.length; i++) { - result = result + originLeft[i].value; - } - - //adding right origin fees - for (uint256 i; i < originRight.length; i++) { - result = result + originRight[i].value; - } - - return result; - } - - function doTransfersExternal( - LibOrder.Order memory left, - LibOrder.Order memory right - ) external payable returns (uint256 totalLeftValue, uint256 totalRightValue) { - LibOrderDataGeneric.GenericOrderData memory leftData = LibOrderDataGeneric.parse(left); - LibOrderDataGeneric.GenericOrderData memory rightData = LibOrderDataGeneric.parse(right); - - return - doTransfers( - getDealSide(left, leftData), - getDealSide(right, rightData), - getDealData( - left.makeAsset.assetType.assetClass, - right.makeAsset.assetType.assetClass, - left.dataType, - right.dataType, - leftData, - rightData - ) - ); - } -} diff --git a/packages/marketplace/contracts/lazy-mint/mocks/ERC1155Test.sol b/packages/marketplace/contracts/lazy-mint/mocks/ERC1155Test.sol index a4105040e9..936c0f5a40 100644 --- a/packages/marketplace/contracts/lazy-mint/mocks/ERC1155Test.sol +++ b/packages/marketplace/contracts/lazy-mint/mocks/ERC1155Test.sol @@ -6,9 +6,11 @@ import {LibERC1155LazyMint} from "../erc-1155/LibERC1155LazyMint.sol"; import {ECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol"; import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol"; +// TODO: ERC1155 or ERC721 ? contract ERC1155Test is EIP712Upgradeable { using ECDSAUpgradeable for bytes32; + // solhint-disable-next-line func-name-mixedcase function __ERC1155Test_init() external initializer { __EIP712_init("Mint1155", "1"); } diff --git a/packages/marketplace/contracts/lazy-mint/mocks/ERC721Test.sol b/packages/marketplace/contracts/lazy-mint/mocks/ERC721Test.sol index 7ae709933c..a9073549ca 100644 --- a/packages/marketplace/contracts/lazy-mint/mocks/ERC721Test.sol +++ b/packages/marketplace/contracts/lazy-mint/mocks/ERC721Test.sol @@ -9,6 +9,7 @@ import {ECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/crypto contract ERC721Test is EIP712Upgradeable { using ECDSAUpgradeable for bytes32; + // solhint-disable-next-line func-name-mixedcase function __ERC721Test_init() external initializer { __EIP712_init("Mint721", "1"); } diff --git a/packages/marketplace/contracts/lib-order/LibOrder.sol b/packages/marketplace/contracts/lib-order/LibOrder.sol index 2449b2e4b2..9b25a98af6 100644 --- a/packages/marketplace/contracts/lib-order/LibOrder.sol +++ b/packages/marketplace/contracts/lib-order/LibOrder.sol @@ -82,6 +82,7 @@ library LibOrder { function hash(Order memory order) internal pure returns (bytes32) { return keccak256( + // solhint-disable-next-line func-named-parameters abi.encode( ORDER_TYPEHASH, order.maker, @@ -100,7 +101,9 @@ library LibOrder { /// @notice validates order time /// @param order whose time we want to validate function validateOrderTime(LibOrder.Order memory order) internal view { + // solhint-disable-next-line not-rely-on-time require(order.start == 0 || order.start < block.timestamp, "Order start validation failed"); + // solhint-disable-next-line not-rely-on-time require(order.end == 0 || order.end > block.timestamp, "Order end validation failed"); } } diff --git a/packages/marketplace/contracts/royalties-registry/RoyaltiesRegistry.sol b/packages/marketplace/contracts/royalties-registry/RoyaltiesRegistry.sol index 003b9e4a59..e2d518024a 100644 --- a/packages/marketplace/contracts/royalties-registry/RoyaltiesRegistry.sol +++ b/packages/marketplace/contracts/royalties-registry/RoyaltiesRegistry.sol @@ -50,6 +50,7 @@ contract RoyaltiesRegistry is IRoyaltiesProvider, OwnableUpgradeable { uint256 internal constant ROYALTIES_TYPES_AMOUNT = 4; /// @notice Royalties registry initializer + // solhint-disable-next-line func-name-mixedcase function __RoyaltiesRegistry_init() external initializer { __Ownable_init(); } diff --git a/packages/marketplace/contracts/royalties-registry/mocks/royalty-registry/RoyaltiesRegistryOld.sol b/packages/marketplace/contracts/royalties-registry/mocks/royalty-registry/RoyaltiesRegistryOld.sol deleted file mode 100644 index 85a2f2f88c..0000000000 --- a/packages/marketplace/contracts/royalties-registry/mocks/royalty-registry/RoyaltiesRegistryOld.sol +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -import {IRoyaltiesProvider} from "../../../interfaces/IRoyaltiesProvider.sol"; -import {LibRoyalties2981} from "../../../royalties/LibRoyalties2981.sol"; -import {LibPart} from "../../../lib-part/LibPart.sol"; -import {IERC2981} from "../../../royalties/IERC2981.sol"; -import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; -import {IERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol"; - -//old RoyaltiesRegistry with royaltiesProviders changed to mapping(address => uint256) to test upgradeability -contract RoyaltiesRegistryOld is IRoyaltiesProvider, OwnableUpgradeable { - event RoyaltiesSetForToken(address indexed token, uint256 indexed tokenId, LibPart.Part[] royalties); - event RoyaltiesSetForContract(address indexed token, LibPart.Part[] royalties); - - struct RoyaltiesSet { - bool initialized; - LibPart.Part[] royalties; - } - - mapping(bytes32 => RoyaltiesSet) public royaltiesByTokenAndTokenId; - mapping(address => RoyaltiesSet) public royaltiesByToken; - mapping(address => uint256) public royaltiesProviders; - - function __RoyaltiesRegistry_init() external initializer { - __Ownable_init(); - } - - function setProviderByToken(address token, address provider) external { - checkOwner(token); - royaltiesProviders[token] = uint160(provider); - } - - function getProvider(address token) public view returns (address) { - return address(uint160(royaltiesProviders[token])); - } - - function setRoyaltiesByToken(address token, LibPart.Part[] memory royalties) external { - checkOwner(token); - uint256 sumRoyalties = 0; - delete royaltiesByToken[token]; - for (uint256 i = 0; i < royalties.length; ++i) { - require(royalties[i].account != address(0x0), "RoyaltiesByToken recipient should be present"); - require(royalties[i].value != 0, "Royalty value for RoyaltiesByToken should be > 0"); - royaltiesByToken[token].royalties.push(royalties[i]); - sumRoyalties += royalties[i].value; - } - require(sumRoyalties < 10000, "Set by token royalties sum more, than 100%"); - royaltiesByToken[token].initialized = true; - emit RoyaltiesSetForContract(token, royalties); - } - - function setRoyaltiesByTokenAndTokenId(address token, uint256 tokenId, LibPart.Part[] memory royalties) external { - checkOwner(token); - setRoyaltiesCacheByTokenAndTokenId(token, tokenId, royalties); - } - - function checkOwner(address token) internal view { - if ((owner() != _msgSender()) && (OwnableUpgradeable(token).owner() != _msgSender())) { - revert("Token owner not detected"); - } - } - - function getRoyalties(address token, uint256 tokenId) external override returns (LibPart.Part[] memory) { - RoyaltiesSet memory royaltiesSet = royaltiesByTokenAndTokenId[keccak256(abi.encode(token, tokenId))]; - if (royaltiesSet.initialized) { - return royaltiesSet.royalties; - } - royaltiesSet = royaltiesByToken[token]; - if (royaltiesSet.initialized) { - return royaltiesSet.royalties; - } - (bool result, LibPart.Part[] memory resultRoyalties) = providerExtractor(token, tokenId); - if (result == false) { - resultRoyalties = royaltiesFromContract(token, tokenId); - } - setRoyaltiesCacheByTokenAndTokenId(token, tokenId, resultRoyalties); - return resultRoyalties; - } - - function setRoyaltiesCacheByTokenAndTokenId( - address token, - uint256 tokenId, - LibPart.Part[] memory royalties - ) internal { - uint256 sumRoyalties = 0; - bytes32 key = keccak256(abi.encode(token, tokenId)); - delete royaltiesByTokenAndTokenId[key].royalties; - for (uint256 i = 0; i < royalties.length; ++i) { - require(royalties[i].account != address(0x0), "RoyaltiesByTokenAndTokenId recipient should be present"); - require(royalties[i].value != 0, "Royalty value for RoyaltiesByTokenAndTokenId should be > 0"); - royaltiesByTokenAndTokenId[key].royalties.push(royalties[i]); - sumRoyalties += royalties[i].value; - } - require(sumRoyalties < 10000, "Set by token and tokenId royalties sum more, than 100%"); - royaltiesByTokenAndTokenId[key].initialized = true; - emit RoyaltiesSetForToken(token, tokenId, royalties); - } - - function royaltiesFromContract(address token, uint256 tokenId) internal view returns (LibPart.Part[] memory) { - (LibPart.Part[] memory royalties, bool isNative) = royaltiesFromContractNative(); - if (isNative) { - return royalties; - } - return royaltiesFromContractSpecial(token, tokenId); - } - - function royaltiesFromContractNative() internal view returns (LibPart.Part[] memory, bool) { - address payable[] memory recipients; - uint256[] memory values; - if (values.length != recipients.length) { - return (new LibPart.Part[](0), true); - } - LibPart.Part[] memory result = new LibPart.Part[](values.length); - for (uint256 i = 0; i < values.length; ++i) { - result[i].value = uint96(values[i]); - result[i].account = recipients[i]; - } - return (result, true); - } - - function royaltiesFromContractSpecial( - address token, - uint256 tokenId - ) internal view returns (LibPart.Part[] memory) { - if (IERC165Upgradeable(token).supportsInterface(LibRoyalties2981._INTERFACE_ID_ROYALTIES)) { - IERC2981 v2981 = IERC2981(token); - try v2981.royaltyInfo(tokenId, LibRoyalties2981._WEIGHT_VALUE) returns ( - address receiver, - uint256 royaltyAmount - ) { - return LibRoyalties2981.calculateRoyalties(receiver, royaltyAmount); - } catch { - return new LibPart.Part[](0); - } - } - return new LibPart.Part[](0); - } - - function providerExtractor( - address token, - uint256 tokenId - ) internal returns (bool result, LibPart.Part[] memory royalties) { - result = false; - address providerAddress = getProvider(token); - if (providerAddress != address(0x0)) { - IRoyaltiesProvider provider = IRoyaltiesProvider(providerAddress); - try provider.getRoyalties(token, tokenId) returns (LibPart.Part[] memory royaltiesByProvider) { - royalties = royaltiesByProvider; - result = true; - // solhint-disable-next-line no-empty-blocks - } catch {} - } - } - - uint256[46] private __gap; -} diff --git a/packages/marketplace/contracts/test/TestChainId.sol b/packages/marketplace/contracts/test/TestChainId.sol deleted file mode 100644 index dec02f15f0..0000000000 --- a/packages/marketplace/contracts/test/TestChainId.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -contract TestChainId { - function getChainID() public view returns (uint256 id) { - assembly { - id := chainid() - } - } -} diff --git a/packages/marketplace/contracts/transfer-manager/TransferManager.sol b/packages/marketplace/contracts/transfer-manager/TransferManager.sol index f7a9e2d3f1..69ec19283f 100644 --- a/packages/marketplace/contracts/transfer-manager/TransferManager.sol +++ b/packages/marketplace/contracts/transfer-manager/TransferManager.sol @@ -52,6 +52,7 @@ abstract contract TransferManager is ERC165Upgradeable, ITransferManager { /// @param newProtocolFeeSecondary fee for secondary market /// @param newDefaultFeeReceiver address for account receiving fees /// @param newRoyaltiesProvider address of royalties registry + // solhint-disable-next-line func-name-mixedcase function __TransferManager_init_unchained( uint256 newProtocolFeePrimary, uint256 newProtocolFeeSecondary, diff --git a/packages/marketplace/contracts/transfer-manager/mocks/TransferExecutorTest.sol b/packages/marketplace/contracts/transfer-manager/mocks/TransferExecutorTest.sol deleted file mode 100644 index 94c17c47f2..0000000000 --- a/packages/marketplace/contracts/transfer-manager/mocks/TransferExecutorTest.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; -import {LibAsset} from "../../lib-asset/LibAsset.sol"; -import {TransferExecutor} from "../TransferExecutor.sol"; - -contract TransferExecutorTest is Initializable, OwnableUpgradeable, TransferExecutor { - function __TransferExecutorTest_init() external initializer { - __Ownable_init(); - } - - function transferTest(LibAsset.Asset calldata asset, address from, address to) external payable { - TransferExecutor.transfer(asset, from, to); - } -} diff --git a/packages/marketplace/test/fixtures.ts b/packages/marketplace/test/fixtures.ts index 30903eb7b6..2f10b3e892 100644 --- a/packages/marketplace/test/fixtures.ts +++ b/packages/marketplace/test/fixtures.ts @@ -18,7 +18,7 @@ async function deploy() { ); const RoyaltyRegistry = await RoyaltyRegistryFactory.deploy(); const OrderValidatorFactory = await ethers.getContractFactory( - 'OrderValidatorTest' + 'OrderValidator' ); const OrderValidatorAsDeployer = await upgrades.deployProxy( OrderValidatorFactory, From f2afbfbaa2f12e5c0077249a7f33942059c7dcd7 Mon Sep 17 00:00:00 2001 From: Andres Adjimann Date: Thu, 28 Sep 2023 00:27:47 -0300 Subject: [PATCH 2/2] fix: remove ExchagenMeta from deploy --- packages/deploy/hardhat.config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/deploy/hardhat.config.ts b/packages/deploy/hardhat.config.ts index cbeadcc96f..d3a3c64e31 100644 --- a/packages/deploy/hardhat.config.ts +++ b/packages/deploy/hardhat.config.ts @@ -12,7 +12,6 @@ const importedPackages = { '@sandbox-smart-contracts/marketplace': [ 'contracts/royalties-registry/RoyaltiesRegistry.sol', 'contracts/exchange/OrderValidator.sol', - 'contracts/exchange/ExchangeMeta.sol', 'contracts/exchange/Exchange.sol', 'contracts/exchange/AssetMatcher.sol', ],