From 1a5276380749dedef05229a19494eed26dadd59b Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Fri, 27 Oct 2023 23:01:51 +0200 Subject: [PATCH] chore(lint): cleanup config and affiliate flows --- contracts/.eslintrc.yml | 10 - contracts/.gitignore | 1 + contracts/.lintstagedrc | 5 +- contracts/.prettierignore | 2 + contracts/.prettierrc.yml | 23 -- contracts/.solcover.js | 7 - contracts/.solhint.json | 5 +- contracts/.vscode/settings.json | 2 - contracts/foundry.toml | 8 +- contracts/package.json | 9 +- .../BatchOrderTypehashRegistry.sol | 16 +- .../CreatorFeeManagerWithRebates.sol | 25 +- .../CreatorFeeManagerWithRoyalties.sol | 21 +- contracts/src/marketplace/CurrencyManager.sol | 4 +- .../src/marketplace/ExecutionManager.sol | 51 ++-- .../src/marketplace/InheritedStrategy.sol | 25 +- .../src/marketplace/LooksRareProtocol.sol | 108 ++++---- contracts/src/marketplace/NonceManager.sol | 8 +- .../src/marketplace/ProtocolFeeRecipient.sol | 8 +- contracts/src/marketplace/StrategyManager.sol | 16 +- contracts/src/marketplace/TransferManager.sol | 43 ++- .../src/marketplace/TransferSelectorNFT.sol | 18 +- .../executionStrategies/BaseStrategy.sol | 8 +- .../BaseStrategyChainlinkPriceLatency.sol | 2 +- .../StrategyChainlinkUSDDynamicAsk.sol | 45 ++-- .../StrategyCollectionOffer.sol | 34 +-- .../StrategyDutchAuction.sol | 30 +-- .../StrategyItemIdsRange.sol | 37 ++- .../marketplace/helpers/OrderValidatorV2A.sol | 254 ++++++++---------- .../marketplace/helpers/ProtocolHelpers.sol | 26 +- .../interfaces/ICreatorFeeManager.sol | 11 +- .../interfaces/IImmutableCreate2Factory.sol | 8 +- .../interfaces/ILooksRareProtocol.sol | 24 +- .../interfaces/IRoyaltyFeeRegistry.sol | 8 +- .../src/marketplace/interfaces/IStrategy.sol | 10 +- .../interfaces/ITransferManager.sol | 4 +- .../libraries/CurrencyValidator.sol | 6 +- .../MerkleProofCalldataWithNodes.sol | 23 +- .../OpenZeppelin/MerkleProofMemory.sol | 2 +- .../marketplace/libraries/OrderStructs.sol | 77 +++--- contracts/src/protocol/AllowlistMinter.sol | 20 +- contracts/src/protocol/HypercertMinter.sol | 59 ++-- contracts/src/protocol/SemiFungible1155.sol | 160 ++++++----- .../src/protocol/interfaces/IAllowlist.sol | 9 +- .../BatchMakerCollectionOrders.t.sol | 27 +- .../marketplace/BatchMakerOrders.t.sol | 202 +++++--------- .../BatchOrderTypehashRegistry.t.sol | 57 ++-- .../marketplace/BundleTransactions.t.sol | 72 ++--- .../CreatorFeeManagerWithRebates.t.sol | 81 ++---- .../CreatorFeeManagerWithRoyalties.t.sol | 138 +++------- .../foundry/marketplace/CurrencyManager.t.sol | 10 +- .../DelegationRecipientsTaker.t.sol | 29 +- .../marketplace/DomainSeparatorUpdates.t.sol | 36 +-- .../marketplace/ExecutionManager.t.sol | 112 ++++---- .../foundry/marketplace/GasGriefing.t.sol | 36 +-- .../foundry/marketplace/InitialStates.t.sol | 4 +- .../marketplace/LooksRareProtocol.t.sol | 104 +++---- .../marketplace/NonceInvalidation.t.sol | 91 +++---- .../marketplace/OrderValidatorV2A.t.sol | 168 +++++------- .../foundry/marketplace/ProtocolBase.t.sol | 63 ++--- .../marketplace/ProtocolFeeRecipient.t.sol | 17 +- .../test/foundry/marketplace/Sandbox.t.sol | 36 +-- .../marketplace/SignaturesEIP2098.t.sol | 14 +- .../SignaturesERC1271WalletForERC1155.t.sol | 150 ++++------- .../SignaturesERC1271WalletForERC721.t.sol | 105 +++----- .../marketplace/SignaturesRevertions.t.sol | 85 +++--- .../marketplace/StandardTransactions.t.sol | 141 ++++------ .../foundry/marketplace/StrategyManager.t.sol | 62 ++--- .../foundry/marketplace/TransferManager.t.sol | 32 +-- ...ifyOrderTimestampValidityEquivalence.t.sol | 8 +- .../Chainlink/USDDynamicAskOrders.t.sol | 93 ++++--- .../CollectionOffers.t.sol | 85 +++--- .../DutchAuctionOrders.t.sol | 143 ++++------ .../ItemIdsRangeOrders.t.sol | 82 +++--- .../MultiFillCollectionOrders.t.sol | 33 +-- .../foundry/marketplace/utils/BytesLib.sol | 4 +- .../marketplace/utils/EIP712MerkleTree.sol | 47 ++-- .../marketplace/utils/ERC1271Wallet.sol | 14 +- .../utils/MaliciousERC1271Wallet.sol | 22 +- ...MaliciousIsValidSignatureERC1271Wallet.sol | 2 +- ...aliciousOnERC1155ReceivedERC1271Wallet.sol | 14 +- ...C1155ReceivedTheThirdTimeERC1271Wallet.sol | 2 +- .../marketplace/utils/MerkleWithPosition.sol | 25 +- .../marketplace/utils/MockOrderGenerator.sol | 65 +++-- .../marketplace/utils/ProtocolHelpers.sol | 18 +- .../StrategyTestMultiFillCollectionOrder.sol | 32 +-- .../foundry/marketplace/utils/TestHelpers.sol | 4 +- .../marketplace/utils/TestParameters.sol | 13 +- .../foundry/protocol/AllowlistMinter.t.sol | 27 +- .../test/foundry/protocol/Bitshifting.t.sol | 17 +- .../HypercertMinter.batchminting.t.sol | 48 ++-- .../protocol/HypercertMinter.pausable.t.sol | 18 +- .../foundry/protocol/HypercertMinter.t.sol | 38 +-- .../protocol/HypercertMinter.transfers.t.sol | 14 +- .../foundry/protocol/PerformanceTesting.t.sol | 49 ++-- .../SemiFungible1155.allowances.t.sol | 8 +- .../protocol/SemiFungible1155.burning.t.sol | 8 +- .../protocol/SemiFungible1155.minting.t.sol | 24 +- .../foundry/protocol/SemiFungible1155.t.sol | 14 +- .../protocol/SemiFungible1155.transfers.t.sol | 18 +- .../protocol/SemiFungible1155.units.sol | 14 +- .../foundry/protocol/SemiFungibleHelper.sol | 8 +- .../api/contracts/HypercertMinter.md | 8 +- pnpm-lock.yaml | 3 - 104 files changed, 1738 insertions(+), 2428 deletions(-) delete mode 100644 contracts/.solcover.js diff --git a/contracts/.eslintrc.yml b/contracts/.eslintrc.yml index a6c77c81..bc63dc32 100644 --- a/contracts/.eslintrc.yml +++ b/contracts/.eslintrc.yml @@ -8,13 +8,3 @@ parserOptions: project: "./contracts/tsconfig.json" plugins: - "@typescript-eslint" -rules: - "@typescript-eslint/no-floating-promises": - - error - - ignoreIIFE: true - ignoreVoid: true - "@typescript-eslint/no-inferrable-types": "off" - "@typescript-eslint/no-unused-vars": - - error - - argsIgnorePattern: "_" - varsIgnorePattern: "_" diff --git a/contracts/.gitignore b/contracts/.gitignore index 41c2623f..45e7e641 100644 --- a/contracts/.gitignore +++ b/contracts/.gitignore @@ -35,6 +35,7 @@ yarn-error.log* .DS_Store /.idea test*.svg +lcov.info # broadcasts !/broadcast diff --git a/contracts/.lintstagedrc b/contracts/.lintstagedrc index 45a7492d..0e2564c9 100644 --- a/contracts/.lintstagedrc +++ b/contracts/.lintstagedrc @@ -1,5 +1,4 @@ { - "*.{js,json,md,sol,ts,yml}": [ - "prettier --config ./.prettierrc.yml --write" - ] + "*.{js,json,md,ts,yml}": ["prettier --config ./.prettierrc.yml --write"], + "*.{sol}": ["forge fmt"] } diff --git a/contracts/.prettierignore b/contracts/.prettierignore index 406d1f27..1a71d38f 100644 --- a/contracts/.prettierignore +++ b/contracts/.prettierignore @@ -22,8 +22,10 @@ # files *.env *.log +*.sol .pnp.* coverage.json npm-debug.log* yarn-debug.log* yarn-error.log* +.DS_Store diff --git a/contracts/.prettierrc.yml b/contracts/.prettierrc.yml index 0f125e7c..b8ea7e0f 100644 --- a/contracts/.prettierrc.yml +++ b/contracts/.prettierrc.yml @@ -6,26 +6,3 @@ singleQuote: false tabWidth: 2 trailingComma: "all" useTabs: false - -plugins: - - prettier-plugin-solidity - -overrides: - - files: "**/*.t.sol" - rules: - max-state-count": "off" - state-visibility": "off" - max-line-length": "off" - options: - tabWidth: 4 - - files: "*.sol" - rules: - compiler-version: "0.8.16" - options: - tabWidth: 4 - - files: "*.ts" - options: - importOrder: ["", "^[./]"] - importOrderParserPlugins: ["importAssertions", "typescript"] - importOrderSeparation: true - importOrderSortSpecifiers: true diff --git a/contracts/.solcover.js b/contracts/.solcover.js deleted file mode 100644 index a6b8e642..00000000 --- a/contracts/.solcover.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - istanbulReporter: ["html", "lcov"], - providerOptions: { - mnemonic: process.env.MNEMONIC, - }, - skipFiles: ["test", "mocks", "lib"], -}; diff --git a/contracts/.solhint.json b/contracts/.solhint.json index c7aea11c..5a2b49ec 100644 --- a/contracts/.solhint.json +++ b/contracts/.solhint.json @@ -1,13 +1,14 @@ { - "plugins": ["prettier"], "extends": "solhint:recommended", "rules": { + "avoid-low-level-calls": "off", "code-complexity": ["error", 12], "compiler-version": ["error", ">=0.8.16"], "func-visibility": ["error", { "ignoreConstructors": true }], - "max-line-length": ["warn", 200], "no-console": "off", + "no-empty-blocks": "off", "not-rely-on-time": "off", + "private-vars-leading-underscore": "warn", "reason-string": ["warn", { "maxLength": 64 }], "one-contract-per-file": "off" } diff --git a/contracts/.vscode/settings.json b/contracts/.vscode/settings.json index 5a74fb60..ea8a1e8a 100644 --- a/contracts/.vscode/settings.json +++ b/contracts/.vscode/settings.json @@ -1,10 +1,8 @@ { "editor.formatOnSave": true, - "solidity.formatter": "prettier", "solidity.packageDefaultDependenciesContractsDirectory": "src", "solidity.packageDefaultDependenciesDirectory": "lib", "solidity.remappings": ["./remappings.txt"], - "solidity.defaultCompiler": "remoteFile", "files.exclude": { "**/.git": true, "**/.svn": true, diff --git a/contracts/foundry.toml b/contracts/foundry.toml index 4b146c01..a3a0c8f9 100644 --- a/contracts/foundry.toml +++ b/contracts/foundry.toml @@ -1,7 +1,7 @@ # Full reference https://github.com/foundry-rs/foundry/tree/master/config [profile.default] -auto_detect_solc = true +auto_detect_solc = true allow_paths = ["../node_modules", "lib"] bytecode_hash = "none" force = false @@ -23,4 +23,8 @@ verbosity = 1 [rpc_endpoints] mainnet = "${MAINNET_RPC_URL}" goerli = "${GOERLI_RPC_URL}" -optimism = "${OPTIMISM_RPC_URL}" \ No newline at end of file +optimism = "${OPTIMISM_RPC_URL}" + +[fmt] +number_underscore = "thousands" +wrap_comments = true diff --git a/contracts/package.json b/contracts/package.json index 36d2c440..5ad67eae 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -84,7 +84,6 @@ "shx": "^0.3.4", "solhint": "^3.6.2", "solhint-plugin-prettier": "^0.0.5", - "solidity-coverage": "^0.8.2", "solmate": "^6.2.0", "ts-node": "^10.9.1", "typechain": "^8.3.1", @@ -104,14 +103,14 @@ "build": "hardhat compile && pnpm tsc -p tsconfig.build.json && rollup -c && pnpm copy:contracts", "build:forge": "forge build", "clean": "rimraf cache out dist src/typechain src/abi", - "copy:contracts": "copyfiles -u 1 ./src/**/*.sol ./src/*.sol ./contracts", + "copy:contracts": "copyfiles -u 1 ./src/**/*.sol ./src/*.sol ./contracts", "docs": "hardhat dodoc", "lint": "pnpm lint:sol && pnpm prettier:check", - "lint:sol": "solhint -w 60 \"./{src,test/protocol,test/marketplace}/**/*.sol\"", + "lint:sol": "forge fmt --check && solhint \"./{src,test/protocol,test/marketplace}/**/*.sol\"", "prebuild": "pnpm clean", "prepublish": "pnpm build", - "prettier": "prettier --config \"./.prettierrc.yml\" --write \"**/*.{json,md,sol,yml}\"", - "prettier:check": "prettier --config \"./.prettierrc.yml\" --check \"**/*.{json,md,sol,yml}\"", + "prettier": "prettier --config \"./.prettierrc.yml\" --write \"**/*.{json,md,ts,yml}\"", + "prettier:check": "prettier --config \"./.prettierrc.yml\" --check \"**/*.{json,md,ts,yml}\"", "slither": "slither ./src", "test": "pnpm test:hardhat && pnpm test:forge", "test:forge": "forge test", diff --git a/contracts/src/marketplace/BatchOrderTypehashRegistry.sol b/contracts/src/marketplace/BatchOrderTypehashRegistry.sol index 13851212..9710a735 100644 --- a/contracts/src/marketplace/BatchOrderTypehashRegistry.sol +++ b/contracts/src/marketplace/BatchOrderTypehashRegistry.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.17; // Shared errors -import { MerkleProofTooLarge } from "./errors/SharedErrors.sol"; +import {MerkleProofTooLarge} from "./errors/SharedErrors.sol"; /** * @title BatchOrderTypehashRegistry @@ -22,9 +22,17 @@ contract BatchOrderTypehashRegistry { /** * @dev It looks like this for each height - * height == 1: BatchOrder(Maker[2] tree)Maker(uint8 quoteType,uint256 globalNonce,uint256 subsetNonce,uint256 orderNonce,uint256 strategyId,uint8 collectionType,address collection,address currency,address signer,uint256 startTime,uint256 endTime,uint256 price,uint256[] itemIds,uint256[] amounts,bytes additionalParameters) - * height == 2: BatchOrder(Maker[2][2] tree)Maker(uint8 quoteType,uint256 globalNonce,uint256 subsetNonce,uint256 orderNonce,uint256 strategyId,uint8 collectionType,address collection,address currency,address signer,uint256 startTime,uint256 endTime,uint256 price,uint256[] itemIds,uint256[] amounts,bytes additionalParameters) - * height == n: BatchOrder(Maker[2]...[2] tree)Maker(uint8 quoteType,uint256 globalNonce,uint256 subsetNonce,uint256 orderNonce,uint256 strategyId,uint8 collectionType,address collection,address currency,address signer,uint256 startTime,uint256 endTime,uint256 price,uint256[] itemIds,uint256[] amounts,bytes additionalParameters) + * height == 1: BatchOrder(Maker[2] tree)Maker(uint8 quoteType,uint256 globalNonce,uint256 subsetNonce,uint256 + * orderNonce,uint256 strategyId,uint8 collectionType,address collection,address currency,address signer,uint256 + * startTime,uint256 endTime,uint256 price,uint256[] itemIds,uint256[] amounts,bytes additionalParameters) + * height == 2: BatchOrder(Maker[2][2] tree)Maker(uint8 quoteType,uint256 globalNonce,uint256 + * subsetNonce,uint256 orderNonce,uint256 strategyId,uint8 collectionType,address collection,address + * currency,address signer,uint256 startTime,uint256 endTime,uint256 price,uint256[] itemIds,uint256[] amounts,bytes + * additionalParameters) + * height == n: BatchOrder(Maker[2]...[2] tree)Maker(uint8 quoteType,uint256 globalNonce,uint256 + * subsetNonce,uint256 orderNonce,uint256 strategyId,uint8 collectionType,address collection,address + * currency,address signer,uint256 startTime,uint256 endTime,uint256 price,uint256[] itemIds,uint256[] amounts,bytes + * additionalParameters) */ function _getBatchOrderTypehash(uint256 height) internal pure returns (bytes32 typehash) { if (height == 1) { diff --git a/contracts/src/marketplace/CreatorFeeManagerWithRebates.sol b/contracts/src/marketplace/CreatorFeeManagerWithRebates.sol index 4b5e6ef7..3a1de368 100644 --- a/contracts/src/marketplace/CreatorFeeManagerWithRebates.sol +++ b/contracts/src/marketplace/CreatorFeeManagerWithRebates.sol @@ -2,14 +2,14 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IERC2981 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC2981.sol"; +import {IERC2981} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC2981.sol"; // Interfaces -import { ICreatorFeeManager } from "./interfaces/ICreatorFeeManager.sol"; -import { IRoyaltyFeeRegistry } from "./interfaces/IRoyaltyFeeRegistry.sol"; +import {ICreatorFeeManager} from "./interfaces/ICreatorFeeManager.sol"; +import {IRoyaltyFeeRegistry} from "./interfaces/IRoyaltyFeeRegistry.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "./constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "./constants/NumericConstants.sol"; /** * @title CreatorFeeManagerWithRebates @@ -38,22 +38,21 @@ contract CreatorFeeManagerWithRebates is ICreatorFeeManager { /** * @inheritdoc ICreatorFeeManager */ - function viewCreatorFeeInfo( - address collection, - uint256 price, - uint256[] memory itemIds - ) external view returns (address creator, uint256 creatorFeeAmount) { + function viewCreatorFeeInfo(address collection, uint256 price, uint256[] memory itemIds) + external + view + returns (address creator, uint256 creatorFeeAmount) + { // Check if there is a royalty info in the system - (creator, ) = royaltyFeeRegistry.royaltyInfo(collection, price); + (creator,) = royaltyFeeRegistry.royaltyInfo(collection, price); if (creator == address(0)) { if (IERC2981(collection).supportsInterface(IERC2981.royaltyInfo.selector)) { uint256 length = itemIds.length; - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { try IERC2981(collection).royaltyInfo(itemIds[i], price) returns ( - address newCreator, - uint256 /* newCreatorFeeAmount */ + address newCreator, uint256 /* newCreatorFeeAmount */ ) { if (i == 0) { creator = newCreator; diff --git a/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol b/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol index ac72682d..a50dde6a 100644 --- a/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol +++ b/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol @@ -2,11 +2,11 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IERC2981 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC2981.sol"; +import {IERC2981} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC2981.sol"; // Interfaces -import { ICreatorFeeManager } from "./interfaces/ICreatorFeeManager.sol"; -import { IRoyaltyFeeRegistry } from "./interfaces/IRoyaltyFeeRegistry.sol"; +import {ICreatorFeeManager} from "./interfaces/ICreatorFeeManager.sol"; +import {IRoyaltyFeeRegistry} from "./interfaces/IRoyaltyFeeRegistry.sol"; /** * @title CreatorFeeManagerWithRoyalties @@ -44,11 +44,11 @@ contract CreatorFeeManagerWithRoyalties is ICreatorFeeManager { * (1) high royalties * (2) potential unexpected royalty changes that can occur after the creation of the order. */ - function viewCreatorFeeInfo( - address collection, - uint256 price, - uint256[] memory itemIds - ) external view returns (address creator, uint256 creatorFeeAmount) { + function viewCreatorFeeInfo(address collection, uint256 price, uint256[] memory itemIds) + external + view + returns (address creator, uint256 creatorFeeAmount) + { // Check if there is a royalty info in the system (creator, creatorFeeAmount) = royaltyFeeRegistry.royaltyInfo(collection, price); @@ -56,10 +56,9 @@ contract CreatorFeeManagerWithRoyalties is ICreatorFeeManager { if (IERC2981(collection).supportsInterface(IERC2981.royaltyInfo.selector)) { uint256 length = itemIds.length; - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { try IERC2981(collection).royaltyInfo(itemIds[i], price) returns ( - address newCreator, - uint256 newCreatorFeeAmount + address newCreator, uint256 newCreatorFeeAmount ) { if (i == 0) { creator = newCreator; diff --git a/contracts/src/marketplace/CurrencyManager.sol b/contracts/src/marketplace/CurrencyManager.sol index 103d0789..f72b5471 100644 --- a/contracts/src/marketplace/CurrencyManager.sol +++ b/contracts/src/marketplace/CurrencyManager.sol @@ -2,10 +2,10 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { OwnableTwoSteps } from "@looksrare/contracts-libs/contracts/OwnableTwoSteps.sol"; +import {OwnableTwoSteps} from "@looksrare/contracts-libs/contracts/OwnableTwoSteps.sol"; // Interfaces -import { ICurrencyManager } from "./interfaces/ICurrencyManager.sol"; +import {ICurrencyManager} from "./interfaces/ICurrencyManager.sol"; /** * @title CurrencyManager diff --git a/contracts/src/marketplace/ExecutionManager.sol b/contracts/src/marketplace/ExecutionManager.sol index 06de37c1..e3e132df 100644 --- a/contracts/src/marketplace/ExecutionManager.sol +++ b/contracts/src/marketplace/ExecutionManager.sol @@ -2,25 +2,31 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "./libraries/OrderStructs.sol"; +import {OrderStructs} from "./libraries/OrderStructs.sol"; // Interfaces -import { IExecutionManager } from "./interfaces/IExecutionManager.sol"; -import { ICreatorFeeManager } from "./interfaces/ICreatorFeeManager.sol"; +import {IExecutionManager} from "./interfaces/IExecutionManager.sol"; +import {ICreatorFeeManager} from "./interfaces/ICreatorFeeManager.sol"; // Direct dependencies -import { InheritedStrategy } from "./InheritedStrategy.sol"; -import { NonceManager } from "./NonceManager.sol"; -import { StrategyManager } from "./StrategyManager.sol"; +import {InheritedStrategy} from "./InheritedStrategy.sol"; +import {NonceManager} from "./NonceManager.sol"; +import {StrategyManager} from "./StrategyManager.sol"; // Assembly -import { NoSelectorForStrategy_error_selector, NoSelectorForStrategy_error_length, OutsideOfTimeRange_error_selector, OutsideOfTimeRange_error_length, Error_selector_offset } from "./constants/AssemblyConstants.sol"; +import { + NoSelectorForStrategy_error_selector, + NoSelectorForStrategy_error_length, + OutsideOfTimeRange_error_selector, + OutsideOfTimeRange_error_length, + Error_selector_offset +} from "./constants/AssemblyConstants.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "./constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "./constants/NumericConstants.sol"; // Enums -import { QuoteType } from "./enums/QuoteType.sol"; +import {QuoteType} from "./enums/QuoteType.sol"; /** * @title ExecutionManager @@ -39,7 +45,7 @@ contract ExecutionManager is InheritedStrategy, NonceManager, StrategyManager, I * @notice Maximum creator fee (in basis point). */ // TODO do we need a max? Is 1% max fair? - uint16 public maxCreatorFeeBp = 1_000; + uint16 public maxCreatorFeeBp = 1000; /** * @notice Creator fee manager. @@ -72,7 +78,7 @@ contract ExecutionManager is InheritedStrategy, NonceManager, StrategyManager, I * Only callable by owner. */ function updateMaxCreatorFeeBp(uint16 newMaxCreatorFeeBp) external onlyOwner { - if (newMaxCreatorFeeBp > 2_500) { + if (newMaxCreatorFeeBp > 2500) { revert CreatorFeeBpTooHigh(); } @@ -172,11 +178,8 @@ contract ExecutionManager is InheritedStrategy, NonceManager, StrategyManager, I } // Creator fee and adjustment of protocol fee - (recipients[1], feeAmounts[1]) = _getCreatorRecipientAndCalculateFeeAmount( - makerOrder.collection, - price, - itemIds - ); + (recipients[1], feeAmounts[1]) = + _getCreatorRecipientAndCalculateFeeAmount(makerOrder.collection, price, itemIds); if (makerOrder.quoteType == QuoteType.Bid) { _setTheRestOfFeeAmountsAndRecipients( makerOrder.strategyId, @@ -187,11 +190,7 @@ contract ExecutionManager is InheritedStrategy, NonceManager, StrategyManager, I ); } else { _setTheRestOfFeeAmountsAndRecipients( - makerOrder.strategyId, - price, - makerOrder.signer, - feeAmounts, - recipients + makerOrder.strategyId, price, makerOrder.signer, feeAmounts, recipients ); } } @@ -240,11 +239,11 @@ contract ExecutionManager is InheritedStrategy, NonceManager, StrategyManager, I * @return creator Creator recipient * @return creatorFeeAmount Creator fee amount */ - function _getCreatorRecipientAndCalculateFeeAmount( - address collection, - uint256 price, - uint256[] memory itemIds - ) private view returns (address creator, uint256 creatorFeeAmount) { + function _getCreatorRecipientAndCalculateFeeAmount(address collection, uint256 price, uint256[] memory itemIds) + private + view + returns (address creator, uint256 creatorFeeAmount) + { if (address(creatorFeeManager) != address(0)) { (creator, creatorFeeAmount) = creatorFeeManager.viewCreatorFeeInfo(collection, price, itemIds); diff --git a/contracts/src/marketplace/InheritedStrategy.sol b/contracts/src/marketplace/InheritedStrategy.sol index 9f84b5a1..93d09414 100644 --- a/contracts/src/marketplace/InheritedStrategy.sol +++ b/contracts/src/marketplace/InheritedStrategy.sol @@ -2,13 +2,18 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "./libraries/OrderStructs.sol"; +import {OrderStructs} from "./libraries/OrderStructs.sol"; // Shared errors -import { OrderInvalid } from "./errors/SharedErrors.sol"; +import {OrderInvalid} from "./errors/SharedErrors.sol"; // Assembly -import { OrderInvalid_error_selector, OrderInvalid_error_length, Error_selector_offset, OneWord } from "./constants/AssemblyConstants.sol"; +import { + OrderInvalid_error_selector, + OrderInvalid_error_length, + Error_selector_offset, + OneWord +} from "./constants/AssemblyConstants.sol"; /** * @title InheritedStrategy @@ -26,10 +31,10 @@ contract InheritedStrategy { * @param amounts Array of amounts * @param itemIds Array of item ids */ - function _verifyItemIdsAndAmountsEqualLengthsAndValidAmounts( - uint256[] calldata amounts, - uint256[] calldata itemIds - ) internal pure { + function _verifyItemIdsAndAmountsEqualLengthsAndValidAmounts(uint256[] calldata amounts, uint256[] calldata itemIds) + internal + pure + { assembly { let end { @@ -56,11 +61,7 @@ contract InheritedStrategy { let amountsOffset := amounts.offset - for { - - } end { - - } { + for {} end {} { /** * @dev Starting from the end of the array minus 32 bytes to load the last item, * ending with `end` equal to 0 to load the first item diff --git a/contracts/src/marketplace/LooksRareProtocol.sol b/contracts/src/marketplace/LooksRareProtocol.sol index 45c6331f..b60e6e30 100644 --- a/contracts/src/marketplace/LooksRareProtocol.sol +++ b/contracts/src/marketplace/LooksRareProtocol.sol @@ -2,32 +2,40 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { SignatureCheckerCalldata } from "@looksrare/contracts-libs/contracts/SignatureCheckerCalldata.sol"; -import { LowLevelETHReturnETHIfAnyExceptOneWei } from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelETHReturnETHIfAnyExceptOneWei.sol"; -import { LowLevelWETH } from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelWETH.sol"; -import { LowLevelERC20Transfer } from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC20Transfer.sol"; +import {SignatureCheckerCalldata} from "@looksrare/contracts-libs/contracts/SignatureCheckerCalldata.sol"; +import {LowLevelETHReturnETHIfAnyExceptOneWei} from + "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelETHReturnETHIfAnyExceptOneWei.sol"; +import {LowLevelWETH} from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelWETH.sol"; +import {LowLevelERC20Transfer} from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC20Transfer.sol"; // OpenZeppelin's library (adjusted) for verifying Merkle proofs -import { MerkleProofCalldataWithNodes } from "./libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol"; +import {MerkleProofCalldataWithNodes} from "./libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol"; // Libraries -import { OrderStructs } from "./libraries/OrderStructs.sol"; +import {OrderStructs} from "./libraries/OrderStructs.sol"; // Interfaces -import { ILooksRareProtocol } from "./interfaces/ILooksRareProtocol.sol"; +import {ILooksRareProtocol} from "./interfaces/ILooksRareProtocol.sol"; // Shared errors -import { CallerInvalid, CurrencyInvalid, LengthsInvalid, MerkleProofInvalid, MerkleProofTooLarge, QuoteTypeInvalid } from "./errors/SharedErrors.sol"; +import { + CallerInvalid, + CurrencyInvalid, + LengthsInvalid, + MerkleProofInvalid, + MerkleProofTooLarge, + QuoteTypeInvalid +} from "./errors/SharedErrors.sol"; // Direct dependencies -import { TransferSelectorNFT } from "./TransferSelectorNFT.sol"; -import { BatchOrderTypehashRegistry } from "./BatchOrderTypehashRegistry.sol"; +import {TransferSelectorNFT} from "./TransferSelectorNFT.sol"; +import {BatchOrderTypehashRegistry} from "./BatchOrderTypehashRegistry.sol"; // Constants -import { MAX_CALLDATA_PROOF_LENGTH, ONE_HUNDRED_PERCENT_IN_BP } from "./constants/NumericConstants.sol"; +import {MAX_CALLDATA_PROOF_LENGTH, ONE_HUNDRED_PERCENT_IN_BP} from "./constants/NumericConstants.sol"; // Enums -import { QuoteType } from "./enums/QuoteType.sol"; +import {QuoteType} from "./enums/QuoteType.sol"; /** * @title LooksRareProtocol @@ -103,7 +111,7 @@ contract LooksRareProtocol is * If a standard ETH transfer fails within this gas limit, ETH will get wrapped to WETH * and transferred to the initial recipient. */ - uint256 private _gasLimitETHTransfer = 2_300; + uint256 private _gasLimitETHTransfer = 2300; /** * @notice Constructor @@ -112,12 +120,9 @@ contract LooksRareProtocol is * @param _transferManager Transfer manager address * @param _weth Wrapped ETH address */ - constructor( - address _owner, - address _protocolFeeRecipient, - address _transferManager, - address _weth - ) TransferSelectorNFT(_owner, _protocolFeeRecipient, _transferManager) { + constructor(address _owner, address _protocolFeeRecipient, address _transferManager, address _weth) + TransferSelectorNFT(_owner, _protocolFeeRecipient, _transferManager) + { _updateDomainSeparator(); WETH = _weth; } @@ -129,8 +134,7 @@ contract LooksRareProtocol is OrderStructs.Taker calldata takerAsk, OrderStructs.Maker calldata makerBid, bytes calldata makerSignature, - OrderStructs.MerkleTree calldata merkleTree, - address affiliate + OrderStructs.MerkleTree calldata merkleTree ) external nonReentrant { address currency = makerBid.currency; @@ -147,7 +151,7 @@ contract LooksRareProtocol is uint256 totalProtocolFeeAmount = _executeTakerAsk(takerAsk, makerBid, orderHash); // Pay protocol fee (and affiliate fee if any) - _payProtocolFeeAndAffiliateFee(currency, signer, affiliate, totalProtocolFeeAmount); + _payProtocolFeeAndAffiliateFee(currency, signer, totalProtocolFeeAmount); } /** @@ -157,8 +161,7 @@ contract LooksRareProtocol is OrderStructs.Taker calldata takerBid, OrderStructs.Maker calldata makerAsk, bytes calldata makerSignature, - OrderStructs.MerkleTree calldata merkleTree, - address affiliate + OrderStructs.MerkleTree calldata merkleTree ) external payable nonReentrant { address currency = makerAsk.currency; @@ -173,8 +176,8 @@ contract LooksRareProtocol is // Execute the transaction and fetch protocol fee amount uint256 totalProtocolFeeAmount = _executeTakerBid(takerBid, makerAsk, msg.sender, orderHash); - // Pay protocol fee amount (and affiliate fee if any) - _payProtocolFeeAndAffiliateFee(currency, msg.sender, affiliate, totalProtocolFeeAmount); + // Pay protocol fee amount + _payProtocolFeeAndAffiliateFee(currency, msg.sender, totalProtocolFeeAmount); // Return ETH if any _returnETHIfAnyWithOneWeiLeft(); @@ -188,13 +191,12 @@ contract LooksRareProtocol is OrderStructs.Maker[] calldata makerAsks, bytes[] calldata makerSignatures, OrderStructs.MerkleTree[] calldata merkleTrees, - address affiliate, bool isAtomic ) external payable nonReentrant { uint256 length = takerBids.length; if ( - length == 0 || - (makerAsks.length ^ length) | (makerSignatures.length ^ length) | (merkleTrees.length ^ length) != 0 + length == 0 + || (makerAsks.length ^ length) | (makerSignatures.length ^ length) | (merkleTrees.length ^ length) != 0 ) { revert LengthsInvalid(); } @@ -212,7 +214,7 @@ contract LooksRareProtocol is // If atomic, it uses the executeTakerBid function. // If not atomic, it uses a catch/revert pattern with external function. if (isAtomic) { - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { OrderStructs.Maker calldata makerAsk = makerAsks[i]; // Verify the currency is the same @@ -237,7 +239,7 @@ contract LooksRareProtocol is } } } else { - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { OrderStructs.Maker calldata makerAsk = makerAsks[i]; // Verify the currency is the same @@ -267,7 +269,7 @@ contract LooksRareProtocol is } // Pay protocol fee (and affiliate fee if any) - _payProtocolFeeAndAffiliateFee(currency, msg.sender, affiliate, totalProtocolFeeAmount); + _payProtocolFeeAndAffiliateFee(currency, msg.sender, totalProtocolFeeAmount); } // Return ETH if any @@ -316,7 +318,7 @@ contract LooksRareProtocol is * @dev Only callable by owner. */ function updateETHGasLimitForTransfer(uint256 newGasLimitETHTransfer) external onlyOwner { - if (newGasLimitETHTransfer < 2_300) { + if (newGasLimitETHTransfer < 2300) { revert NewGasLimitETHTransferTooLow(); } @@ -346,9 +348,9 @@ contract LooksRareProtocol is bytes32 userOrderNonceStatus = userOrderNonce[signer][makerBid.orderNonce]; // Verify nonces if ( - userBidAskNonces[signer].bidNonce != makerBid.globalNonce || - userSubsetNonce[signer][makerBid.subsetNonce] || - (userOrderNonceStatus != bytes32(0) && userOrderNonceStatus != orderHash) + userBidAskNonces[signer].bidNonce != makerBid.globalNonce + || userSubsetNonce[signer][makerBid.subsetNonce] + || (userOrderNonceStatus != bytes32(0) && userOrderNonceStatus != orderHash) ) { revert NoncesInvalid(); } @@ -416,9 +418,9 @@ contract LooksRareProtocol is bytes32 userOrderNonceStatus = userOrderNonce[signer][makerAsk.orderNonce]; if ( - userBidAskNonces[signer].askNonce != makerAsk.globalNonce || - userSubsetNonce[signer][makerAsk.subsetNonce] || - (userOrderNonceStatus != bytes32(0) && userOrderNonceStatus != orderHash) + userBidAskNonces[signer].askNonce != makerAsk.globalNonce + || userSubsetNonce[signer][makerAsk.subsetNonce] + || (userOrderNonceStatus != bytes32(0) && userOrderNonceStatus != orderHash) ) { revert NoncesInvalid(); } @@ -473,15 +475,11 @@ contract LooksRareProtocol is * @notice This function is internal and is used to pay the protocol fee and affiliate fee (if any). * @param currency Currency address to transfer (address(0) is ETH) * @param bidUser Bid user address - * @param affiliate Affiliate address (address(0) if none) * @param totalProtocolFeeAmount Total protocol fee amount (denominated in the currency) */ - function _payProtocolFeeAndAffiliateFee( - address currency, - address bidUser, - address affiliate, - uint256 totalProtocolFeeAmount - ) internal { + function _payProtocolFeeAndAffiliateFee(address currency, address bidUser, uint256 totalProtocolFeeAmount) + internal + { if (totalProtocolFeeAmount != 0) { // Transfer remaining protocol fee to the protocol fee recipient _transferFungibleTokens(currency, bidUser, protocolFeeRecipient, totalProtocolFeeAmount); @@ -563,12 +561,9 @@ contract LooksRareProtocol is * If it is equal to false, this function maps the order hash for this user order nonce * to prevent other order structs sharing the same order nonce to be executed. */ - function _updateUserOrderNonce( - bool isNonceInvalidated, - address signer, - uint256 orderNonce, - bytes32 orderHash - ) private { + function _updateUserOrderNonce(bool isNonceInvalidated, address signer, uint256 orderNonce, bytes32 orderHash) + private + { userOrderNonce[signer][orderNonce] = (isNonceInvalidated ? MAGIC_VALUE_ORDER_NONCE_EXECUTED : orderHash); } @@ -579,13 +574,14 @@ contract LooksRareProtocol is * @param makerSignature Signature of the maker * @param signer Signer address */ - function _computeDigestAndVerify(bytes32 computedHash, bytes calldata makerSignature, address signer) private view { + function _computeDigestAndVerify(bytes32 computedHash, bytes calldata makerSignature, address signer) + private + view + { if (chainId == block.chainid) { // \x19\x01 is the standard encoding prefix SignatureCheckerCalldata.verify( - keccak256(abi.encodePacked("\x19\x01", domainSeparator, computedHash)), - signer, - makerSignature + keccak256(abi.encodePacked("\x19\x01", domainSeparator, computedHash)), signer, makerSignature ); } else { revert ChainIdInvalid(); diff --git a/contracts/src/marketplace/NonceManager.sol b/contracts/src/marketplace/NonceManager.sol index bc3dda7a..d9a94cfc 100644 --- a/contracts/src/marketplace/NonceManager.sol +++ b/contracts/src/marketplace/NonceManager.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.17; // Interfaces and errors -import { INonceManager } from "./interfaces/INonceManager.sol"; -import { LengthsInvalid } from "./errors/SharedErrors.sol"; +import {INonceManager} from "./interfaces/INonceManager.sol"; +import {LengthsInvalid} from "./errors/SharedErrors.sol"; /** * @title NonceManager @@ -49,7 +49,7 @@ contract NonceManager is INonceManager { revert LengthsInvalid(); } - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { userOrderNonce[msg.sender][orderNonces[i]] = MAGIC_VALUE_ORDER_NONCE_EXECUTED; unchecked { ++i; @@ -71,7 +71,7 @@ contract NonceManager is INonceManager { revert LengthsInvalid(); } - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { userSubsetNonce[msg.sender][subsetNonces[i]] = true; unchecked { ++i; diff --git a/contracts/src/marketplace/ProtocolFeeRecipient.sol b/contracts/src/marketplace/ProtocolFeeRecipient.sol index 2d3d2c73..33cfceb4 100644 --- a/contracts/src/marketplace/ProtocolFeeRecipient.sol +++ b/contracts/src/marketplace/ProtocolFeeRecipient.sol @@ -2,9 +2,9 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { LowLevelERC20Transfer } from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC20Transfer.sol"; -import { IWETH } from "@looksrare/contracts-libs/contracts/interfaces/generic/IWETH.sol"; -import { IERC20 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC20.sol"; +import {LowLevelERC20Transfer} from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC20Transfer.sol"; +import {IWETH} from "@looksrare/contracts-libs/contracts/interfaces/generic/IWETH.sol"; +import {IERC20} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC20.sol"; /** * @title ProtocolFeeRecipient @@ -28,7 +28,7 @@ contract ProtocolFeeRecipient is LowLevelERC20Transfer { uint256 ethBalance = address(this).balance; if (ethBalance != 0) { - WETH.deposit{ value: ethBalance }(); + WETH.deposit{value: ethBalance}(); } uint256 wethBalance = IERC20(address(WETH)).balanceOf(address(this)); diff --git a/contracts/src/marketplace/StrategyManager.sol b/contracts/src/marketplace/StrategyManager.sol index c80af8df..4edb9d66 100644 --- a/contracts/src/marketplace/StrategyManager.sol +++ b/contracts/src/marketplace/StrategyManager.sol @@ -2,11 +2,11 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { CurrencyManager } from "./CurrencyManager.sol"; +import {CurrencyManager} from "./CurrencyManager.sol"; // Interfaces -import { IStrategy } from "./interfaces/IStrategy.sol"; -import { IStrategyManager } from "./interfaces/IStrategyManager.sol"; +import {IStrategy} from "./interfaces/IStrategy.sol"; +import {IStrategyManager} from "./interfaces/IStrategyManager.sol"; /** * @title StrategyManager @@ -103,12 +103,10 @@ contract StrategyManager is IStrategyManager, CurrencyManager { * @param newMinTotalFee New minimum total fee (in basis point) * @dev Only callable by owner. */ - function updateStrategy( - uint256 strategyId, - bool isActive, - uint16 newStandardProtocolFee, - uint16 newMinTotalFee - ) external onlyOwner { + function updateStrategy(uint256 strategyId, bool isActive, uint16 newStandardProtocolFee, uint16 newMinTotalFee) + external + onlyOwner + { if (strategyId >= _countStrategies) { revert StrategyNotUsed(); } diff --git a/contracts/src/marketplace/TransferManager.sol b/contracts/src/marketplace/TransferManager.sol index f0015e67..cc1c9578 100644 --- a/contracts/src/marketplace/TransferManager.sol +++ b/contracts/src/marketplace/TransferManager.sol @@ -2,23 +2,24 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { OwnableTwoSteps } from "@looksrare/contracts-libs/contracts/OwnableTwoSteps.sol"; -import { LowLevelERC721Transfer } from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC721Transfer.sol"; -import { LowLevelERC1155Transfer } from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC1155Transfer.sol"; +import {OwnableTwoSteps} from "@looksrare/contracts-libs/contracts/OwnableTwoSteps.sol"; +import {LowLevelERC721Transfer} from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC721Transfer.sol"; +import {LowLevelERC1155Transfer} from "@looksrare/contracts-libs/contracts/lowLevelCallers/LowLevelERC1155Transfer.sol"; // Interfaces and errors -import { ITransferManager } from "./interfaces/ITransferManager.sol"; -import { AmountInvalid, LengthsInvalid } from "./errors/SharedErrors.sol"; +import {ITransferManager} from "./interfaces/ITransferManager.sol"; +import {AmountInvalid, LengthsInvalid} from "./errors/SharedErrors.sol"; // Libraries -import { OrderStructs } from "./libraries/OrderStructs.sol"; +import {OrderStructs} from "./libraries/OrderStructs.sol"; // Enums -import { CollectionType } from "./enums/CollectionType.sol"; +import {CollectionType} from "./enums/CollectionType.sol"; /** * @title TransferManager - * @notice This contract provides the transfer functions for ERC721/ERC1155/Hypercert/Hyperboard for contracts that require them. + * @notice This contract provides the transfer functions for ERC721/ERC1155/Hypercert/Hyperboard for contracts that + * require them. * Collection type "0" refers to ERC721 transfer functions. * Collection type "1" refers to ERC1155 transfer functions. * Collection type "2" refers to Hypercert transfer functions. @@ -68,7 +69,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER _isOperatorValidForTransfer(from, msg.sender); - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { if (amounts[i] != 1) { revert AmountInvalid(); } @@ -109,7 +110,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER } _executeERC1155SafeTransferFrom(collection, from, to, itemIds[0], amounts[0]); } else { - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { if (amounts[i] == 0) { revert AmountInvalid(); } @@ -152,7 +153,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER } _executeERC1155SafeTransferFrom(collection, from, to, itemIds[0], amounts[0]); } else { - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { if (amounts[i] == 0) { revert AmountInvalid(); } @@ -195,7 +196,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER } _executeERC1155SafeTransferFrom(collection, from, to, itemIds[0], amounts[0]); } else { - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { if (amounts[i] == 0) { revert AmountInvalid(); } @@ -214,11 +215,9 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER * @param from Sender address * @param to Recipient address */ - function transferBatchItemsAcrossCollections( - BatchTransferItem[] calldata items, - address from, - address to - ) external { + function transferBatchItemsAcrossCollections(BatchTransferItem[] calldata items, address from, address to) + external + { uint256 itemsLength = items.length; if (itemsLength == 0) { @@ -229,7 +228,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER _isOperatorValidForTransfer(from, msg.sender); } - for (uint256 i; i < itemsLength; ) { + for (uint256 i; i < itemsLength;) { uint256[] calldata itemIds = items[i].itemIds; uint256 itemIdsLengthForSingleCollection = itemIds.length; uint256[] calldata amounts = items[i].amounts; @@ -240,7 +239,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER CollectionType collectionType = items[i].collectionType; if (collectionType == CollectionType.ERC721) { - for (uint256 j; j < itemIdsLengthForSingleCollection; ) { + for (uint256 j; j < itemIdsLengthForSingleCollection;) { if (amounts[j] != 1) { revert AmountInvalid(); } @@ -250,7 +249,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER } } } else if (collectionType == CollectionType.ERC1155) { - for (uint256 j; j < itemIdsLengthForSingleCollection; ) { + for (uint256 j; j < itemIdsLengthForSingleCollection;) { if (amounts[j] == 0) { revert AmountInvalid(); } @@ -281,7 +280,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER revert LengthsInvalid(); } - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { address operator = operators[i]; if (!isOperatorAllowed[operator]) { @@ -313,7 +312,7 @@ contract TransferManager is ITransferManager, LowLevelERC721Transfer, LowLevelER revert LengthsInvalid(); } - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { address operator = operators[i]; if (!hasUserApprovedOperator[msg.sender][operator]) { diff --git a/contracts/src/marketplace/TransferSelectorNFT.sol b/contracts/src/marketplace/TransferSelectorNFT.sol index 5e504203..8b4d201c 100644 --- a/contracts/src/marketplace/TransferSelectorNFT.sol +++ b/contracts/src/marketplace/TransferSelectorNFT.sol @@ -2,15 +2,15 @@ pragma solidity 0.8.17; // Direct dependencies -import { PackableReentrancyGuard } from "@looksrare/contracts-libs/contracts/PackableReentrancyGuard.sol"; -import { ExecutionManager } from "./ExecutionManager.sol"; -import { TransferManager } from "./TransferManager.sol"; +import {PackableReentrancyGuard} from "@looksrare/contracts-libs/contracts/PackableReentrancyGuard.sol"; +import {ExecutionManager} from "./ExecutionManager.sol"; +import {TransferManager} from "./TransferManager.sol"; // Libraries -import { OrderStructs } from "./libraries/OrderStructs.sol"; +import {OrderStructs} from "./libraries/OrderStructs.sol"; // Enums -import { CollectionType } from "./enums/CollectionType.sol"; +import {CollectionType} from "./enums/CollectionType.sol"; /** * @title TransferSelectorNFT @@ -31,11 +31,9 @@ contract TransferSelectorNFT is ExecutionManager, PackableReentrancyGuard { * @param _protocolFeeRecipient Protocol fee recipient address * @param _transferManager Address of the transfer manager for ERC721/ERC1155 */ - constructor( - address _owner, - address _protocolFeeRecipient, - address _transferManager - ) ExecutionManager(_owner, _protocolFeeRecipient) { + constructor(address _owner, address _protocolFeeRecipient, address _transferManager) + ExecutionManager(_owner, _protocolFeeRecipient) + { transferManager = TransferManager(_transferManager); } diff --git a/contracts/src/marketplace/executionStrategies/BaseStrategy.sol b/contracts/src/marketplace/executionStrategies/BaseStrategy.sol index 75ce5f87..9d0bec3c 100644 --- a/contracts/src/marketplace/executionStrategies/BaseStrategy.sol +++ b/contracts/src/marketplace/executionStrategies/BaseStrategy.sol @@ -2,16 +2,16 @@ pragma solidity 0.8.17; // Interfaces -import { IStrategy } from "../interfaces/IStrategy.sol"; +import {IStrategy} from "../interfaces/IStrategy.sol"; // Assembly constants -import { OrderInvalid_error_selector } from "../constants/AssemblyConstants.sol"; +import {OrderInvalid_error_selector} from "../constants/AssemblyConstants.sol"; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; // Enums -import { CollectionType } from "../enums/CollectionType.sol"; +import {CollectionType} from "../enums/CollectionType.sol"; /** * @title BaseStrategy diff --git a/contracts/src/marketplace/executionStrategies/Chainlink/BaseStrategyChainlinkPriceLatency.sol b/contracts/src/marketplace/executionStrategies/Chainlink/BaseStrategyChainlinkPriceLatency.sol index f95a5c12..09cb3dc3 100644 --- a/contracts/src/marketplace/executionStrategies/Chainlink/BaseStrategyChainlinkPriceLatency.sol +++ b/contracts/src/marketplace/executionStrategies/Chainlink/BaseStrategyChainlinkPriceLatency.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { OwnableTwoSteps } from "@looksrare/contracts-libs/contracts/OwnableTwoSteps.sol"; +import {OwnableTwoSteps} from "@looksrare/contracts-libs/contracts/OwnableTwoSteps.sol"; /** * @title BaseStrategyChainlinkPriceLatency diff --git a/contracts/src/marketplace/executionStrategies/Chainlink/StrategyChainlinkUSDDynamicAsk.sol b/contracts/src/marketplace/executionStrategies/Chainlink/StrategyChainlinkUSDDynamicAsk.sol index ad6b9f9d..137c1e86 100644 --- a/contracts/src/marketplace/executionStrategies/Chainlink/StrategyChainlinkUSDDynamicAsk.sol +++ b/contracts/src/marketplace/executionStrategies/Chainlink/StrategyChainlinkUSDDynamicAsk.sol @@ -2,22 +2,28 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../../libraries/OrderStructs.sol"; -import { CurrencyValidator } from "../../libraries/CurrencyValidator.sol"; +import {OrderStructs} from "../../libraries/OrderStructs.sol"; +import {CurrencyValidator} from "../../libraries/CurrencyValidator.sol"; // Interfaces -import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; +import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; // Enums -import { QuoteType } from "../../enums/QuoteType.sol"; +import {QuoteType} from "../../enums/QuoteType.sol"; // Shared errors -import { BidTooLow, OrderInvalid, CurrencyInvalid, FunctionSelectorInvalid, QuoteTypeInvalid } from "../../errors/SharedErrors.sol"; -import { ChainlinkPriceInvalid, PriceFeedNotAvailable, PriceNotRecentEnough } from "../../errors/ChainlinkErrors.sol"; +import { + BidTooLow, + OrderInvalid, + CurrencyInvalid, + FunctionSelectorInvalid, + QuoteTypeInvalid +} from "../../errors/SharedErrors.sol"; +import {ChainlinkPriceInvalid, PriceFeedNotAvailable, PriceNotRecentEnough} from "../../errors/ChainlinkErrors.sol"; // Base strategy contracts -import { BaseStrategy, IStrategy } from "../BaseStrategy.sol"; -import { BaseStrategyChainlinkPriceLatency } from "./BaseStrategyChainlinkPriceLatency.sol"; +import {BaseStrategy, IStrategy} from "../BaseStrategy.sol"; +import {BaseStrategyChainlinkPriceLatency} from "./BaseStrategyChainlinkPriceLatency.sol"; /** * @title StrategyChainlinkUSDDynamicAsk @@ -47,7 +53,7 @@ contract StrategyChainlinkUSDDynamicAsk is BaseStrategy, BaseStrategyChainlinkPr * @param _owner Owner address * @param _priceFeed Address of the ETH/USD price feed */ - constructor(address _owner, address _weth, address _priceFeed) BaseStrategyChainlinkPriceLatency(_owner, 3_600) { + constructor(address _owner, address _weth, address _priceFeed) BaseStrategyChainlinkPriceLatency(_owner, 3600) { WETH = _weth; priceFeed = AggregatorV3Interface(_priceFeed); } @@ -61,10 +67,7 @@ contract StrategyChainlinkUSDDynamicAsk is BaseStrategy, BaseStrategyChainlinkPr * @param makerAsk Maker ask struct (maker ask-specific parameters for the execution) * @dev The client has to provide the seller's desired sale price in USD as the additionalParameters */ - function executeStrategyWithTakerBid( - OrderStructs.Taker calldata takerBid, - OrderStructs.Maker calldata makerAsk - ) + function executeStrategyWithTakerBid(OrderStructs.Taker calldata takerBid, OrderStructs.Maker calldata makerAsk) external view returns (uint256 price, uint256[] memory itemIds, uint256[] memory amounts, bool isNonceInvalidated) @@ -77,7 +80,7 @@ contract StrategyChainlinkUSDDynamicAsk is BaseStrategy, BaseStrategyChainlinkPr CurrencyValidator.allowNativeOrAllowedCurrency(makerAsk.currency, WETH); - (, int256 answer, , uint256 updatedAt, ) = priceFeed.latestRoundData(); + (, int256 answer,, uint256 updatedAt,) = priceFeed.latestRoundData(); if (answer <= 0) { revert ChainlinkPriceInvalid(); @@ -113,10 +116,12 @@ contract StrategyChainlinkUSDDynamicAsk is BaseStrategy, BaseStrategyChainlinkPr /** * @inheritdoc IStrategy */ - function isMakerOrderValid( - OrderStructs.Maker calldata makerAsk, - bytes4 functionSelector - ) external view override returns (bool isValid, bytes4 errorSelector) { + function isMakerOrderValid(OrderStructs.Maker calldata makerAsk, bytes4 functionSelector) + external + view + override + returns (bool isValid, bytes4 errorSelector) + { if (functionSelector != StrategyChainlinkUSDDynamicAsk.executeStrategyWithTakerBid.selector) { return (isValid, FunctionSelectorInvalid.selector); } @@ -131,7 +136,7 @@ contract StrategyChainlinkUSDDynamicAsk is BaseStrategy, BaseStrategyChainlinkPr return (isValid, OrderInvalid.selector); } - for (uint256 i; i < itemIdsLength; ) { + for (uint256 i; i < itemIdsLength;) { _validateAmountNoRevert(makerAsk.amounts[i], makerAsk.collectionType); unchecked { ++i; @@ -144,7 +149,7 @@ contract StrategyChainlinkUSDDynamicAsk is BaseStrategy, BaseStrategyChainlinkPr } } - (, int256 answer, , uint256 updatedAt, ) = priceFeed.latestRoundData(); + (, int256 answer,, uint256 updatedAt,) = priceFeed.latestRoundData(); if (answer <= 0) { return (isValid, ChainlinkPriceInvalid.selector); diff --git a/contracts/src/marketplace/executionStrategies/StrategyCollectionOffer.sol b/contracts/src/marketplace/executionStrategies/StrategyCollectionOffer.sol index 90b3b872..9f0d04bf 100644 --- a/contracts/src/marketplace/executionStrategies/StrategyCollectionOffer.sol +++ b/contracts/src/marketplace/executionStrategies/StrategyCollectionOffer.sol @@ -2,19 +2,19 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; // OpenZeppelin's library for verifying Merkle proofs -import { MerkleProofMemory } from "../libraries/OpenZeppelin/MerkleProofMemory.sol"; +import {MerkleProofMemory} from "../libraries/OpenZeppelin/MerkleProofMemory.sol"; // Enums -import { QuoteType } from "../enums/QuoteType.sol"; +import {QuoteType} from "../enums/QuoteType.sol"; // Shared errors -import { OrderInvalid, FunctionSelectorInvalid, MerkleProofInvalid, QuoteTypeInvalid } from "../errors/SharedErrors.sol"; +import {OrderInvalid, FunctionSelectorInvalid, MerkleProofInvalid, QuoteTypeInvalid} from "../errors/SharedErrors.sol"; // Base strategy contracts -import { BaseStrategy, IStrategy } from "./BaseStrategy.sol"; +import {BaseStrategy, IStrategy} from "./BaseStrategy.sol"; /** * @title StrategyCollectionOffer @@ -83,10 +83,8 @@ contract StrategyCollectionOffer is BaseStrategy { revert OrderInvalid(); } - (uint256 offeredItemId, bytes32[] memory proof) = abi.decode( - takerAsk.additionalParameters, - (uint256, bytes32[]) - ); + (uint256 offeredItemId, bytes32[] memory proof) = + abi.decode(takerAsk.additionalParameters, (uint256, bytes32[])); itemIds = new uint256[](1); itemIds[0] = offeredItemId; isNonceInvalidated = true; @@ -103,13 +101,15 @@ contract StrategyCollectionOffer is BaseStrategy { /** * @inheritdoc IStrategy */ - function isMakerOrderValid( - OrderStructs.Maker calldata makerBid, - bytes4 functionSelector - ) external pure override returns (bool isValid, bytes4 errorSelector) { + function isMakerOrderValid(OrderStructs.Maker calldata makerBid, bytes4 functionSelector) + external + pure + override + returns (bool isValid, bytes4 errorSelector) + { if ( - functionSelector != StrategyCollectionOffer.executeCollectionStrategyWithTakerAskWithProof.selector && - functionSelector != StrategyCollectionOffer.executeCollectionStrategyWithTakerAsk.selector + functionSelector != StrategyCollectionOffer.executeCollectionStrategyWithTakerAskWithProof.selector + && functionSelector != StrategyCollectionOffer.executeCollectionStrategyWithTakerAsk.selector ) { return (isValid, FunctionSelectorInvalid.selector); } @@ -127,8 +127,8 @@ contract StrategyCollectionOffer is BaseStrategy { // If no root is provided or invalid length, it should be invalid. // @dev It does not mean the merkle root is valid against a specific itemId that exists in the collection. if ( - functionSelector == StrategyCollectionOffer.executeCollectionStrategyWithTakerAskWithProof.selector && - makerBid.additionalParameters.length != 32 + functionSelector == StrategyCollectionOffer.executeCollectionStrategyWithTakerAskWithProof.selector + && makerBid.additionalParameters.length != 32 ) { return (isValid, OrderInvalid.selector); } diff --git a/contracts/src/marketplace/executionStrategies/StrategyDutchAuction.sol b/contracts/src/marketplace/executionStrategies/StrategyDutchAuction.sol index 377539c0..3c4fcf27 100644 --- a/contracts/src/marketplace/executionStrategies/StrategyDutchAuction.sol +++ b/contracts/src/marketplace/executionStrategies/StrategyDutchAuction.sol @@ -2,16 +2,16 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; // Enums -import { QuoteType } from "../enums/QuoteType.sol"; +import {QuoteType} from "../enums/QuoteType.sol"; // Shared errors -import { BidTooLow, OrderInvalid, FunctionSelectorInvalid, QuoteTypeInvalid } from "../errors/SharedErrors.sol"; +import {BidTooLow, OrderInvalid, FunctionSelectorInvalid, QuoteTypeInvalid} from "../errors/SharedErrors.sol"; // Base strategy contracts -import { BaseStrategy, IStrategy } from "./BaseStrategy.sol"; +import {BaseStrategy, IStrategy} from "./BaseStrategy.sol"; /** * @title StrategyDutchAuction @@ -27,10 +27,7 @@ contract StrategyDutchAuction is BaseStrategy { * @param makerAsk Maker ask struct (maker bid-specific parameters for the execution) * @dev The client has to provide the seller's desired initial start price as the additionalParameters. */ - function executeStrategyWithTakerBid( - OrderStructs.Taker calldata takerBid, - OrderStructs.Maker calldata makerAsk - ) + function executeStrategyWithTakerBid(OrderStructs.Taker calldata takerBid, OrderStructs.Maker calldata makerAsk) external view returns (uint256 price, uint256[] memory itemIds, uint256[] memory amounts, bool isNonceInvalidated) @@ -50,9 +47,8 @@ contract StrategyDutchAuction is BaseStrategy { uint256 startTime = makerAsk.startTime; uint256 endTime = makerAsk.endTime; - price = - ((endTime - block.timestamp) * startPrice + (block.timestamp - startTime) * makerAsk.price) / - (endTime - startTime); + price = ((endTime - block.timestamp) * startPrice + (block.timestamp - startTime) * makerAsk.price) + / (endTime - startTime); uint256 maxPrice = abi.decode(takerBid.additionalParameters, (uint256)); if (maxPrice < price) { @@ -68,10 +64,12 @@ contract StrategyDutchAuction is BaseStrategy { /** * @inheritdoc IStrategy */ - function isMakerOrderValid( - OrderStructs.Maker calldata makerAsk, - bytes4 functionSelector - ) external pure override returns (bool isValid, bytes4 errorSelector) { + function isMakerOrderValid(OrderStructs.Maker calldata makerAsk, bytes4 functionSelector) + external + pure + override + returns (bool isValid, bytes4 errorSelector) + { if (functionSelector != StrategyDutchAuction.executeStrategyWithTakerBid.selector) { return (isValid, FunctionSelectorInvalid.selector); } @@ -86,7 +84,7 @@ contract StrategyDutchAuction is BaseStrategy { return (isValid, OrderInvalid.selector); } - for (uint256 i; i < itemIdsLength; ) { + for (uint256 i; i < itemIdsLength;) { _validateAmountNoRevert(makerAsk.amounts[i], makerAsk.collectionType); unchecked { ++i; diff --git a/contracts/src/marketplace/executionStrategies/StrategyItemIdsRange.sol b/contracts/src/marketplace/executionStrategies/StrategyItemIdsRange.sol index 81ffd51d..96470011 100644 --- a/contracts/src/marketplace/executionStrategies/StrategyItemIdsRange.sol +++ b/contracts/src/marketplace/executionStrategies/StrategyItemIdsRange.sol @@ -2,16 +2,16 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; // Enums -import { QuoteType } from "../enums/QuoteType.sol"; +import {QuoteType} from "../enums/QuoteType.sol"; // Shared errors -import { OrderInvalid, FunctionSelectorInvalid, QuoteTypeInvalid } from "../errors/SharedErrors.sol"; +import {OrderInvalid, FunctionSelectorInvalid, QuoteTypeInvalid} from "../errors/SharedErrors.sol"; // Base strategy contracts -import { BaseStrategy, IStrategy } from "./BaseStrategy.sol"; +import {BaseStrategy, IStrategy} from "./BaseStrategy.sol"; /** * @title StrategyItemIdsRange @@ -29,10 +29,7 @@ contract StrategyItemIdsRange is BaseStrategy { * @param takerAsk Taker ask struct (taker ask-specific parameters for the execution) * @param makerBid Maker bid struct (maker bid-specific parameters for the execution) */ - function executeStrategyWithTakerAsk( - OrderStructs.Taker calldata takerAsk, - OrderStructs.Maker calldata makerBid - ) + function executeStrategyWithTakerAsk(OrderStructs.Taker calldata takerAsk, OrderStructs.Maker calldata makerBid) external pure returns (uint256 price, uint256[] memory itemIds, uint256[] memory amounts, bool isNonceInvalidated) @@ -43,10 +40,8 @@ contract StrategyItemIdsRange is BaseStrategy { revert OrderInvalid(); } - (uint256 minItemId, uint256 maxItemId, uint256 desiredAmount) = abi.decode( - makerBid.additionalParameters, - (uint256, uint256, uint256) - ); + (uint256 minItemId, uint256 maxItemId, uint256 desiredAmount) = + abi.decode(makerBid.additionalParameters, (uint256, uint256, uint256)); if (minItemId >= maxItemId || desiredAmount == 0) { revert OrderInvalid(); @@ -55,7 +50,7 @@ contract StrategyItemIdsRange is BaseStrategy { uint256 totalOfferedAmount; uint256 lastItemId; - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { uint256 offeredItemId = itemIds[i]; // Force the client to sort the item ids in ascending order, // in order to prevent taker ask from providing duplicated @@ -90,10 +85,12 @@ contract StrategyItemIdsRange is BaseStrategy { /** * @inheritdoc IStrategy */ - function isMakerOrderValid( - OrderStructs.Maker calldata makerBid, - bytes4 functionSelector - ) external pure override returns (bool isValid, bytes4 errorSelector) { + function isMakerOrderValid(OrderStructs.Maker calldata makerBid, bytes4 functionSelector) + external + pure + override + returns (bool isValid, bytes4 errorSelector) + { if (functionSelector != StrategyItemIdsRange.executeStrategyWithTakerAsk.selector) { return (isValid, FunctionSelectorInvalid.selector); } @@ -102,10 +99,8 @@ contract StrategyItemIdsRange is BaseStrategy { return (isValid, QuoteTypeInvalid.selector); } - (uint256 minItemId, uint256 maxItemId, uint256 desiredAmount) = abi.decode( - makerBid.additionalParameters, - (uint256, uint256, uint256) - ); + (uint256 minItemId, uint256 maxItemId, uint256 desiredAmount) = + abi.decode(makerBid.additionalParameters, (uint256, uint256, uint256)); if (minItemId >= maxItemId || desiredAmount == 0) { return (isValid, OrderInvalid.selector); diff --git a/contracts/src/marketplace/helpers/OrderValidatorV2A.sol b/contracts/src/marketplace/helpers/OrderValidatorV2A.sol index 2d917b34..808a8386 100644 --- a/contracts/src/marketplace/helpers/OrderValidatorV2A.sol +++ b/contracts/src/marketplace/helpers/OrderValidatorV2A.sol @@ -2,35 +2,35 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IERC165 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC165.sol"; -import { IERC20 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC20.sol"; -import { IERC721 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC721.sol"; -import { IERC1155 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC1155.sol"; -import { IERC1271 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC1271.sol"; +import {IERC165} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC165.sol"; +import {IERC20} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC20.sol"; +import {IERC721} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC721.sol"; +import {IERC1155} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC1155.sol"; +import {IERC1271} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC1271.sol"; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; -import { MerkleProofCalldataWithNodes } from "../libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; +import {MerkleProofCalldataWithNodes} from "../libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol"; // Interfaces -import { ICreatorFeeManager } from "../interfaces/ICreatorFeeManager.sol"; -import { IStrategy } from "../interfaces/IStrategy.sol"; -import { IRoyaltyFeeRegistry } from "../interfaces/IRoyaltyFeeRegistry.sol"; +import {ICreatorFeeManager} from "../interfaces/ICreatorFeeManager.sol"; +import {IStrategy} from "../interfaces/IStrategy.sol"; +import {IRoyaltyFeeRegistry} from "../interfaces/IRoyaltyFeeRegistry.sol"; // Shared errors -import { OrderInvalid } from "../errors/SharedErrors.sol"; +import {OrderInvalid} from "../errors/SharedErrors.sol"; // Other dependencies -import { LooksRareProtocol } from "../LooksRareProtocol.sol"; -import { TransferManager } from "../TransferManager.sol"; +import {LooksRareProtocol} from "../LooksRareProtocol.sol"; +import {TransferManager} from "../TransferManager.sol"; // Constants import "../constants/ValidationCodeConstants.sol"; -import { MAX_CALLDATA_PROOF_LENGTH, ONE_HUNDRED_PERCENT_IN_BP } from "../constants/NumericConstants.sol"; +import {MAX_CALLDATA_PROOF_LENGTH, ONE_HUNDRED_PERCENT_IN_BP} from "../constants/NumericConstants.sol"; // Enums -import { CollectionType } from "../enums/CollectionType.sol"; -import { QuoteType } from "../enums/QuoteType.sol"; +import {CollectionType} from "../enums/CollectionType.sol"; +import {QuoteType} from "../enums/QuoteType.sol"; /** * @title OrderValidatorV2A @@ -138,7 +138,7 @@ contract OrderValidatorV2A { validationCodes = new uint256[CRITERIA_GROUPS][](length); - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { validationCodes[i] = checkMakerOrderValidity(makerOrders[i], signatures[i], merkleTrees[i]); unchecked { ++i; @@ -160,11 +160,8 @@ contract OrderValidatorV2A { ) public view returns (uint256[9] memory validationCodes) { bytes32 orderHash = makerOrder.hash(); - validationCodes[0] = _checkValidityCurrencyAndStrategy( - makerOrder.quoteType, - makerOrder.currency, - makerOrder.strategyId - ); + validationCodes[0] = + _checkValidityCurrencyAndStrategy(makerOrder.quoteType, makerOrder.currency, makerOrder.strategyId); // It will exit here if the strategy does not exist. // However, if the strategy is implemented but invalid (except if wrong quote type), @@ -181,7 +178,7 @@ contract OrderValidatorV2A { if (makerOrder.quoteType == QuoteType.Ask) { (validationCode1, itemIds, amounts, price) = _checkValidityMakerAskItemIdsAndAmountsAndPrice(makerOrder); } else { - (validationCode1, itemIds, , price) = _checkValidityMakerBidItemIdsAndAmountsAndPrice(makerOrder); + (validationCode1, itemIds,, price) = _checkValidityMakerBidItemIdsAndAmountsAndPrice(makerOrder); } validationCodes[1] = validationCode1; @@ -205,11 +202,7 @@ contract OrderValidatorV2A { validationCodes[5] = _checkValidityMakerBidERC20Assets(makerOrder.currency, makerOrder.signer, price); } else { validationCodes[5] = _checkValidityMakerAskNFTAssets( - makerOrder.collection, - makerOrder.collectionType, - makerOrder.signer, - itemIds, - amounts + makerOrder.collection, makerOrder.collectionType, makerOrder.signer, itemIds, amounts ); } @@ -284,11 +277,11 @@ contract OrderValidatorV2A { * @param strategyId Strategy id * @return validationCode Validation code */ - function _checkValidityCurrencyAndStrategy( - QuoteType quoteType, - address currency, - uint256 strategyId - ) private view returns (uint256 validationCode) { + function _checkValidityCurrencyAndStrategy(QuoteType quoteType, address currency, uint256 strategyId) + private + view + returns (uint256 validationCode) + { // 1. Verify whether the currency is allowed if (!looksRareProtocol.isCurrencyAllowed(currency)) { return CURRENCY_NOT_ALLOWED; @@ -299,8 +292,8 @@ contract OrderValidatorV2A { } // 2. Verify whether the strategy is valid - (bool strategyIsActive, , , , , bool strategyIsMakerBid, address strategyImplementation) = looksRareProtocol - .strategyInfo(strategyId); + (bool strategyIsActive,,,,, bool strategyIsMakerBid, address strategyImplementation) = + looksRareProtocol.strategyInfo(strategyId); if (strategyId != 0 && strategyImplementation == address(0)) { return STRATEGY_NOT_IMPLEMENTED; @@ -308,8 +301,8 @@ contract OrderValidatorV2A { if (strategyId != 0) { if ( - (strategyIsMakerBid && quoteType != QuoteType.Bid) || - (!strategyIsMakerBid && quoteType != QuoteType.Ask) + (strategyIsMakerBid && quoteType != QuoteType.Bid) + || (!strategyIsMakerBid && quoteType != QuoteType.Ask) ) { return STRATEGY_INVALID_QUOTE_TYPE; } @@ -326,10 +319,11 @@ contract OrderValidatorV2A { * @param endTime End time * @return validationCode Validation code */ - function _checkValidityTimestamps( - uint256 startTime, - uint256 endTime - ) private view returns (uint256 validationCode) { + function _checkValidityTimestamps(uint256 startTime, uint256 endTime) + private + view + returns (uint256 validationCode) + { // @dev It is possible for startTime to be equal to endTime. // If so, the execution only succeeds when the startTime = endTime = block.timestamp. // For order invalidation, if the call succeeds, it is already too late for later execution since the @@ -355,13 +349,14 @@ contract OrderValidatorV2A { * (i.e. collections that are tradable but do not implement the proper interfaceId). * If ERC165 is not implemented, it will revert. */ - function _checkIfPotentialInvalidCollectionTypes( - address collection, - CollectionType collectionType - ) private view returns (uint256 validationCode) { + function _checkIfPotentialInvalidCollectionTypes(address collection, CollectionType collectionType) + private + view + returns (uint256 validationCode) + { if (collectionType == CollectionType.ERC721) { - bool isERC721 = IERC165(collection).supportsInterface(ERC721_INTERFACE_ID_1) || - IERC165(collection).supportsInterface(ERC721_INTERFACE_ID_2); + bool isERC721 = IERC165(collection).supportsInterface(ERC721_INTERFACE_ID_1) + || IERC165(collection).supportsInterface(ERC721_INTERFACE_ID_2); if (!isERC721) { return POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC721; @@ -381,11 +376,11 @@ contract OrderValidatorV2A { * @param price Price (defined by the maker order) * @return validationCode Validation code */ - function _checkValidityMakerBidERC20Assets( - address currency, - address user, - uint256 price - ) private view returns (uint256 validationCode) { + function _checkValidityMakerBidERC20Assets(address currency, address user, uint256 price) + private + view + returns (uint256 validationCode) + { if (currency != address(0)) { if (IERC20(currency).balanceOf(user) < price) { return ERC20_BALANCE_INFERIOR_TO_PRICE; @@ -434,18 +429,18 @@ contract OrderValidatorV2A { * @param itemIds Array of item ids * @return validationCode Validation code */ - function _checkValidityERC721AndEquivalents( - address collection, - address user, - uint256[] memory itemIds - ) private view returns (uint256 validationCode) { + function _checkValidityERC721AndEquivalents(address collection, address user, uint256[] memory itemIds) + private + view + returns (uint256 validationCode) + { // 1. Verify itemId is owned by user and catch revertion if ERC721 ownerOf fails uint256 length = itemIds.length; bool success; bytes memory data; - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { (success, data) = collection.staticcall(abi.encodeCall(IERC721.ownerOf, (itemIds[i]))); if (!success) { @@ -462,9 +457,8 @@ contract OrderValidatorV2A { } // 2. Verify if collection is approved by transfer manager - (success, data) = collection.staticcall( - abi.encodeCall(IERC721.isApprovedForAll, (user, address(transferManager))) - ); + (success, data) = + collection.staticcall(abi.encodeCall(IERC721.isApprovedForAll, (user, address(transferManager)))); bool isApprovedAll; if (success) { @@ -472,7 +466,7 @@ contract OrderValidatorV2A { } if (!isApprovedAll) { - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { // 3. If collection is not approved by transfer manager, try to see if it is approved individually (success, data) = collection.staticcall(abi.encodeCall(IERC721.getApproved, (itemIds[i]))); @@ -502,12 +496,11 @@ contract OrderValidatorV2A { * @param amounts Array of amounts * @return validationCode Validation code */ - function _checkValidityERC1155( - address collection, - address user, - uint256[] memory itemIds, - uint256[] memory amounts - ) private view returns (uint256 validationCode) { + function _checkValidityERC1155(address collection, address user, uint256[] memory itemIds, uint256[] memory amounts) + private + view + returns (uint256 validationCode) + { // 1. Verify each itemId is owned by user and catch revertion if ERC1155 ownerOf fails address[] memory users = new address[](1); users[0] = user; @@ -515,13 +508,12 @@ contract OrderValidatorV2A { uint256 length = itemIds.length; // 1.1 Use balanceOfBatch - (bool success, bytes memory data) = collection.staticcall( - abi.encodeCall(IERC1155.balanceOfBatch, (users, itemIds)) - ); + (bool success, bytes memory data) = + collection.staticcall(abi.encodeCall(IERC1155.balanceOfBatch, (users, itemIds))); if (success) { uint256[] memory balances = abi.decode(data, (uint256[])); - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { if (balances[i] < amounts[i]) { return ERC1155_BALANCE_OF_ITEM_ID_INFERIOR_TO_AMOUNT; } @@ -531,7 +523,7 @@ contract OrderValidatorV2A { } } else { // 1.2 If the balanceOfBatch does not work, use loop with balanceOf function - for (uint256 i; i < length; ) { + for (uint256 i; i < length;) { (success, data) = collection.staticcall(abi.encodeCall(IERC1155.balanceOf, (user, itemIds[i]))); if (!success) { @@ -549,9 +541,8 @@ contract OrderValidatorV2A { } // 2. Verify if collection is approved by transfer manager - (success, data) = collection.staticcall( - abi.encodeCall(IERC1155.isApprovedForAll, (user, address(transferManager))) - ); + (success, data) = + collection.staticcall(abi.encodeCall(IERC1155.isApprovedForAll, (user, address(transferManager)))); if (!success) { return ERC1155_IS_APPROVED_FOR_ALL_DOES_NOT_EXIST; @@ -599,11 +590,11 @@ contract OrderValidatorV2A { * @param itemIds Item ids * @return validationCode Validation code */ - function _checkValidityCreatorFee( - address collection, - uint256 price, - uint256[] memory itemIds - ) private view returns (uint256 validationCode) { + function _checkValidityCreatorFee(address collection, uint256 price, uint256[] memory itemIds) + private + view + returns (uint256 validationCode) + { if (address(creatorFeeManager) != address(0)) { (bool status, bytes memory data) = address(creatorFeeManager).staticcall( abi.encodeCall(ICreatorFeeManager.viewCreatorFeeInfo, (collection, price, itemIds)) @@ -631,17 +622,14 @@ contract OrderValidatorV2A { * @param signer Signer address * @return validationCode Validation code */ - function _computeDigestAndVerify( - bytes32 computedHash, - bytes calldata makerSignature, - address signer - ) private view returns (uint256 validationCode) { - return - _validateSignature( - keccak256(abi.encodePacked("\x19\x01", domainSeparator, computedHash)), - makerSignature, - signer - ); + function _computeDigestAndVerify(bytes32 computedHash, bytes calldata makerSignature, address signer) + private + view + returns (uint256 validationCode) + { + return _validateSignature( + keccak256(abi.encodePacked("\x19\x01", domainSeparator, computedHash)), makerSignature, signer + ); } /** @@ -651,11 +639,11 @@ contract OrderValidatorV2A { * @param signer Signer address * @return validationCode Validation code */ - function _validateSignature( - bytes32 hash, - bytes calldata signature, - address signer - ) private view returns (uint256 validationCode) { + function _validateSignature(bytes32 hash, bytes calldata signature, address signer) + private + view + returns (uint256 validationCode) + { // Logic if EOA if (signer.code.length == 0) { bytes32 r; @@ -699,9 +687,8 @@ contract OrderValidatorV2A { } } else { // Logic if ERC1271 - (bool success, bytes memory data) = signer.staticcall( - abi.encodeCall(IERC1271.isValidSignature, (hash, signature)) - ); + (bool success, bytes memory data) = + signer.staticcall(abi.encodeCall(IERC1271.isValidSignature, (hash, signature))); if (!success) { return MISSING_IS_VALID_SIGNATURE_FUNCTION_EIP1271; @@ -728,64 +715,56 @@ contract OrderValidatorV2A { } } - function _checkValidityMakerAskItemIdsAndAmountsAndPrice( - OrderStructs.Maker memory makerAsk - ) private view returns (uint256 validationCode, uint256[] memory itemIds, uint256[] memory amounts, uint256 price) { + function _checkValidityMakerAskItemIdsAndAmountsAndPrice(OrderStructs.Maker memory makerAsk) + private + view + returns (uint256 validationCode, uint256[] memory itemIds, uint256[] memory amounts, uint256 price) + { if (makerAsk.strategyId == 0) { itemIds = makerAsk.itemIds; amounts = makerAsk.amounts; price = makerAsk.price; - validationCode = _getOrderValidationCodeForStandardStrategy( - makerAsk.collectionType, - itemIds.length, - amounts - ); + validationCode = + _getOrderValidationCodeForStandardStrategy(makerAsk.collectionType, itemIds.length, amounts); } else { itemIds = makerAsk.itemIds; amounts = makerAsk.amounts; // @dev It should ideally be adjusted by real price price = makerAsk.price; - (, , , , bytes4 strategySelector, , address strategyImplementation) = looksRareProtocol.strategyInfo( - makerAsk.strategyId - ); + (,,,, bytes4 strategySelector,, address strategyImplementation) = + looksRareProtocol.strategyInfo(makerAsk.strategyId); - (bool isValid, bytes4 errorSelector) = IStrategy(strategyImplementation).isMakerOrderValid( - makerAsk, - strategySelector - ); + (bool isValid, bytes4 errorSelector) = + IStrategy(strategyImplementation).isMakerOrderValid(makerAsk, strategySelector); validationCode = _getOrderValidationCodeForNonStandardStrategies(isValid, errorSelector); } } - function _checkValidityMakerBidItemIdsAndAmountsAndPrice( - OrderStructs.Maker memory makerBid - ) private view returns (uint256 validationCode, uint256[] memory itemIds, uint256[] memory amounts, uint256 price) { + function _checkValidityMakerBidItemIdsAndAmountsAndPrice(OrderStructs.Maker memory makerBid) + private + view + returns (uint256 validationCode, uint256[] memory itemIds, uint256[] memory amounts, uint256 price) + { if (makerBid.strategyId == 0) { itemIds = makerBid.itemIds; amounts = makerBid.amounts; price = makerBid.price; - validationCode = _getOrderValidationCodeForStandardStrategy( - makerBid.collectionType, - itemIds.length, - amounts - ); + validationCode = + _getOrderValidationCodeForStandardStrategy(makerBid.collectionType, itemIds.length, amounts); } else { // @dev It should ideally be adjusted by real price // amounts and itemIds are not used since most non-native maker bids won't target a single item price = makerBid.price; - (, , , , bytes4 strategySelector, , address strategyImplementation) = looksRareProtocol.strategyInfo( - makerBid.strategyId - ); + (,,,, bytes4 strategySelector,, address strategyImplementation) = + looksRareProtocol.strategyInfo(makerBid.strategyId); - (bool isValid, bytes4 errorSelector) = IStrategy(strategyImplementation).isMakerOrderValid( - makerBid, - strategySelector - ); + (bool isValid, bytes4 errorSelector) = + IStrategy(strategyImplementation).isMakerOrderValid(makerBid, strategySelector); validationCode = _getOrderValidationCodeForNonStandardStrategies(isValid, errorSelector); } @@ -804,8 +783,8 @@ contract OrderValidatorV2A { // Only check if length of array is greater than 1 if (length > 1) { - for (uint256 i = 0; i < length - 1; ) { - for (uint256 j = i + 1; j < length; ) { + for (uint256 i = 0; i < length - 1;) { + for (uint256 j = i + 1; j < length;) { if (itemIds[i] == itemIds[j]) { return SAME_ITEM_ID_IN_BUNDLE; } @@ -830,7 +809,7 @@ contract OrderValidatorV2A { if (expectedLength == 0 || (amounts.length != expectedLength)) { validationCode = MAKER_ORDER_INVALID_STANDARD_SALE; } else { - for (uint256 i; i < expectedLength; ) { + for (uint256 i; i < expectedLength;) { uint256 amount = amounts[i]; if (amount == 0) { @@ -848,10 +827,11 @@ contract OrderValidatorV2A { } } - function _getOrderValidationCodeForNonStandardStrategies( - bool isValid, - bytes4 errorSelector - ) private pure returns (uint256 validationCode) { + function _getOrderValidationCodeForNonStandardStrategies(bool isValid, bytes4 errorSelector) + private + pure + returns (uint256 validationCode) + { if (isValid) { validationCode = ORDER_EXPECTED_TO_BE_VALID; } else { diff --git a/contracts/src/marketplace/helpers/ProtocolHelpers.sol b/contracts/src/marketplace/helpers/ProtocolHelpers.sol index 01162985..99c37c0d 100644 --- a/contracts/src/marketplace/helpers/ProtocolHelpers.sol +++ b/contracts/src/marketplace/helpers/ProtocolHelpers.sol @@ -2,13 +2,13 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { SignatureCheckerCalldata } from "@looksrare/contracts-libs/contracts/SignatureCheckerCalldata.sol"; +import {SignatureCheckerCalldata} from "@looksrare/contracts-libs/contracts/SignatureCheckerCalldata.sol"; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; // Other dependencies -import { LooksRareProtocol } from "../LooksRareProtocol.sol"; +import {LooksRareProtocol} from "../LooksRareProtocol.sol"; /** * @title ProtocolHelpers @@ -60,11 +60,11 @@ contract ProtocolHelpers { * @param signer Signer address * @dev It returns true only if the SignatureCheckerCalldata does not revert before. */ - function verifyMakerSignature( - OrderStructs.Maker memory maker, - bytes calldata makerSignature, - address signer - ) public view returns (bool) { + function verifyMakerSignature(OrderStructs.Maker memory maker, bytes calldata makerSignature, address signer) + public + view + returns (bool) + { bytes32 digest = computeMakerDigest(maker); SignatureCheckerCalldata.verify(digest, signer, makerSignature); return true; @@ -77,11 +77,11 @@ contract ProtocolHelpers { * @param signer Signer address * @dev It returns true only if the SignatureCheckerCalldata does not revert before. */ - function verifyMerkleTree( - OrderStructs.MerkleTree memory merkleTree, - bytes calldata makerSignature, - address signer - ) public view returns (bool) { + function verifyMerkleTree(OrderStructs.MerkleTree memory merkleTree, bytes calldata makerSignature, address signer) + public + view + returns (bool) + { bytes32 digest = computeDigestMerkleTree(merkleTree); SignatureCheckerCalldata.verify(digest, signer, makerSignature); return true; diff --git a/contracts/src/marketplace/interfaces/ICreatorFeeManager.sol b/contracts/src/marketplace/interfaces/ICreatorFeeManager.sol index d469ff27..6b6728e7 100644 --- a/contracts/src/marketplace/interfaces/ICreatorFeeManager.sol +++ b/contracts/src/marketplace/interfaces/ICreatorFeeManager.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.17; // Interfaces -import { IRoyaltyFeeRegistry } from "./IRoyaltyFeeRegistry.sol"; +import {IRoyaltyFeeRegistry} from "./IRoyaltyFeeRegistry.sol"; /** * @title ICreatorFeeManager @@ -28,9 +28,8 @@ interface ICreatorFeeManager { * @return creator Creator address * @return creatorFeeAmount Creator fee amount */ - function viewCreatorFeeInfo( - address collection, - uint256 price, - uint256[] memory itemIds - ) external view returns (address creator, uint256 creatorFeeAmount); + function viewCreatorFeeInfo(address collection, uint256 price, uint256[] memory itemIds) + external + view + returns (address creator, uint256 creatorFeeAmount); } diff --git a/contracts/src/marketplace/interfaces/IImmutableCreate2Factory.sol b/contracts/src/marketplace/interfaces/IImmutableCreate2Factory.sol index 9071ab43..efbecb66 100644 --- a/contracts/src/marketplace/interfaces/IImmutableCreate2Factory.sol +++ b/contracts/src/marketplace/interfaces/IImmutableCreate2Factory.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.17; interface IImmutableCreate2Factory { - function safeCreate2( - bytes32 salt, - bytes calldata initializationCode - ) external payable returns (address deploymentAddress); + function safeCreate2(bytes32 salt, bytes calldata initializationCode) + external + payable + returns (address deploymentAddress); } diff --git a/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol b/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol index 09722537..e2a52119 100644 --- a/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol +++ b/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; /** * @title ILooksRareProtocol @@ -22,14 +22,6 @@ interface ILooksRareProtocol { bool isNonceInvalidated; } - /** - * @notice It is emitted when there is an affiliate fee paid. - * @param affiliate Affiliate address - * @param currency Address of the currency - * @param affiliateFee Affiliate fee (in the currency) - */ - event AffiliatePayment(address affiliate, address currency, uint256 affiliateFee); - /** * @notice It is emitted if there is a change in the domain separator. */ @@ -60,8 +52,8 @@ interface ILooksRareProtocol { * feeAmounts[2] Protocol fee amount prior to adjustment for a potential affiliate payment */ // maker (receives the NFT) + // taker (initiates the transaction) event TakerAsk( - // taker (initiates the transaction) NonceInvalidationParameters nonceInvalidationParameters, address askUser, address bidUser, @@ -93,8 +85,8 @@ interface ILooksRareProtocol { * feeAmounts[2] Protocol fee amount prior to adjustment for a potential affiliate payment */ // taker (receives the NFT) + // taker (initiates the transaction) event TakerBid( - // taker (initiates the transaction) NonceInvalidationParameters nonceInvalidationParameters, address bidUser, address bidRecipient, @@ -133,14 +125,12 @@ interface ILooksRareProtocol { * @param makerBid Maker bid struct * @param makerSignature Maker signature * @param merkleTree Merkle tree struct (if the signature contains multiple maker orders) - * @param affiliate Affiliate address */ function executeTakerAsk( OrderStructs.Taker calldata takerAsk, OrderStructs.Maker calldata makerBid, bytes calldata makerSignature, - OrderStructs.MerkleTree calldata merkleTree, - address affiliate + OrderStructs.MerkleTree calldata merkleTree ) external; /** @@ -149,14 +139,12 @@ interface ILooksRareProtocol { * @param makerAsk Maker ask struct * @param makerSignature Maker signature * @param merkleTree Merkle tree struct (if the signature contains multiple maker orders) - * @param affiliate Affiliate address */ function executeTakerBid( OrderStructs.Taker calldata takerBid, OrderStructs.Maker calldata makerAsk, bytes calldata makerSignature, - OrderStructs.MerkleTree calldata merkleTree, - address affiliate + OrderStructs.MerkleTree calldata merkleTree ) external payable; /** @@ -165,7 +153,6 @@ interface ILooksRareProtocol { * @param makerAsks Array of maker ask structs * @param makerSignatures Array of maker signatures * @param merkleTrees Array of merkle tree structs if the signature contains multiple maker orders - * @param affiliate Affiliate address * @param isAtomic Whether the execution should be atomic * i.e. whether it should revert if 1 or more transactions fail */ @@ -174,7 +161,6 @@ interface ILooksRareProtocol { OrderStructs.Maker[] calldata makerAsks, bytes[] calldata makerSignatures, OrderStructs.MerkleTree[] calldata merkleTrees, - address affiliate, bool isAtomic ) external payable; } diff --git a/contracts/src/marketplace/interfaces/IRoyaltyFeeRegistry.sol b/contracts/src/marketplace/interfaces/IRoyaltyFeeRegistry.sol index a76c84cb..766d4603 100644 --- a/contracts/src/marketplace/interfaces/IRoyaltyFeeRegistry.sol +++ b/contracts/src/marketplace/interfaces/IRoyaltyFeeRegistry.sol @@ -13,8 +13,8 @@ interface IRoyaltyFeeRegistry { * @return receiver Receiver address * @return royaltyFee Royalty fee amount */ - function royaltyInfo( - address collection, - uint256 price - ) external view returns (address receiver, uint256 royaltyFee); + function royaltyInfo(address collection, uint256 price) + external + view + returns (address receiver, uint256 royaltyFee); } diff --git a/contracts/src/marketplace/interfaces/IStrategy.sol b/contracts/src/marketplace/interfaces/IStrategy.sol index 39585c5f..a9b7e450 100644 --- a/contracts/src/marketplace/interfaces/IStrategy.sol +++ b/contracts/src/marketplace/interfaces/IStrategy.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; /** * @title IStrategy @@ -17,10 +17,10 @@ interface IStrategy { * @return isValid Whether the maker struct is valid * @return errorSelector If isValid is false, it returns the error's 4 bytes selector */ - function isMakerOrderValid( - OrderStructs.Maker calldata makerOrder, - bytes4 functionSelector - ) external view returns (bool isValid, bytes4 errorSelector); + function isMakerOrderValid(OrderStructs.Maker calldata makerOrder, bytes4 functionSelector) + external + view + returns (bool isValid, bytes4 errorSelector); /** * @notice This function acts as a safety check for the protocol's owner when adding new execution strategies. diff --git a/contracts/src/marketplace/interfaces/ITransferManager.sol b/contracts/src/marketplace/interfaces/ITransferManager.sol index 56f70e19..8f19f9a4 100644 --- a/contracts/src/marketplace/interfaces/ITransferManager.sol +++ b/contracts/src/marketplace/interfaces/ITransferManager.sol @@ -2,10 +2,10 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../libraries/OrderStructs.sol"; +import {OrderStructs} from "../libraries/OrderStructs.sol"; // Enums -import { CollectionType } from "../enums/CollectionType.sol"; +import {CollectionType} from "../enums/CollectionType.sol"; /** * @title ITransferManager diff --git a/contracts/src/marketplace/libraries/CurrencyValidator.sol b/contracts/src/marketplace/libraries/CurrencyValidator.sol index d7523744..61208646 100644 --- a/contracts/src/marketplace/libraries/CurrencyValidator.sol +++ b/contracts/src/marketplace/libraries/CurrencyValidator.sol @@ -2,7 +2,11 @@ pragma solidity 0.8.17; // Assembly -import { CurrencyInvalid_error_selector, CurrencyInvalid_error_length, Error_selector_offset } from "../constants/AssemblyConstants.sol"; +import { + CurrencyInvalid_error_selector, + CurrencyInvalid_error_length, + Error_selector_offset +} from "../constants/AssemblyConstants.sol"; /** * @title CurrencyValidator diff --git a/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol b/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol index d3d04cfe..f3af4e8b 100644 --- a/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol +++ b/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofCalldataWithNodes.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "../../libraries/OrderStructs.sol"; +import {OrderStructs} from "../../libraries/OrderStructs.sol"; /** * @title MerkleProofCalldataWithNodes @@ -16,11 +16,11 @@ library MerkleProofCalldataWithNodes { * For this, a `proof` must be provided, containing sibling hashes on the branch from the leaf to the * root of the tree. Each pair of leaves and each pair of pre-images are assumed to be sorted. */ - function verifyCalldata( - OrderStructs.MerkleTreeNode[] calldata proof, - bytes32 root, - bytes32 leaf - ) internal pure returns (bool) { + function verifyCalldata(OrderStructs.MerkleTreeNode[] calldata proof, bytes32 root, bytes32 leaf) + internal + pure + returns (bool) + { return processProofCalldata(proof, leaf) == root; } @@ -29,14 +29,15 @@ library MerkleProofCalldataWithNodes { * A `proof` is valid if and only if the rebuilt hash matches the root of the tree. * When processing the proof, the pairs of leafs & pre-images are assumed to be sorted. */ - function processProofCalldata( - OrderStructs.MerkleTreeNode[] calldata proof, - bytes32 leaf - ) internal pure returns (bytes32) { + function processProofCalldata(OrderStructs.MerkleTreeNode[] calldata proof, bytes32 leaf) + internal + pure + returns (bytes32) + { bytes32 computedHash = leaf; uint256 length = proof.length; - for (uint256 i = 0; i < length; ) { + for (uint256 i = 0; i < length;) { if (proof[i].position == OrderStructs.MerkleTreeNodePosition.Left) { computedHash = _efficientHash(proof[i].value, computedHash); } else { diff --git a/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofMemory.sol b/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofMemory.sol index 1e00db5a..02ab8737 100644 --- a/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofMemory.sol +++ b/contracts/src/marketplace/libraries/OpenZeppelin/MerkleProofMemory.sol @@ -27,7 +27,7 @@ library MerkleProofMemory { bytes32 computedHash = leaf; uint256 length = proof.length; - for (uint256 i = 0; i < length; ) { + for (uint256 i = 0; i < length;) { computedHash = _hashPair(computedHash, proof[i]); unchecked { ++i; diff --git a/contracts/src/marketplace/libraries/OrderStructs.sol b/contracts/src/marketplace/libraries/OrderStructs.sol index e7600695..19b3a88d 100644 --- a/contracts/src/marketplace/libraries/OrderStructs.sol +++ b/contracts/src/marketplace/libraries/OrderStructs.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.17; // Enums -import { CollectionType } from "../enums/CollectionType.sol"; -import { QuoteType } from "../enums/QuoteType.sol"; +import {CollectionType} from "../enums/CollectionType.sol"; +import {QuoteType} from "../enums/QuoteType.sol"; /** * @title OrderStructs @@ -106,26 +106,12 @@ library OrderStructs { /** * @notice This is the type hash constant used to compute the maker order hash. */ - bytes32 internal constant _MAKER_TYPEHASH = - keccak256( - "Maker(" - "uint8 quoteType," - "uint256 globalNonce," - "uint256 subsetNonce," - "uint256 orderNonce," - "uint256 strategyId," - "uint8 collectionType," - "address collection," - "address currency," - "address signer," - "uint256 startTime," - "uint256 endTime," - "uint256 price," - "uint256[] itemIds," - "uint256[] amounts," - "bytes additionalParameters" - ")" - ); + bytes32 internal constant _MAKER_TYPEHASH = keccak256( + "Maker(" "uint8 quoteType," "uint256 globalNonce," "uint256 subsetNonce," "uint256 orderNonce," + "uint256 strategyId," "uint8 collectionType," "address collection," "address currency," "address signer," + "uint256 startTime," "uint256 endTime," "uint256 price," "uint256[] itemIds," "uint256[] amounts," + "bytes additionalParameters" ")" + ); /** * 5. Hash functions @@ -138,30 +124,29 @@ library OrderStructs { */ function hash(Maker memory maker) internal pure returns (bytes32) { // Encoding is done into two parts to avoid stack too deep issues - return - keccak256( - bytes.concat( - abi.encode( - _MAKER_TYPEHASH, - maker.quoteType, - maker.globalNonce, - maker.subsetNonce, - maker.orderNonce, - maker.strategyId, - maker.collectionType, - maker.collection, - maker.currency - ), - abi.encode( - maker.signer, - maker.startTime, - maker.endTime, - maker.price, - keccak256(abi.encodePacked(maker.itemIds)), - keccak256(abi.encodePacked(maker.amounts)), - keccak256(maker.additionalParameters) - ) + return keccak256( + bytes.concat( + abi.encode( + _MAKER_TYPEHASH, + maker.quoteType, + maker.globalNonce, + maker.subsetNonce, + maker.orderNonce, + maker.strategyId, + maker.collectionType, + maker.collection, + maker.currency + ), + abi.encode( + maker.signer, + maker.startTime, + maker.endTime, + maker.price, + keccak256(abi.encodePacked(maker.itemIds)), + keccak256(abi.encodePacked(maker.amounts)), + keccak256(maker.additionalParameters) ) - ); + ) + ); } } diff --git a/contracts/src/protocol/AllowlistMinter.sol b/contracts/src/protocol/AllowlistMinter.sol index 576b45ee..599831cb 100644 --- a/contracts/src/protocol/AllowlistMinter.sol +++ b/contracts/src/protocol/AllowlistMinter.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.16; -import { MerkleProofUpgradeable } from "oz-upgradeable/utils/cryptography/MerkleProofUpgradeable.sol"; -import { IAllowlist } from "./interfaces/IAllowlist.sol"; +import {MerkleProofUpgradeable} from "oz-upgradeable/utils/cryptography/MerkleProofUpgradeable.sol"; +import {IAllowlist} from "./interfaces/IAllowlist.sol"; -import { Errors } from "./libs/Errors.sol"; +import {Errors} from "./libs/Errors.sol"; /// @title Interface for hypercert token interactions /// @author bitbeckers @@ -19,11 +19,11 @@ contract AllowlistMinter is IAllowlist { mapping(uint256 => uint256) internal maxUnits; mapping(uint256 => uint256) internal minted; - function isAllowedToClaim( - bytes32[] calldata proof, - uint256 claimID, - bytes32 leaf - ) external view returns (bool isAllowed) { + function isAllowedToClaim(bytes32[] calldata proof, uint256 claimID, bytes32 leaf) + external + view + returns (bool isAllowed) + { if (merkleRoots[claimID].length == 0) revert Errors.DoesNotExist(); isAllowed = MerkleProofUpgradeable.verifyCalldata(proof, merkleRoots[claimID], leaf); } @@ -44,8 +44,8 @@ contract AllowlistMinter is IAllowlist { if (hasBeenClaimed[claimID][leaf]) revert Errors.AlreadyClaimed(); if ( - !MerkleProofUpgradeable.verifyCalldata(proof, merkleRoots[claimID], leaf) || - (minted[claimID] + amount) > maxUnits[claimID] + !MerkleProofUpgradeable.verifyCalldata(proof, merkleRoots[claimID], leaf) + || (minted[claimID] + amount) > maxUnits[claimID] ) revert Errors.Invalid(); hasBeenClaimed[claimID][leaf] = true; diff --git a/contracts/src/protocol/HypercertMinter.sol b/contracts/src/protocol/HypercertMinter.sol index 4a2e274d..cf387a86 100644 --- a/contracts/src/protocol/HypercertMinter.sol +++ b/contracts/src/protocol/HypercertMinter.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.16; -import { IHypercertToken } from "./interfaces/IHypercertToken.sol"; -import { SemiFungible1155 } from "./SemiFungible1155.sol"; -import { AllowlistMinter } from "./AllowlistMinter.sol"; -import { PausableUpgradeable } from "oz-upgradeable/security/PausableUpgradeable.sol"; +import {IHypercertToken} from "./interfaces/IHypercertToken.sol"; +import {SemiFungible1155} from "./SemiFungible1155.sol"; +import {AllowlistMinter} from "./AllowlistMinter.sol"; +import {PausableUpgradeable} from "oz-upgradeable/security/PausableUpgradeable.sol"; -import { Errors } from "./libs/Errors.sol"; +import {Errors} from "./libs/Errors.sol"; /// @title Contract for managing hypercert claims and whitelists /// @author bitbeckers @@ -37,12 +37,11 @@ contract HypercertMinter is IHypercertToken, SemiFungible1155, AllowlistMinter, /// @notice Mint a semi-fungible token for the impact claim referenced via `uri` /// @dev see {IHypercertToken} - function mintClaim( - address account, - uint256 units, - string memory _uri, - TransferRestrictions restrictions - ) external override whenNotPaused { + function mintClaim(address account, uint256 units, string memory _uri, TransferRestrictions restrictions) + external + override + whenNotPaused + { // This enables us to release this restriction in the future if (msg.sender != account) revert Errors.NotAllowed(); uint256 claimID = _mintNewTypeWithToken(account, units, _uri); @@ -72,12 +71,10 @@ contract HypercertMinter is IHypercertToken, SemiFungible1155, AllowlistMinter, /// @notice Mint a semi-fungible token representing a fraction of the claim /// @dev Calls AllowlistMinter to verify `proof`. /// @dev Mints the `amount` of units for the hypercert stored under `claimID` - function mintClaimFromAllowlist( - address account, - bytes32[] calldata proof, - uint256 claimID, - uint256 units - ) external whenNotPaused { + function mintClaimFromAllowlist(address account, bytes32[] calldata proof, uint256 claimID, uint256 units) + external + whenNotPaused + { _processClaim(proof, claimID, units); _mintToken(account, claimID, units); } @@ -92,7 +89,7 @@ contract HypercertMinter is IHypercertToken, SemiFungible1155, AllowlistMinter, uint256[] calldata units ) external whenNotPaused { uint256 len = claimIDs.length; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { _processClaim(proofs[i], claimIDs[i], units[i]); unchecked { ++i; @@ -119,11 +116,10 @@ contract HypercertMinter is IHypercertToken, SemiFungible1155, AllowlistMinter, /// @notice Split a claimtokens value into parts with summed value equal to the original /// @dev see {IHypercertToken} - function splitFraction( - address _account, - uint256 _tokenID, - uint256[] calldata _newFractions - ) external whenNotPaused { + function splitFraction(address _account, uint256 _tokenID, uint256[] calldata _newFractions) + external + whenNotPaused + { _splitTokenUnits(_account, _tokenID, _newFractions); } @@ -147,13 +143,17 @@ contract HypercertMinter is IHypercertToken, SemiFungible1155, AllowlistMinter, /// @notice Burn a claimtoken; override is needed to update units/values /// @dev see {ERC1155Burnable} - function burn(address account, uint256 id, uint256 value) public override whenNotPaused { + function burn(address account, uint256 id, uint256 /*value*/ ) public override whenNotPaused { _burnToken(account, id); } /// @notice Batch burn claimtokens; override is needed to update units/values /// @dev see {ERC1155Burnable} - function burnBatch(address account, uint256[] memory ids, uint256[] memory values) public override whenNotPaused { + function burnBatch(address account, uint256[] memory ids, uint256[] memory /*values*/ ) + public + override + whenNotPaused + { _batchBurnToken(account, ids); } @@ -180,7 +180,12 @@ contract HypercertMinter is IHypercertToken, SemiFungible1155, AllowlistMinter, /// METADATA /// @dev see { IHypercertMetadata} - function uri(uint256 tokenID) public view override(IHypercertToken, SemiFungible1155) returns (string memory _uri) { + function uri(uint256 tokenID) + public + view + override(IHypercertToken, SemiFungible1155) + returns (string memory _uri) + { _uri = SemiFungible1155.uri(tokenID); } @@ -222,7 +227,7 @@ contract HypercertMinter is IHypercertToken, SemiFungible1155, AllowlistMinter, // Transfer case, where to and from are non-zero uint256 len = ids.length; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { uint256 typeID = getBaseType(ids[i]); TransferRestrictions policy = typeRestrictions[typeID]; if (policy == TransferRestrictions.DisallowAll) { diff --git a/contracts/src/protocol/SemiFungible1155.sol b/contracts/src/protocol/SemiFungible1155.sol index fba07983..fb409bbe 100644 --- a/contracts/src/protocol/SemiFungible1155.sol +++ b/contracts/src/protocol/SemiFungible1155.sol @@ -3,13 +3,13 @@ // https://github.com/enjin/erc-1155/blob/master/contracts/ERC1155MixedFungibleMintable.sol pragma solidity 0.8.16; -import { ERC1155Upgradeable } from "oz-upgradeable/token/ERC1155/ERC1155Upgradeable.sol"; -import { ERC1155BurnableUpgradeable } from "oz-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol"; -import { ERC1155URIStorageUpgradeable } from "oz-upgradeable/token/ERC1155/extensions/ERC1155URIStorageUpgradeable.sol"; -import { OwnableUpgradeable } from "oz-upgradeable/access/OwnableUpgradeable.sol"; -import { Initializable } from "oz-upgradeable/proxy/utils/Initializable.sol"; -import { UUPSUpgradeable } from "oz-upgradeable/proxy/utils/UUPSUpgradeable.sol"; -import { Errors } from "./libs/Errors.sol"; +import {ERC1155Upgradeable} from "oz-upgradeable/token/ERC1155/ERC1155Upgradeable.sol"; +import {ERC1155BurnableUpgradeable} from "oz-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol"; +import {ERC1155URIStorageUpgradeable} from "oz-upgradeable/token/ERC1155/extensions/ERC1155URIStorageUpgradeable.sol"; +import {OwnableUpgradeable} from "oz-upgradeable/access/OwnableUpgradeable.sol"; +import {Initializable} from "oz-upgradeable/proxy/utils/Initializable.sol"; +import {UUPSUpgradeable} from "oz-upgradeable/proxy/utils/UUPSUpgradeable.sol"; +import {Errors} from "./libs/Errors.sol"; /// @title Contract for minting semi-fungible EIP1155 tokens /// @author bitbeckers @@ -163,17 +163,18 @@ contract SemiFungible1155 is * @param _units The number of units associated with the new token. * @param _uri The URI for the metadata associated with the new token. * @return typeID The new token type ID. - * @dev This function creates a new token type ID by calling the `_createTokenType` function and then mints a new token with the new type ID. + * @dev This function creates a new token type ID by calling the `_createTokenType` function and then mints a new + * token with the new type ID. * @dev The `tokenID` is calculated by adding the `typeID` to the current maximum index for the `typeID`. * @dev The `tokenValues` mapping is updated with the number of units associated with the new token. - * @dev A `ValueTransfer` event is emitted to indicate that a new token has been minted and assigned to the specified account. + * @dev A `ValueTransfer` event is emitted to indicate that a new token has been minted and assigned to the + * specified account. * @dev If `_units` is zero, the function will revert with an error. */ - function _mintNewTypeWithToken( - address _account, - uint256 _units, - string memory _uri - ) internal returns (uint256 typeID) { + function _mintNewTypeWithToken(address _account, uint256 _units, string memory _uri) + internal + returns (uint256 typeID) + { if (_units == 0) { revert Errors.NotAllowed(); } @@ -193,18 +194,20 @@ contract SemiFungible1155 is * @param _fractions An array of values associated with the new token. * @param _uri The URI for the metadata associated with the new token. * @return typeID The new token type ID. - * @dev This function creates a new token type ID by calling the `_createTokenType` function and then mints a new token with the new type ID. + * @dev This function creates a new token type ID by calling the `_createTokenType` function and then mints a new + * token with the new type ID. * @dev The `tokenID` is calculated by adding the `typeID` to the current maximum index for the `typeID`. * @dev The `tokenValues` mapping is updated with the number of units associated with the new token. - * @dev A `ValueTransfer` event is emitted to indicate that a new token has been minted and assigned to the specified account. + * @dev A `ValueTransfer` event is emitted to indicate that a new token has been minted and assigned to the + * specified account. * @dev If any of the fractional values in `_fractions` are zero, the function will revert with an error. - * @dev This function also calls the `_splitTokenUnits` function to split the new token into multiple sub-tokens with the specified fractional values. + * @dev This function also calls the `_splitTokenUnits` function to split the new token into multiple sub-tokens + * with the specified fractional values. */ - function _mintNewTypeWithTokens( - address _account, - uint256[] calldata _fractions, - string memory _uri - ) internal returns (uint256 typeID) { + function _mintNewTypeWithTokens(address _account, uint256[] calldata _fractions, string memory _uri) + internal + returns (uint256 typeID) + { typeID = _mintNewTypeWithToken(_account, _getSum(_fractions), _uri); _splitTokenUnits(_account, typeID + maxIndex[typeID], _fractions); } @@ -215,10 +218,13 @@ contract SemiFungible1155 is * @param _typeID The ID of the token type to mint. * @param _units The number of units associated with the new token. * @return tokenID The ID of the newly minted token. - * @dev This function checks that the specified token type ID is a base type and that the maximum number of tokens for the token type has not been reached. - * @dev The function then calculates the new token ID by adding the specified token type ID to the current maximum index for the token type. + * @dev This function checks that the specified token type ID is a base type and that the maximum number of tokens + * for the token type has not been reached. + * @dev The function then calculates the new token ID by adding the specified token type ID to the current maximum + * index for the token type. * @dev The `tokenValues` mapping is updated with the number of units associated with the new token. - * @dev A `ValueTransfer` event is emitted to indicate that a new token has been minted and assigned to the specified account. + * @dev A `ValueTransfer` event is emitted to indicate that a new token has been minted and assigned to the + * specified account. */ function _mintToken(address _account, uint256 _typeID, uint256 _units) internal returns (uint256 tokenID) { if (!isBaseType(_typeID)) revert Errors.NotAllowed(); @@ -241,23 +247,25 @@ contract SemiFungible1155 is * @param _typeIDs An array of token type IDs to mint. * @param _units An array of numbers of units associated with the new tokens. * @return tokenIDs An array of the IDs of the newly minted tokens. - * @dev This function checks that each specified token type ID is a base type and that the maximum number of tokens for each token type has not been reached. - * @dev The function then calculates the new token IDs by adding the specified token type IDs to the current maximum index for each token type. + * @dev This function checks that each specified token type ID is a base type and that the maximum number of tokens + * for each token type has not been reached. + * @dev The function then calculates the new token IDs by adding the specified token type IDs to the current maximum + * index for each token type. * @dev The `tokenValues` mapping is updated with the number of units associated with each new token. - * @dev A `BatchValueTransfer` event is emitted to indicate that new tokens have been minted and assigned to the specified account. + * @dev A `BatchValueTransfer` event is emitted to indicate that new tokens have been minted and assigned to the + * specified account. */ - function _batchMintTokens( - address _account, - uint256[] calldata _typeIDs, - uint256[] calldata _units - ) internal returns (uint256[] memory tokenIDs) { + function _batchMintTokens(address _account, uint256[] calldata _typeIDs, uint256[] calldata _units) + internal + returns (uint256[] memory tokenIDs) + { uint256 len = _typeIDs.length; tokenIDs = new uint256[](len); uint256[] memory amounts = new uint256[](len); uint256[] memory zeroes = new uint256[](len); - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { uint256 _typeID = _typeIDs[i]; if (!isBaseType(_typeID)) revert Errors.NotAllowed(); _notMaxItem(maxIndex[_typeID]); @@ -282,9 +290,12 @@ contract SemiFungible1155 is * @param _values An array of numbers of units associated with the new tokens. * @dev This function splits a token into multiple tokens with different unit values. * @dev The `_values` array specifies the number of units associated with each new token. - * @dev The function checks that the length of the `_values` array is between 2 and `FRACTION_LIMIT`, and that the sum of the values in the `_values` array is equal to the number of units associated with the original token. - * @dev The function then creates new tokens with the specified unit values and assigns them to the specified account. - * @dev A `BatchValueTransfer` event is emitted to indicate that the original token has been split into multiple tokens. + * @dev The function checks that the length of the `_values` array is between 2 and `FRACTION_LIMIT`, and that the + * sum of the values in the `_values` array is equal to the number of units associated with the original token. + * @dev The function then creates new tokens with the specified unit values and assigns them to the specified + * account. + * @dev A `BatchValueTransfer` event is emitted to indicate that the original token has been split into multiple + * tokens. */ function _splitTokenUnits(address _account, uint256 _tokenID, uint256[] calldata _values) internal { if (_values.length > FRACTION_LIMIT || _values.length < 2) revert Errors.ArraySize(); @@ -309,7 +320,7 @@ contract SemiFungible1155 is _valuesCache[len] = _valuesCache[0]; _valuesCache[0] = swapValue; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { _notMaxItem(maxIndex[_typeID]); typeIDs[i] = _typeID; @@ -326,7 +337,7 @@ contract SemiFungible1155 is _beforeUnitTransfer(_msgSender(), owners[_tokenID], fromIDs, toIDs, values, ""); - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { valueLeft -= values[i]; tokenValues[toIDs[i]] = values[i]; @@ -350,7 +361,8 @@ contract SemiFungible1155 is * @dev This function merges the units of multiple tokens into a single token. * @dev The `_fractionIDs` array specifies the IDs of the tokens to merge. * @dev The function checks that the length of the `_fractionIDs` array is between 2 and `FRACTION_LIMIT`. - * @dev The function then calculates the total value of the merged token by summing the values of the tokens to be merged. + * @dev The function then calculates the total value of the merged token by summing the values of the tokens to be + * merged. * @dev The `tokenValues` mapping is updated with the total value of the merged token. * @dev The tokens to be merged are burned except the last one that receives all the units. * @dev A `BatchValueTransfer` event is emitted to indicate that the tokens have been merged into a single token. @@ -370,7 +382,7 @@ contract SemiFungible1155 is uint256[] memory amounts = new uint256[](len); { - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { uint256 _fractionID = _fractionIDs[i]; fromIDs[i] = _fractionID; toIDs[i] = target; @@ -385,7 +397,7 @@ contract SemiFungible1155 is _beforeUnitTransfer(_msgSender(), _account, fromIDs, toIDs, values, ""); - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { _totalValue += values[i]; delete tokenValues[fromIDs[i]]; @@ -404,8 +416,10 @@ contract SemiFungible1155 is * @param _account The address of the account that owns the token to burn. * @param _tokenID The ID of the token to burn. * @dev This function burns a single token with the specified ID and emits a `ValueTransfer` event `toTokenID` 0. - * @dev The function checks that the caller is the owner of the token or is approved to burn the token on behalf of the owner. - * @dev The function then deletes the token from the `tokenValues` mapping and calls the `_burn` function to burn the token. + * @dev The function checks that the caller is the owner of the token or is approved to burn the token on behalf of + * the owner. + * @dev The function then deletes the token from the `tokenValues` mapping and calls the `_burn` function to burn + * the token. */ function _burnToken(address _account, uint256 _tokenID) internal { if (_account != _msgSender() && !isApprovedForAll(_account, _msgSender())) revert Errors.NotApprovedOrOwner(); @@ -423,9 +437,12 @@ contract SemiFungible1155 is * @param _account The address of the account that owns the tokens to burn. * @param _tokenIDs An array of token IDs to burn. * @dev This function burns multiple tokens with the specified IDs and emits a `BatchValueTransfer` event. - * @dev The function checks that the caller is the owner of the tokens or is approved to burn the tokens on behalf of the owner. - * @dev The function then deletes the tokens from the `tokenValues` mapping and calls the `_burnBatch` function to burn the tokens. - * @dev Finally, the function emits a `BatchValueTransfer` event with a value of 1 and `toTokenIDs` as 0 for each token burned to indicate that the tokens have been burned. + * @dev The function checks that the caller is the owner of the tokens or is approved to burn the tokens on behalf + * of the owner. + * @dev The function then deletes the tokens from the `tokenValues` mapping and calls the `_burnBatch` function to + * burn the tokens. + * @dev Finally, the function emits a `BatchValueTransfer` event with a value of 1 and `toTokenIDs` as 0 for each + * token burned to indicate that the tokens have been burned. */ function _batchBurnToken(address _account, uint256[] memory _tokenIDs) internal { if (_account != _msgSender() && !isApprovedForAll(_account, _msgSender())) revert Errors.NotApprovedOrOwner(); @@ -478,7 +495,7 @@ contract SemiFungible1155 is uint256 len = ids.length; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { owners[ids[i]] = to; unchecked { ++i; @@ -488,25 +505,26 @@ contract SemiFungible1155 is /** * @dev Called before a batch of tokens is transferred. - * @param operator The address of the operator performing the transfer. + * @param {operator} The address of the operator performing the transfer. * @param from The address of the sender of the tokens. * @param fromIDs An array of token IDs that are being transferred. * @param toIDs An array of token IDs that the tokens are being transferred to. - * @param values An array of token amounts that are being transferred. - * @param data Additional data that was passed along with the transfer. - * @dev This function checks that the transfer is allowed by verifying that the sender is approved to transfer the tokens and that the tokens being transferred are of the same base type. + * @param {values} An array of token amounts that are being transferred. + * @param {data} Additional data that was passed along with the transfer. + * @dev This function checks that the transfer is allowed by verifying that the sender is approved to transfer the + * tokens and that the tokens being transferred are of the same base type. */ function _beforeUnitTransfer( - address operator, + address, /*operator*/ address from, uint256[] memory fromIDs, uint256[] memory toIDs, - uint256[] memory values, - bytes memory data + uint256[] memory, /*values*/ + bytes memory /*data*/ ) internal virtual { uint256 len = fromIDs.length; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { uint256 _from = fromIDs[i]; uint256 _to = toIDs[i]; @@ -525,13 +543,19 @@ contract SemiFungible1155 is * @dev Returns the metadata URI for a given token ID. * @param tokenID The ID of the token to retrieve the metadata URI for. * @return _uri The metadata URI for the specified token ID. - * @dev This function retrieves the metadata URI for the specified token ID by calling the `uri` function of the `ERC1155URIStorageUpgradeable` contract. - * @dev The metadata URI is a string that points to a JSON file containing information about the token, such as its name, symbol, and image. + * @dev This function retrieves the metadata URI for the specified token ID by calling the `uri` function of the + * `ERC1155URIStorageUpgradeable` contract. + * @dev The metadata URI is a string that points to a JSON file containing information about the token, such as its + * name, symbol, and image. * @dev This function always returns the URI for the basetype so that it's managed in one place. */ - function uri( - uint256 tokenID - ) public view virtual override(ERC1155Upgradeable, ERC1155URIStorageUpgradeable) returns (string memory _uri) { + function uri(uint256 tokenID) + public + view + virtual + override(ERC1155Upgradeable, ERC1155URIStorageUpgradeable) + returns (string memory _uri) + { // All tokens share the same metadata at the moment _uri = ERC1155URIStorageUpgradeable.uri(getBaseType(tokenID)); } @@ -541,7 +565,8 @@ contract SemiFungible1155 is /** * @dev Checks if the specified token ID is below the maximum item index. * @param tokenID The ID of the token to check. - * @dev This function checks if the specified token ID is below the maximum item index by converting the token ID to a `uint128` value and incrementing it. + * @dev This function checks if the specified token ID is below the maximum item index by converting the token ID to + * a `uint128` value and incrementing it. * @dev If the token ID is greater than or equal to the maximum item index, the function will revert with an error. */ function _notMaxItem(uint256 tokenID) private pure { @@ -552,7 +577,8 @@ contract SemiFungible1155 is /** * @dev Checks if the specified token ID is below the maximum type index. * @param tokenID The ID of the token to check. - * @dev This function checks if the specified token ID is below the maximum type index by shifting the token ID right by 128 bits to get the type ID and converting it to a `uint128` value. + * @dev This function checks if the specified token ID is below the maximum type index by shifting the token ID + * right by 128 bits to get the type ID and converting it to a `uint128` value. * @dev If the type ID is greater than or equal to the maximum type index, the function will revert with an error. */ function _notMaxType(uint256 tokenID) private pure { @@ -564,12 +590,13 @@ contract SemiFungible1155 is * @dev Calculates the sum of the elements of an array. * @param array The array of uint256 values to sum. * @return sum The sum of the elements of the array. - * @dev This function calculates the sum of the elements of the specified array by iterating over the array and adding each element to a running total. + * @dev This function calculates the sum of the elements of the specified array by iterating over the array and + * adding each element to a running total. * @dev If an element in the array is 0, the function will revert with an error. */ function _getSum(uint256[] memory array) internal pure returns (uint256 sum) { uint256 len = array.length; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { if (array[i] == 0) revert Errors.NotAllowed(); sum += array[i]; unchecked { @@ -582,7 +609,8 @@ contract SemiFungible1155 is * @dev Returns an array containing a single element. * @param element The element to include in the array. * @return An array containing a single element. - * @dev This function returns an array containing a single element by creating a new array with a length of 1 and setting the first element to the specified value. + * @dev This function returns an array containing a single element by creating a new array with a length of 1 and + * setting the first element to the specified value. */ function _getSingletonArray(uint256 element) private pure returns (uint256[] memory) { uint256[] memory array = new uint256[](1); diff --git a/contracts/src/protocol/interfaces/IAllowlist.sol b/contracts/src/protocol/interfaces/IAllowlist.sol index fe4a9ec4..2ce9a044 100644 --- a/contracts/src/protocol/interfaces/IAllowlist.sol +++ b/contracts/src/protocol/interfaces/IAllowlist.sol @@ -6,9 +6,8 @@ pragma solidity 0.8.16; /// @notice This interface declares the required functionality for a hypercert token /// @notice This interface does not specify the underlying token type (e.g. 721 or 1155) interface IAllowlist { - function isAllowedToClaim( - bytes32[] calldata proof, - uint256 tokenID, - bytes32 leaf - ) external view returns (bool isAllowed); + function isAllowedToClaim(bytes32[] calldata proof, uint256 tokenID, bytes32 leaf) + external + view + returns (bool isAllowed); } diff --git a/contracts/test/foundry/marketplace/BatchMakerCollectionOrders.t.sol b/contracts/test/foundry/marketplace/BatchMakerCollectionOrders.t.sol index 9222bd04..8810028b 100644 --- a/contracts/test/foundry/marketplace/BatchMakerCollectionOrders.t.sol +++ b/contracts/test/foundry/marketplace/BatchMakerCollectionOrders.t.sol @@ -2,23 +2,23 @@ pragma solidity 0.8.17; // Strategies -import { StrategyCollectionOffer } from "@hypercerts/marketplace/executionStrategies/StrategyCollectionOffer.sol"; +import {StrategyCollectionOffer} from "@hypercerts/marketplace/executionStrategies/StrategyCollectionOffer.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Helpers -import { EIP712MerkleTree } from "./utils/EIP712MerkleTree.sol"; +import {EIP712MerkleTree} from "./utils/EIP712MerkleTree.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract BatchMakerCollectionOrdersTest is ProtocolBase { StrategyCollectionOffer private strategy; @@ -50,7 +50,7 @@ contract BatchMakerCollectionOrdersTest is ProtocolBase { OrderStructs.Maker[] memory makerBids = _createBatchMakerBids(numberOrders); - (bytes memory signature, ) = eip712MerkleTree.sign(makerUserPK, makerBids, 0); + (bytes memory signature,) = eip712MerkleTree.sign(makerUserPK, makerBids, 0); for (uint256 i; i < numberOrders; i++) { // To prove that we only need 1 signature for multiple collection offers, @@ -66,7 +66,7 @@ contract BatchMakerCollectionOrdersTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerOrder, makerBidToExecute, signature, merkleTree, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerOrder, makerBidToExecute, signature, merkleTree); // Maker user has received the asset assertEq(mockERC721.ownerOf(i), makerUser); @@ -80,15 +80,12 @@ contract BatchMakerCollectionOrdersTest is ProtocolBase { uint256 totalValue = price * numberOrders; assertEq( - weth.balanceOf(makerUser), - _initialWETHBalanceUser - totalValue, - "Maker bid user should pay the whole price" + weth.balanceOf(makerUser), _initialWETHBalanceUser - totalValue, "Maker bid user should pay the whole price" ); assertEq( weth.balanceOf(takerUser), - _initialWETHBalanceUser + - (totalValue * _sellerProceedBpWithStandardProtocolFeeBp) / - ONE_HUNDRED_PERCENT_IN_BP, + _initialWETHBalanceUser + + (totalValue * _sellerProceedBpWithStandardProtocolFeeBp) / ONE_HUNDRED_PERCENT_IN_BP, "Taker ask user should receive 99.5% of the whole price (0.5% protocol)" ); } diff --git a/contracts/test/foundry/marketplace/BatchMakerOrders.t.sol b/contracts/test/foundry/marketplace/BatchMakerOrders.t.sol index fabceaae..35bb3570 100644 --- a/contracts/test/foundry/marketplace/BatchMakerOrders.t.sol +++ b/contracts/test/foundry/marketplace/BatchMakerOrders.t.sol @@ -2,25 +2,31 @@ pragma solidity 0.8.17; // Murky (third-party) library is used to compute Merkle trees in Solidity -import { Merkle } from "murky/Merkle.sol"; +import {Merkle} from "murky/Merkle.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Errors and constants -import { MerkleProofTooLarge, MerkleProofInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { MERKLE_PROOF_PROOF_TOO_LARGE, ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; -import { ONE_HUNDRED_PERCENT_IN_BP, MAX_CALLDATA_PROOF_LENGTH } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {MerkleProofTooLarge, MerkleProofInvalid} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import { + MERKLE_PROOF_PROOF_TOO_LARGE, + ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + ONE_HUNDRED_PERCENT_IN_BP, + MAX_CALLDATA_PROOF_LENGTH +} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Helpers -import { EIP712MerkleTree } from "./utils/EIP712MerkleTree.sol"; +import {EIP712MerkleTree} from "./utils/EIP712MerkleTree.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract BatchMakerOrdersTest is ProtocolBase { uint256 private constant price = 1.2222 ether; // Fixed price of sale @@ -39,11 +45,8 @@ contract BatchMakerOrdersTest is ProtocolBase { OrderStructs.Maker[] memory makerAsks = _createBatchMakerAsks(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerAsks, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerAsks, orderIndex); OrderStructs.Maker memory makerAskToExecute = makerAsks[orderIndex]; @@ -52,13 +55,7 @@ contract BatchMakerOrdersTest is ProtocolBase { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - _genericTakerOrder(), - makerAskToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(_genericTakerOrder(), makerAskToExecute, signature, merkleTree); // Taker user has received the asset assertEq(mockERC721.ownerOf(orderIndex), takerUser); @@ -73,8 +70,7 @@ contract BatchMakerOrdersTest is ProtocolBase { assertEq(address(looksRareProtocol).balance, 0); // Verify the nonce is marked as executed assertEq( - looksRareProtocol.userOrderNonce(makerUser, makerAskToExecute.orderNonce), - MAGIC_VALUE_ORDER_NONCE_EXECUTED + looksRareProtocol.userOrderNonce(makerUser, makerAskToExecute.orderNonce), MAGIC_VALUE_ORDER_NONCE_EXECUTED ); } @@ -85,11 +81,8 @@ contract BatchMakerOrdersTest is ProtocolBase { OrderStructs.Maker[] memory makerBids = _createBatchMakerBids(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerBids, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerBids, orderIndex); OrderStructs.Maker memory makerBidToExecute = makerBids[orderIndex]; @@ -98,13 +91,7 @@ contract BatchMakerOrdersTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBidToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBidToExecute, signature, merkleTree); // Maker user has received the asset assertEq(mockERC721.ownerOf(orderIndex), makerUser); @@ -117,23 +104,21 @@ contract BatchMakerOrdersTest is ProtocolBase { ); // Verify the nonce is marked as executed assertEq( - looksRareProtocol.userOrderNonce(makerUser, makerBidToExecute.orderNonce), - MAGIC_VALUE_ORDER_NONCE_EXECUTED + looksRareProtocol.userOrderNonce(makerUser, makerBidToExecute.orderNonce), MAGIC_VALUE_ORDER_NONCE_EXECUTED ); } - function testTakerBidMultipleOrdersSignedERC721MerkleProofInvalid(uint256 numberOrders, uint256 orderIndex) public { + function testTakerBidMultipleOrdersSignedERC721MerkleProofInvalid(uint256 numberOrders, uint256 orderIndex) + public + { _assertMerkleTreeAssumptions(numberOrders, orderIndex); mockERC721.batchMint(makerUser, numberOrders); OrderStructs.Maker[] memory makerAsks = _createBatchMakerAsks(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerAsks, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerAsks, orderIndex); bytes32 tamperedRoot = bytes32(uint256(merkleTree.root) + 1); merkleTree.root = tamperedRoot; @@ -142,35 +127,25 @@ contract BatchMakerOrdersTest is ProtocolBase { // Verify invalidity of maker ask order _assertMakerOrderReturnValidationCodeWithMerkleTree( - makerAskToExecute, - signature, - merkleTree, - ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE + makerAskToExecute, signature, merkleTree, ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE ); vm.prank(takerUser); vm.expectRevert(MerkleProofInvalid.selector); - looksRareProtocol.executeTakerBid{ value: price }( - _genericTakerOrder(), - makerAskToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(_genericTakerOrder(), makerAskToExecute, signature, merkleTree); } - function testTakerAskMultipleOrdersSignedERC721MerkleProofInvalid(uint256 numberOrders, uint256 orderIndex) public { + function testTakerAskMultipleOrdersSignedERC721MerkleProofInvalid(uint256 numberOrders, uint256 orderIndex) + public + { _assertMerkleTreeAssumptions(numberOrders, orderIndex); mockERC721.batchMint(takerUser, numberOrders); OrderStructs.Maker[] memory makerBids = _createBatchMakerBids(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerBids, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerBids, orderIndex); bytes32 tamperedRoot = bytes32(uint256(merkleTree.root) + 1); merkleTree.root = tamperedRoot; @@ -179,38 +154,25 @@ contract BatchMakerOrdersTest is ProtocolBase { // Verify invalidity of maker bid order _assertMakerOrderReturnValidationCodeWithMerkleTree( - makerBidToExecute, - signature, - merkleTree, - ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE + makerBidToExecute, signature, merkleTree, ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE ); vm.prank(takerUser); vm.expectRevert(MerkleProofInvalid.selector); - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBidToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBidToExecute, signature, merkleTree); } - function testTakerBidMultipleOrdersSignedERC721MerkleProofWrongPosition( - uint256 numberOrders, - uint256 orderIndex - ) public { + function testTakerBidMultipleOrdersSignedERC721MerkleProofWrongPosition(uint256 numberOrders, uint256 orderIndex) + public + { _assertMerkleTreeAssumptions(numberOrders, orderIndex); mockERC721.batchMint(makerUser, numberOrders); OrderStructs.Maker[] memory makerAsks = _createBatchMakerAsks(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerAsks, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerAsks, orderIndex); // Swap every node's position OrderStructs.MerkleTreeNode[] memory proof = merkleTree.proof; @@ -226,38 +188,25 @@ contract BatchMakerOrdersTest is ProtocolBase { // Verify invalidity of maker ask order _assertMakerOrderReturnValidationCodeWithMerkleTree( - makerAskToExecute, - signature, - merkleTree, - ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE + makerAskToExecute, signature, merkleTree, ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE ); vm.prank(takerUser); vm.expectRevert(MerkleProofInvalid.selector); - looksRareProtocol.executeTakerBid{ value: price }( - _genericTakerOrder(), - makerAskToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(_genericTakerOrder(), makerAskToExecute, signature, merkleTree); } - function testTakerAskMultipleOrdersSignedERC721MerkleProofWrongPosition( - uint256 numberOrders, - uint256 orderIndex - ) public { + function testTakerAskMultipleOrdersSignedERC721MerkleProofWrongPosition(uint256 numberOrders, uint256 orderIndex) + public + { _assertMerkleTreeAssumptions(numberOrders, orderIndex); mockERC721.batchMint(takerUser, numberOrders); OrderStructs.Maker[] memory makerBids = _createBatchMakerBids(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerBids, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerBids, orderIndex); // Swap every node's position OrderStructs.MerkleTreeNode[] memory proof = merkleTree.proof; @@ -273,21 +222,12 @@ contract BatchMakerOrdersTest is ProtocolBase { // Verify invalidity of maker bid order _assertMakerOrderReturnValidationCodeWithMerkleTree( - makerBidToExecute, - signature, - merkleTree, - ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE + makerBidToExecute, signature, merkleTree, ORDER_HASH_PROOF_NOT_IN_MERKLE_TREE ); vm.prank(takerUser); vm.expectRevert(MerkleProofInvalid.selector); - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBidToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBidToExecute, signature, merkleTree); } function testTakerBidRevertsIfProofTooLarge() public { @@ -301,30 +241,20 @@ contract BatchMakerOrdersTest is ProtocolBase { OrderStructs.Maker[] memory makerAsks = _createBatchMakerAsks(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerAsks, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerAsks, orderIndex); OrderStructs.Maker memory makerAskToExecute = makerAsks[orderIndex]; // Verify validity _assertMakerOrderReturnValidationCodeWithMerkleTree( - makerAskToExecute, - signature, - merkleTree, - MERKLE_PROOF_PROOF_TOO_LARGE + makerAskToExecute, signature, merkleTree, MERKLE_PROOF_PROOF_TOO_LARGE ); vm.prank(takerUser); vm.expectRevert(abi.encodeWithSelector(MerkleProofTooLarge.selector, proofLength)); - looksRareProtocol.executeTakerBid{ value: price }( - _genericTakerOrder(), - makerAskToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE + looksRareProtocol.executeTakerBid{value: price}( + _genericTakerOrder(), makerAskToExecute, signature, merkleTree ); } } @@ -340,30 +270,20 @@ contract BatchMakerOrdersTest is ProtocolBase { OrderStructs.Maker[] memory makerBids = _createBatchMakerBids(numberOrders); - (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = eip712MerkleTree.sign( - makerUserPK, - makerBids, - orderIndex - ); + (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) = + eip712MerkleTree.sign(makerUserPK, makerBids, orderIndex); OrderStructs.Maker memory makerBidToExecute = makerBids[orderIndex]; // Verify validity _assertMakerOrderReturnValidationCodeWithMerkleTree( - makerBidToExecute, - signature, - merkleTree, - MERKLE_PROOF_PROOF_TOO_LARGE + makerBidToExecute, signature, merkleTree, MERKLE_PROOF_PROOF_TOO_LARGE ); vm.prank(takerUser); vm.expectRevert(abi.encodeWithSelector(MerkleProofTooLarge.selector, proofLength)); - looksRareProtocol.executeTakerBid{ value: price }( - _genericTakerOrder(), - makerBidToExecute, - signature, - merkleTree, - _EMPTY_AFFILIATE + looksRareProtocol.executeTakerBid{value: price}( + _genericTakerOrder(), makerBidToExecute, signature, merkleTree ); } } diff --git a/contracts/test/foundry/marketplace/BatchOrderTypehashRegistry.t.sol b/contracts/test/foundry/marketplace/BatchOrderTypehashRegistry.t.sol index cbbf7cb3..e44c2af4 100644 --- a/contracts/test/foundry/marketplace/BatchOrderTypehashRegistry.t.sol +++ b/contracts/test/foundry/marketplace/BatchOrderTypehashRegistry.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { Test } from "forge-std/Test.sol"; +import {Test} from "forge-std/Test.sol"; -import { BatchOrderTypehashRegistry } from "@hypercerts/marketplace/BatchOrderTypehashRegistry.sol"; +import {BatchOrderTypehashRegistry} from "@hypercerts/marketplace/BatchOrderTypehashRegistry.sol"; // Shared errors -import { MerkleProofTooLarge } from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import {MerkleProofTooLarge} from "@hypercerts/marketplace/errors/SharedErrors.sol"; contract BatchOrderTypehashRegistryInheriter is BatchOrderTypehashRegistry { function getBatchOrderTypehash(uint256 height) external pure returns (bytes32 typehash) { @@ -19,67 +19,44 @@ contract BatchOrderTypehashRegistryTest is Test { BatchOrderTypehashRegistryInheriter registry = new BatchOrderTypehashRegistryInheriter(); bytes32 root = hex"6942000000000000000000000000000000000000000000000000000000000000"; assertEq( - registry.hashBatchOrder(root, 1), - hex"8f0c85a215cff55fe39cf62ee7a1e0b5205a8ade02ff12ffee9ece02d626ffc3" + registry.hashBatchOrder(root, 1), hex"8f0c85a215cff55fe39cf62ee7a1e0b5205a8ade02ff12ffee9ece02d626ffc3" ); assertEq( - registry.hashBatchOrder(root, 2), - hex"f04a7d8a4688cf084b00b51ed583de7e5a19e59b073635e00a45a474899e89ec" + registry.hashBatchOrder(root, 2), hex"f04a7d8a4688cf084b00b51ed583de7e5a19e59b073635e00a45a474899e89ec" ); assertEq( - registry.hashBatchOrder(root, 3), - hex"56ef3bb8c564d19cfe494776934aa5e7ed84c41ae609d5f10e726f76281dd30b" + registry.hashBatchOrder(root, 3), hex"56ef3bb8c564d19cfe494776934aa5e7ed84c41ae609d5f10e726f76281dd30b" ); assertEq( - registry.hashBatchOrder(root, 4), - hex"2b0cb021eacab73e36d9ac9a04c1cf58589ff5bb4dc0d9b88ec29f67358ca812" + registry.hashBatchOrder(root, 4), hex"2b0cb021eacab73e36d9ac9a04c1cf58589ff5bb4dc0d9b88ec29f67358ca812" ); assertEq( - registry.hashBatchOrder(root, 5), - hex"253b3cc8d591a8b01fc8967cefe3ac3d0e078b884d96aa589f1ffd4536921bbb" + registry.hashBatchOrder(root, 5), hex"253b3cc8d591a8b01fc8967cefe3ac3d0e078b884d96aa589f1ffd4536921bbb" ); assertEq( - registry.hashBatchOrder(root, 6), - hex"7e4c4a2c5806fc4765bca325e8b78ccf9633bd1c7643144a56210293daefcbca" + registry.hashBatchOrder(root, 6), hex"7e4c4a2c5806fc4765bca325e8b78ccf9633bd1c7643144a56210293daefcbca" ); assertEq( - registry.hashBatchOrder(root, 7), - hex"e8e39cebe7137f0fadf6b88ba611044ac79c0168444eab66ca53bddd0c5fb717" + registry.hashBatchOrder(root, 7), hex"e8e39cebe7137f0fadf6b88ba611044ac79c0168444eab66ca53bddd0c5fb717" ); assertEq( - registry.hashBatchOrder(root, 8), - hex"6e02f123509255ed381c7552de5e2ac1c1ea401a23e026e2452f01b70564affb" + registry.hashBatchOrder(root, 8), hex"6e02f123509255ed381c7552de5e2ac1c1ea401a23e026e2452f01b70564affb" ); assertEq( - registry.hashBatchOrder(root, 9), - hex"7eeb4a7fe4655841fdd66f8ecfcf6cd261d50eafabbaebb10f63f5fe84ddddc9" + registry.hashBatchOrder(root, 9), hex"7eeb4a7fe4655841fdd66f8ecfcf6cd261d50eafabbaebb10f63f5fe84ddddc9" ); assertEq( - registry.hashBatchOrder(root, 10), - hex"a96dee8b7b88deda5d50b55f641ca08c1ee00825eeb1db7a324f392fa0b8bb83" + registry.hashBatchOrder(root, 10), hex"a96dee8b7b88deda5d50b55f641ca08c1ee00825eeb1db7a324f392fa0b8bb83" ); } function testGetTypehash() public { BatchOrderTypehashRegistryInheriter registry = new BatchOrderTypehashRegistryInheriter(); bytes memory makerOrderString = bytes( - "Maker(" - "uint8 quoteType," - "uint256 globalNonce," - "uint256 subsetNonce," - "uint256 orderNonce," - "uint256 strategyId," - "uint8 collectionType," - "address collection," - "address currency," - "address signer," - "uint256 startTime," - "uint256 endTime," - "uint256 price," - "uint256[] itemIds," - "uint256[] amounts," - "bytes additionalParameters" - ")" + "Maker(" "uint8 quoteType," "uint256 globalNonce," "uint256 subsetNonce," "uint256 orderNonce," + "uint256 strategyId," "uint8 collectionType," "address collection," "address currency," "address signer," + "uint256 startTime," "uint256 endTime," "uint256 price," "uint256[] itemIds," "uint256[] amounts," + "bytes additionalParameters" ")" ); assertEq( diff --git a/contracts/test/foundry/marketplace/BundleTransactions.t.sol b/contracts/test/foundry/marketplace/BundleTransactions.t.sol index c7331cd3..62ffccf9 100644 --- a/contracts/test/foundry/marketplace/BundleTransactions.t.sol +++ b/contracts/test/foundry/marketplace/BundleTransactions.t.sol @@ -2,13 +2,13 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Other tests -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; contract BundleTransactionsTest is ProtocolBase { function setUp() public { @@ -19,10 +19,8 @@ contract BundleTransactionsTest is ProtocolBase { _setUpUsers(); uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle(address(mockERC721), address(weth), numberItemsInBundle); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -35,7 +33,7 @@ contract BundleTransactionsTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertMockERC721Ownership(makerBid.itemIds, makerUser); @@ -46,10 +44,8 @@ contract BundleTransactionsTest is ProtocolBase { _setUpUsers(); uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle(address(mockERC1155), address(weth), numberItemsInBundle); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC1155), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -62,7 +58,7 @@ contract BundleTransactionsTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); for (uint256 i; i < makerBid.itemIds.length; i++) { // Maker user has received all the assets in the bundle @@ -77,10 +73,8 @@ contract BundleTransactionsTest is ProtocolBase { _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle(address(mockERC721), address(weth), numberItemsInBundle); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721), address(weth), numberItemsInBundle); uint256 price = makerBid.price; @@ -95,7 +89,7 @@ contract BundleTransactionsTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertMockERC721Ownership(makerBid.itemIds, makerUser); @@ -124,10 +118,8 @@ contract BundleTransactionsTest is ProtocolBase { _setUpUsers(); uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerAsk, - OrderStructs.Taker memory takerBid - ) = _createMockMakerAskAndTakerBidWithBundle(address(mockERC721), numberItemsInBundle); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBidWithBundle(address(mockERC721), numberItemsInBundle); uint256 price = makerAsk.price; @@ -140,13 +132,7 @@ contract BundleTransactionsTest is ProtocolBase { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); _assertMockERC721Ownership(makerAsk.itemIds, takerUser); @@ -157,10 +143,8 @@ contract BundleTransactionsTest is ProtocolBase { _setUpUsers(); uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerAsk, - OrderStructs.Taker memory takerBid - ) = _createMockMakerAskAndTakerBidWithBundle(address(mockERC1155), numberItemsInBundle); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBidWithBundle(address(mockERC1155), numberItemsInBundle); uint256 price = makerAsk.price; @@ -173,13 +157,7 @@ contract BundleTransactionsTest is ProtocolBase { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); for (uint256 i; i < makerAsk.itemIds.length; i++) { // Taker user has received all the assets in the bundle @@ -194,10 +172,8 @@ contract BundleTransactionsTest is ProtocolBase { _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerAsk, - OrderStructs.Taker memory takerBid - ) = _createMockMakerAskAndTakerBidWithBundle(address(mockERC721), numberItemsInBundle); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBidWithBundle(address(mockERC721), numberItemsInBundle); uint256 price = makerAsk.price; @@ -211,13 +187,7 @@ contract BundleTransactionsTest is ProtocolBase { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); _assertMockERC721Ownership(makerAsk.itemIds, takerUser); diff --git a/contracts/test/foundry/marketplace/CreatorFeeManagerWithRebates.t.sol b/contracts/test/foundry/marketplace/CreatorFeeManagerWithRebates.t.sol index 6a3b7ac0..93a552db 100644 --- a/contracts/test/foundry/marketplace/CreatorFeeManagerWithRebates.t.sol +++ b/contracts/test/foundry/marketplace/CreatorFeeManagerWithRebates.t.sol @@ -2,23 +2,23 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IERC721 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC721.sol"; +import {IERC721} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC721.sol"; -import { CreatorFeeManagerWithRebates } from "@hypercerts/marketplace/CreatorFeeManagerWithRebates.sol"; +import {CreatorFeeManagerWithRebates} from "@hypercerts/marketplace/CreatorFeeManagerWithRebates.sol"; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { ICreatorFeeManager } from "@hypercerts/marketplace/interfaces/ICreatorFeeManager.sol"; -import { IExecutionManager } from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {ICreatorFeeManager} from "@hypercerts/marketplace/interfaces/ICreatorFeeManager.sol"; +import {IExecutionManager} from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; // Shared errors -import { BUNDLE_ERC2981_NOT_SUPPORTED } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import {BUNDLE_ERC2981_NOT_SUPPORTED} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; contract CreatorFeeManagerWithRebatesTest is ProtocolBase { function setUp() public { @@ -32,20 +32,15 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { function _setUpRoyaltiesRegistry(uint256 fee) private { vm.prank(_owner); royaltyFeeRegistry.updateRoyaltyInfoForCollection( - address(mockERC721), - _royaltyRecipient, - _royaltyRecipient, - fee + address(mockERC721), _royaltyRecipient, _royaltyRecipient, fee ); } function _testCreatorFeeRebatesArePaid(address erc721) private { _setUpUsers(); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - erc721, - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(erc721, address(weth)); bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -57,9 +52,7 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { } else if (erc721 == address(mockERC721WithRoyalties)) { // Adjust ERC721 with royalties mockERC721WithRoyalties.addCustomRoyaltyInformationForTokenId( - makerBid.itemIds[0], - _royaltyRecipient, - _standardRoyaltyFee + makerBid.itemIds[0], _royaltyRecipient, _standardRoyaltyFee ); // Mint asset mockERC721WithRoyalties.mint(takerUser, makerBid.itemIds[0]); @@ -69,7 +62,7 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Verify ownership is transferred assertEq(IERC721(erc721).ownerOf(makerBid.itemIds[0]), makerUser); @@ -84,10 +77,8 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { uint256 numberItemsInBundle = 5; // Create order - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle(erc721, address(weth), numberItemsInBundle); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(erc721, address(weth), numberItemsInBundle); if (erc721 == address(mockERC721)) { // Adjust royalties @@ -98,9 +89,7 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { // Adjust ERC721 with royalties for (uint256 i; i < makerBid.itemIds.length; i++) { mockERC721WithRoyalties.addCustomRoyaltyInformationForTokenId( - makerBid.itemIds[i], - _royaltyRecipient, - _standardRoyaltyFee + makerBid.itemIds[i], _royaltyRecipient, _standardRoyaltyFee ); } // Mint the items @@ -116,7 +105,7 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { vm.prank(takerUser); // Execute taker ask transaction - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Verify ownership is transferred for (uint256 i; i < makerBid.itemIds.length; i++) { @@ -147,14 +136,8 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle( - address(mockERC721WithRoyalties), - address(weth), - numberItemsInBundle - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721WithRoyalties), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -171,9 +154,7 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { // Adjust ERC721 with royalties for (uint256 i; i < makerBid.itemIds.length; i++) { mockERC721WithRoyalties.addCustomRoyaltyInformationForTokenId( - makerBid.itemIds[i], - i == 0 ? _royaltyRecipient : address(50), - 50 + makerBid.itemIds[i], i == 0 ? _royaltyRecipient : address(50), 50 ); } @@ -182,11 +163,10 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert( abi.encodeWithSelector( - ICreatorFeeManager.BundleEIP2981NotAllowed.selector, - address(mockERC721WithRoyalties) + ICreatorFeeManager.BundleEIP2981NotAllowed.selector, address(mockERC721WithRoyalties) ) ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCreatorRoyaltiesRevertForEIP2981WithBundlesIfAtLeastOneCallReverts(uint256 revertIndex) public { @@ -195,14 +175,8 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { uint256 numberItemsInBundle = 5; vm.assume(revertIndex < numberItemsInBundle); - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle( - address(mockERC721WithRoyalties), - address(weth), - numberItemsInBundle - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721WithRoyalties), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -227,11 +201,10 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert( abi.encodeWithSelector( - ICreatorFeeManager.BundleEIP2981NotAllowed.selector, - address(mockERC721WithRoyalties) + ICreatorFeeManager.BundleEIP2981NotAllowed.selector, address(mockERC721WithRoyalties) ) ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function _assertSuccessfulTakerAsk(OrderStructs.Maker memory makerBid) private { @@ -246,7 +219,7 @@ contract CreatorFeeManagerWithRebatesTest is ProtocolBase { ); assertEq( weth.balanceOf(takerUser), - _initialWETHBalanceUser + (price * 9_900) / ONE_HUNDRED_PERCENT_IN_BP, + _initialWETHBalanceUser + (price * 9900) / ONE_HUNDRED_PERCENT_IN_BP, "Taker ask user should receive 99% of the whole price" ); assertEq( diff --git a/contracts/test/foundry/marketplace/CreatorFeeManagerWithRoyalties.t.sol b/contracts/test/foundry/marketplace/CreatorFeeManagerWithRoyalties.t.sol index d4fea298..3ba84222 100644 --- a/contracts/test/foundry/marketplace/CreatorFeeManagerWithRoyalties.t.sol +++ b/contracts/test/foundry/marketplace/CreatorFeeManagerWithRoyalties.t.sol @@ -2,21 +2,24 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { ICreatorFeeManager } from "@hypercerts/marketplace/interfaces/ICreatorFeeManager.sol"; -import { IExecutionManager } from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {ICreatorFeeManager} from "@hypercerts/marketplace/interfaces/ICreatorFeeManager.sol"; +import {IExecutionManager} from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; // Core contract -import { CreatorFeeManagerWithRoyalties } from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; +import {CreatorFeeManagerWithRoyalties} from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; // Shared errors -import { BUNDLE_ERC2981_NOT_SUPPORTED, CREATOR_FEE_TOO_HIGH } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + BUNDLE_ERC2981_NOT_SUPPORTED, + CREATOR_FEE_TOO_HIGH +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { CreatorFeeManagerWithRoyalties public creatorFeeManagerWithRoyalties; @@ -30,10 +33,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { function _setUpRoyaltiesRegistry(uint256 fee) internal { vm.prank(_owner); royaltyFeeRegistry.updateRoyaltyInfoForCollection( - address(mockERC721), - _royaltyRecipient, - _royaltyRecipient, - fee + address(mockERC721), _royaltyRecipient, _royaltyRecipient, fee ); } @@ -56,7 +56,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { // Adjust royalties _setUpRoyaltiesRegistry(_newCreatorRoyaltyFee); - (OrderStructs.Maker memory makerBid, ) = _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); + (OrderStructs.Maker memory makerBid,) = _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -68,13 +68,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBid, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBid, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(makerBid.itemIds[0]), makerUser); @@ -84,16 +78,12 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { function testCreatorRoyaltiesGetPaidForERC2981() public { _setUpUsers(); - (OrderStructs.Maker memory makerBid, ) = _createMockMakerBidAndTakerAsk( - address(mockERC721WithRoyalties), - address(weth) - ); + (OrderStructs.Maker memory makerBid,) = + _createMockMakerBidAndTakerAsk(address(mockERC721WithRoyalties), address(weth)); // Adjust ERC721 with royalties mockERC721WithRoyalties.addCustomRoyaltyInformationForTokenId( - makerBid.itemIds[0], - _royaltyRecipient, - _newCreatorRoyaltyFee + makerBid.itemIds[0], _royaltyRecipient, _newCreatorRoyaltyFee ); // Sign order @@ -106,13 +96,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBid, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBid, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721WithRoyalties.ownerOf(makerBid.itemIds[0]), makerUser); @@ -127,10 +111,8 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle(address(mockERC721), address(weth), numberItemsInBundle); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -145,7 +127,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { vm.prank(takerUser); // Execute taker ask transaction - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertMockERC721Ownership(makerBid.itemIds, makerUser); @@ -157,14 +139,8 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle( - address(mockERC721WithRoyalties), - address(weth), - numberItemsInBundle - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721WithRoyalties), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -175,9 +151,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { // Adjust ERC721 with royalties for (uint256 i; i < makerBid.itemIds.length; i++) { mockERC721WithRoyalties.addCustomRoyaltyInformationForTokenId( - makerBid.itemIds[i], - _royaltyRecipient, - _newCreatorRoyaltyFee + makerBid.itemIds[i], _royaltyRecipient, _newCreatorRoyaltyFee ); } @@ -187,7 +161,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { vm.prank(takerUser); // Execute taker ask transaction - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertSuccessfulTakerAskBundle(makerBid); } @@ -197,14 +171,8 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { uint256 numberItemsInBundle = 5; - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle( - address(mockERC721WithRoyalties), - address(weth), - numberItemsInBundle - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721WithRoyalties), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -231,12 +199,11 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert( abi.encodeWithSelector( - ICreatorFeeManager.BundleEIP2981NotAllowed.selector, - address(mockERC721WithRoyalties) + ICreatorFeeManager.BundleEIP2981NotAllowed.selector, address(mockERC721WithRoyalties) ) ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); /** * 2. Same fee structure but different recipient @@ -244,9 +211,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { // Adjust ERC721 with royalties for (uint256 i; i < makerBid.itemIds.length; i++) { mockERC721WithRoyalties.addCustomRoyaltyInformationForTokenId( - makerBid.itemIds[i], - i == 0 ? _royaltyRecipient : address(50), - _newCreatorRoyaltyFee + makerBid.itemIds[i], i == 0 ? _royaltyRecipient : address(50), _newCreatorRoyaltyFee ); } @@ -255,12 +220,11 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert( abi.encodeWithSelector( - ICreatorFeeManager.BundleEIP2981NotAllowed.selector, - address(mockERC721WithRoyalties) + ICreatorFeeManager.BundleEIP2981NotAllowed.selector, address(mockERC721WithRoyalties) ) ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCreatorRoyaltiesRevertForEIP2981WithBundlesIfAtLeastOneCallReverts(uint256 revertIndex) public { @@ -269,14 +233,8 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { uint256 numberItemsInBundle = 5; vm.assume(revertIndex < numberItemsInBundle); - ( - OrderStructs.Maker memory makerBid, - OrderStructs.Taker memory takerAsk - ) = _createMockMakerBidAndTakerAskWithBundle( - address(mockERC721WithRoyalties), - address(weth), - numberItemsInBundle - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAskWithBundle(address(mockERC721WithRoyalties), address(weth), numberItemsInBundle); // Sign the order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -300,12 +258,11 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert( abi.encodeWithSelector( - ICreatorFeeManager.BundleEIP2981NotAllowed.selector, - address(mockERC721WithRoyalties) + ICreatorFeeManager.BundleEIP2981NotAllowed.selector, address(mockERC721WithRoyalties) ) ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCreatorRoyaltiesRevertIfFeeHigherThanLimit() public { @@ -315,10 +272,8 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { // Adjust royalties _setUpRoyaltiesRegistry(_creatorRoyaltyFeeTooHigh); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -329,16 +284,15 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { vm.expectRevert(IExecutionManager.CreatorFeeBpTooHigh.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // 2. Maker ask // Mint asset mockERC721.mint(makerUser, 1); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); // The itemId changes as it is already minted before makerAsk.itemIds[0] = 1; @@ -349,13 +303,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { vm.expectRevert(IExecutionManager.CreatorFeeBpTooHigh.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: 1 ether }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: 1 ether}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function _assertSuccessfulTakerAsk(OrderStructs.Maker memory makerBid) private { @@ -369,7 +317,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { "ProtocolFeeRecipient should receive 2% of the whole price" ); // Taker ask user receives 95% of the whole price - assertEq(weth.balanceOf(takerUser), _initialWETHBalanceUser + (price * 9_500) / ONE_HUNDRED_PERCENT_IN_BP); + assertEq(weth.balanceOf(takerUser), _initialWETHBalanceUser + (price * 9500) / ONE_HUNDRED_PERCENT_IN_BP); // Royalty recipient receives 3% of the whole price assertEq( weth.balanceOf(_royaltyRecipient), @@ -395,7 +343,7 @@ contract CreatorFeeManagerWithRoyaltiesTest is ProtocolBase { "ProtocolFeeRecipient should receive protocol fee" ); // Taker ask user receives 95% of the whole price - assertEq(weth.balanceOf(takerUser), _initialWETHBalanceUser + (price * 9_500) / ONE_HUNDRED_PERCENT_IN_BP); + assertEq(weth.balanceOf(takerUser), _initialWETHBalanceUser + (price * 9500) / ONE_HUNDRED_PERCENT_IN_BP); // Verify the nonce is marked as executed assertEq(looksRareProtocol.userOrderNonce(makerUser, makerBid.orderNonce), MAGIC_VALUE_ORDER_NONCE_EXECUTED); } diff --git a/contracts/test/foundry/marketplace/CurrencyManager.t.sol b/contracts/test/foundry/marketplace/CurrencyManager.t.sol index 3b00915a..8c410dca 100644 --- a/contracts/test/foundry/marketplace/CurrencyManager.t.sol +++ b/contracts/test/foundry/marketplace/CurrencyManager.t.sol @@ -2,15 +2,15 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IOwnableTwoSteps } from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; +import {IOwnableTwoSteps} from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; // Core contracts -import { CurrencyManager, ICurrencyManager } from "@hypercerts/marketplace/CurrencyManager.sol"; +import {CurrencyManager, ICurrencyManager} from "@hypercerts/marketplace/CurrencyManager.sol"; // Other mocks and utils -import { TestHelpers } from "./utils/TestHelpers.sol"; -import { TestParameters } from "./utils/TestParameters.sol"; -import { MockERC20 } from "../../mock/MockERC20.sol"; +import {TestHelpers} from "./utils/TestHelpers.sol"; +import {TestParameters} from "./utils/TestParameters.sol"; +import {MockERC20} from "../../mock/MockERC20.sol"; contract CurrencyManagerTest is TestHelpers, TestParameters, ICurrencyManager { CurrencyManager private currencyManager; diff --git a/contracts/test/foundry/marketplace/DelegationRecipientsTaker.t.sol b/contracts/test/foundry/marketplace/DelegationRecipientsTaker.t.sol index b052c146..ea5e6445 100644 --- a/contracts/test/foundry/marketplace/DelegationRecipientsTaker.t.sol +++ b/contracts/test/foundry/marketplace/DelegationRecipientsTaker.t.sol @@ -2,14 +2,14 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { CreatorFeeManagerWithRoyalties } from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {CreatorFeeManagerWithRoyalties} from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; contract DelegationRecipientsTakerTest is ProtocolBase { function setUp() public { @@ -32,10 +32,8 @@ contract DelegationRecipientsTakerTest is ProtocolBase { _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); address randomRecipientSaleProceeds = address(420); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -77,7 +75,7 @@ contract DelegationRecipientsTakerTest is ProtocolBase { expectedRecipients, expectedFees ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(makerBid.itemIds[0]), makerUser); @@ -107,9 +105,8 @@ contract DelegationRecipientsTakerTest is ProtocolBase { _setUpUsers(); _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); // Mint asset mockERC721.mint(makerUser, makerAsk.itemIds[0]); @@ -151,13 +148,7 @@ contract DelegationRecipientsTakerTest is ProtocolBase { expectedFees ); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Random recipient user has received the asset assertEq(mockERC721.ownerOf(makerAsk.itemIds[0]), randomRecipientNFT); diff --git a/contracts/test/foundry/marketplace/DomainSeparatorUpdates.t.sol b/contracts/test/foundry/marketplace/DomainSeparatorUpdates.t.sol index 3936ba5a..c1ed9701 100644 --- a/contracts/test/foundry/marketplace/DomainSeparatorUpdates.t.sol +++ b/contracts/test/foundry/marketplace/DomainSeparatorUpdates.t.sol @@ -2,15 +2,15 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IOwnableTwoSteps } from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; -import { SignatureEOAInvalid } from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; +import {IOwnableTwoSteps} from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; +import {SignatureEOAInvalid} from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { ILooksRareProtocol } from "@hypercerts/marketplace/interfaces/ILooksRareProtocol.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {ILooksRareProtocol} from "@hypercerts/marketplace/interfaces/ILooksRareProtocol.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; contract DomainSeparatorUpdatesTest is ProtocolBase { function setUp() public { @@ -51,9 +51,8 @@ contract DomainSeparatorUpdatesTest is ProtocolBase { vm.prank(_owner); looksRareProtocol.updateDomainSeparator(); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); bytes memory signature = _signMakerOrder(makerAsk, makerUserPK); @@ -62,13 +61,7 @@ contract DomainSeparatorUpdatesTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(SignatureEOAInvalid.selector); - looksRareProtocol.executeTakerBid{ value: makerAsk.price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: makerAsk.price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testCannotTradeIfChainIdHasChanged(uint64 newChainId) public { @@ -79,9 +72,8 @@ contract DomainSeparatorUpdatesTest is ProtocolBase { // ChainId update vm.chainId(newChainId); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); bytes memory signature = _signMakerOrder(makerAsk, makerUserPK); @@ -90,13 +82,7 @@ contract DomainSeparatorUpdatesTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(ILooksRareProtocol.ChainIdInvalid.selector); - looksRareProtocol.executeTakerBid{ value: makerAsk.price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: makerAsk.price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testUpdateDomainSeparatorSameDomainSeparator() public asPrankedUser(_owner) { diff --git a/contracts/test/foundry/marketplace/ExecutionManager.t.sol b/contracts/test/foundry/marketplace/ExecutionManager.t.sol index edc413af..b330d91a 100644 --- a/contracts/test/foundry/marketplace/ExecutionManager.t.sol +++ b/contracts/test/foundry/marketplace/ExecutionManager.t.sol @@ -2,19 +2,27 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IOwnableTwoSteps } from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; +import {IOwnableTwoSteps} from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { IExecutionManager } from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; -import { IStrategyManager } from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {IExecutionManager} from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; +import {IStrategyManager} from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; // Shared errors -import { OrderInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { MAKER_ORDER_INVALID_STANDARD_SALE, STRATEGY_INVALID_QUOTE_TYPE, STRATEGY_INVALID_QUOTE_TYPE, STRATEGY_NOT_ACTIVE, START_TIME_GREATER_THAN_END_TIME, TOO_LATE_TO_EXECUTE_ORDER, TOO_EARLY_TO_EXECUTE_ORDER } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import {OrderInvalid} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import { + MAKER_ORDER_INVALID_STANDARD_SALE, + STRATEGY_INVALID_QUOTE_TYPE, + STRATEGY_INVALID_QUOTE_TYPE, + STRATEGY_NOT_ACTIVE, + START_TIME_GREATER_THAN_END_TIME, + TOO_LATE_TO_EXECUTE_ORDER, + TOO_EARLY_TO_EXECUTE_ORDER +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManager { function setUp() public { @@ -34,7 +42,7 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag } function testUpdateMaxCreatorFeeBp(uint16 newMaxCreatorFeeBp) public asPrankedUser(_owner) { - vm.assume(newMaxCreatorFeeBp <= 2_500); + vm.assume(newMaxCreatorFeeBp <= 2500); vm.expectEmit(true, false, false, true); emit NewMaxCreatorFeeBp(newMaxCreatorFeeBp); looksRareProtocol.updateMaxCreatorFeeBp(newMaxCreatorFeeBp); @@ -43,11 +51,11 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag function testUpdateMaxCreatorFeeBpNotOwner() public { vm.expectRevert(IOwnableTwoSteps.NotOwner.selector); - looksRareProtocol.updateMaxCreatorFeeBp(uint16(2_500)); + looksRareProtocol.updateMaxCreatorFeeBp(uint16(2500)); } function testUpdateMaxCreatorFeeBpTooHigh(uint16 newMaxCreatorFeeBp) public asPrankedUser(_owner) { - vm.assume(newMaxCreatorFeeBp > 2_500); + vm.assume(newMaxCreatorFeeBp > 2500); vm.expectRevert(CreatorFeeBpTooHigh.selector); looksRareProtocol.updateMaxCreatorFeeBp(newMaxCreatorFeeBp); } @@ -75,10 +83,8 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag // Change timestamp to avoid underflow issues vm.warp(timestamp); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); makerBid.startTime = block.timestamp; makerBid.endTime = block.timestamp + 1 seconds; @@ -91,7 +97,7 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag // Maker bid is invalid if its start time is not within 5 minutes into the future vm.warp(makerBid.startTime - 5 minutes - 1 seconds); vm.expectRevert(OutsideOfTimeRange.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCannotValidateOrderIfTooLateToExecute(uint256 timestamp) public asPrankedUser(takerUser) { @@ -99,10 +105,8 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag // Change timestamp to avoid underflow issues vm.warp(timestamp); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); makerBid.startTime = block.timestamp - 1 seconds; makerBid.endTime = block.timestamp; @@ -113,7 +117,7 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag vm.warp(block.timestamp + 1 seconds); vm.expectRevert(OutsideOfTimeRange.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCannotValidateOrderIfStartTimeLaterThanEndTime(uint256 timestamp) public asPrankedUser(takerUser) { @@ -121,10 +125,8 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag // Change timestamp to avoid underflow issues vm.warp(timestamp); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); makerBid.startTime = block.timestamp + 1 seconds; makerBid.endTime = block.timestamp; @@ -133,14 +135,12 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag _assertMakerOrderReturnValidationCode(makerBid, signature, START_TIME_GREATER_THAN_END_TIME); vm.expectRevert(OutsideOfTimeRange.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCannotValidateOrderIfMakerBidItemIdsIsEmpty() public { - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); uint256[] memory itemIds = new uint256[](0); makerBid.itemIds = itemIds; @@ -149,18 +149,17 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag _assertMakerOrderReturnValidationCode(makerBid, signature, MAKER_ORDER_INVALID_STANDARD_SALE); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } - function testCannotValidateOrderIfMakerBidItemIdsLengthMismatch( - uint256 makerBidItemIdsLength - ) public asPrankedUser(takerUser) { + function testCannotValidateOrderIfMakerBidItemIdsLengthMismatch(uint256 makerBidItemIdsLength) + public + asPrankedUser(takerUser) + { vm.assume(makerBidItemIdsLength > 1 && makerBidItemIdsLength < 100_000); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); uint256[] memory itemIds = new uint256[](makerBidItemIdsLength); makerBid.itemIds = itemIds; @@ -169,15 +168,14 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag _assertMakerOrderReturnValidationCode(makerBid, signature, MAKER_ORDER_INVALID_STANDARD_SALE); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCannotValidateOrderIfMakerAskItemIdsIsEmpty() public asPrankedUser(takerUser) { vm.deal(takerUser, 100 ether); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); // Change maker itemIds array to make its length equal to 0 uint256[] memory itemIds = new uint256[](0); @@ -187,25 +185,19 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag _assertMakerOrderReturnValidationCode(makerAsk, signature, MAKER_ORDER_INVALID_STANDARD_SALE); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerBid{ value: makerAsk.price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: makerAsk.price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } - function testCannotValidateOrderIfMakerAskItemIdsLengthMismatch( - uint256 makerAskItemIdsLength - ) public asPrankedUser(takerUser) { + function testCannotValidateOrderIfMakerAskItemIdsLengthMismatch(uint256 makerAskItemIdsLength) + public + asPrankedUser(takerUser) + { vm.deal(takerUser, 100 ether); vm.assume(makerAskItemIdsLength > 1 && makerAskItemIdsLength < 100_000); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); uint256[] memory itemIds = new uint256[](makerAskItemIdsLength); makerAsk.itemIds = itemIds; @@ -214,13 +206,7 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag _assertMakerOrderReturnValidationCode(makerAsk, signature, MAKER_ORDER_INVALID_STANDARD_SALE); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerBid{ value: makerAsk.price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: makerAsk.price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } // TODO check is we need this test and replace the chainlink floor strategy @@ -255,7 +241,7 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag // vm.prank(takerUser); // vm.expectRevert(IExecutionManager.NoSelectorForStrategy.selector); // looksRareProtocol.executeTakerBid{value: makerAsk.price}( - // takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE + // takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE // ); // } @@ -291,6 +277,6 @@ contract ExecutionManagerTest is ProtocolBase, IExecutionManager, IStrategyManag // vm.prank(takerUser); // vm.expectRevert(IExecutionManager.NoSelectorForStrategy.selector); - // looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + // looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // } } diff --git a/contracts/test/foundry/marketplace/GasGriefing.t.sol b/contracts/test/foundry/marketplace/GasGriefing.t.sol index 31852b5a..b973ddff 100644 --- a/contracts/test/foundry/marketplace/GasGriefing.t.sol +++ b/contracts/test/foundry/marketplace/GasGriefing.t.sol @@ -2,21 +2,21 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { WETH } from "solmate/src/tokens/WETH.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {WETH} from "solmate/src/tokens/WETH.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Mocks and other utils -import { GasGriefer } from "./utils/GasGriefer.sol"; +import {GasGriefer} from "./utils/GasGriefer.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract GasGriefingTest is ProtocolBase { uint256 private constant price = 1 ether; // Fixed price of sale @@ -36,9 +36,8 @@ contract GasGriefingTest is ProtocolBase { function testTakerBidGasGriefing() public { _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.signer = gasGriefer; // Mint asset @@ -56,13 +55,7 @@ contract GasGriefingTest is ProtocolBase { vm.prank(takerUser); // Execute taker bid transaction - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(makerAsk.itemIds[0]), takerUser); @@ -122,13 +115,8 @@ contract GasGriefingTest is ProtocolBase { vm.prank(takerUser); // Execute taker bid transaction - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); for (uint256 i; i < numberPurchases; i++) { diff --git a/contracts/test/foundry/marketplace/InitialStates.t.sol b/contracts/test/foundry/marketplace/InitialStates.t.sol index c17f827b..5817a403 100644 --- a/contracts/test/foundry/marketplace/InitialStates.t.sol +++ b/contracts/test/foundry/marketplace/InitialStates.t.sol @@ -2,10 +2,10 @@ pragma solidity 0.8.17; // Interfaces -import { IStrategyManager } from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; +import {IStrategyManager} from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; contract InitialStatesTest is ProtocolBase, IStrategyManager { function setUp() public { diff --git a/contracts/test/foundry/marketplace/LooksRareProtocol.t.sol b/contracts/test/foundry/marketplace/LooksRareProtocol.t.sol index 73027c4b..5f685cec 100644 --- a/contracts/test/foundry/marketplace/LooksRareProtocol.t.sol +++ b/contracts/test/foundry/marketplace/LooksRareProtocol.t.sol @@ -2,24 +2,33 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IOwnableTwoSteps } from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; +import {IOwnableTwoSteps} from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Shared errors -import { AmountInvalid, CallerInvalid, CurrencyInvalid, OrderInvalid, QuoteTypeInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { CURRENCY_NOT_ALLOWED, MAKER_ORDER_INVALID_STANDARD_SALE } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + AmountInvalid, + CallerInvalid, + CurrencyInvalid, + OrderInvalid, + QuoteTypeInvalid +} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import { + CURRENCY_NOT_ALLOWED, + MAKER_ORDER_INVALID_STANDARD_SALE +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Other mocks and utils -import { MockERC20 } from "../../mock/MockERC20.sol"; +import {MockERC20} from "../../mock/MockERC20.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract LooksRareProtocolTest is ProtocolBase { // Fixed price of sale @@ -37,9 +46,8 @@ contract LooksRareProtocolTest is ProtocolBase { function testCannotTradeIfInvalidAmounts() public { _setUpUsers(); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); // Mint asset mockERC721.mint(makerUser, makerAsk.itemIds[0]); @@ -54,13 +62,7 @@ contract LooksRareProtocolTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // 2. Amount > 1 for ERC721 makerAsk.amounts[0] = 2; @@ -72,21 +74,14 @@ contract LooksRareProtocolTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testCannotTradeIfCurrencyInvalid() public { _setUpUsers(); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.currency = address(mockERC20); // Mint asset @@ -100,13 +95,7 @@ contract LooksRareProtocolTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(CurrencyInvalid.selector); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); OrderStructs.Maker[] memory makerAsks = new OrderStructs.Maker[](1); OrderStructs.Taker[] memory takerBids = new OrderStructs.Taker[](1); @@ -119,32 +108,28 @@ contract LooksRareProtocolTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(CurrencyInvalid.selector); - looksRareProtocol.executeMultipleTakerBids{ value: price }( + looksRareProtocol.executeMultipleTakerBids{value: price}( takerBids, makerAsks, signatures, merkleTrees, - _EMPTY_AFFILIATE, true // Atomic ); vm.prank(takerUser); vm.expectRevert(CurrencyInvalid.selector); - looksRareProtocol.executeMultipleTakerBids{ value: price }( + looksRareProtocol.executeMultipleTakerBids{value: price}( takerBids, makerAsks, signatures, merkleTrees, - _EMPTY_AFFILIATE, false // Non-atomic ); } function testCannotTradeIfETHIsUsedForMakerBid() public { - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - ETH - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), ETH); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -158,27 +143,24 @@ contract LooksRareProtocolTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); vm.expectRevert(CurrencyInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCannotTradeIfInvalidQuoteType() public { // 1. QuoteType = BID but executeTakerBid - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); vm.prank(takerUser); vm.expectRevert(QuoteTypeInvalid.selector); - looksRareProtocol.executeTakerBid(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // 2. QuoteType = ASK but executeTakerAsk - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.currency = address(weth); // Sign order @@ -186,7 +168,7 @@ contract LooksRareProtocolTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(QuoteTypeInvalid.selector); - looksRareProtocol.executeTakerAsk(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testUpdateETHGasLimitForTransfer() public asPrankedUser(_owner) { @@ -197,7 +179,7 @@ contract LooksRareProtocolTest is ProtocolBase { } function testUpdateETHGasLimitForTransferRevertsIfTooLow() public asPrankedUser(_owner) { - uint256 newGasLimitETHTransfer = 2_300; + uint256 newGasLimitETHTransfer = 2300; vm.expectRevert(NewGasLimitETHTransferTooLow.selector); looksRareProtocol.updateETHGasLimitForTransfer(newGasLimitETHTransfer - 1); @@ -213,9 +195,8 @@ contract LooksRareProtocolTest is ProtocolBase { function testCannotCallRestrictedExecuteTakerBid() public { _setUpUsers(); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); // Mint asset mockERC721.mint(makerUser, makerAsk.itemIds[0]); @@ -280,13 +261,8 @@ contract LooksRareProtocolTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(CurrencyInvalid.selector); - looksRareProtocol.executeMultipleTakerBids{ value: price }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - isAtomic + looksRareProtocol.executeMultipleTakerBids{value: price}( + takerBids, makerAsks, signatures, merkleTrees, isAtomic ); } } diff --git a/contracts/test/foundry/marketplace/NonceInvalidation.t.sol b/contracts/test/foundry/marketplace/NonceInvalidation.t.sol index 594ec13a..ae497f79 100644 --- a/contracts/test/foundry/marketplace/NonceInvalidation.t.sol +++ b/contracts/test/foundry/marketplace/NonceInvalidation.t.sol @@ -2,18 +2,24 @@ pragma solidity 0.8.17; // Libraries, interfaces, errors -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { INonceManager } from "@hypercerts/marketplace/interfaces/INonceManager.sol"; -import { LengthsInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { INVALID_USER_GLOBAL_BID_NONCE, INVALID_USER_GLOBAL_ASK_NONCE, USER_SUBSET_NONCE_CANCELLED, USER_ORDER_NONCE_IN_EXECUTION_WITH_OTHER_HASH, USER_ORDER_NONCE_EXECUTED_OR_CANCELLED } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {INonceManager} from "@hypercerts/marketplace/interfaces/INonceManager.sol"; +import {LengthsInvalid} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import { + INVALID_USER_GLOBAL_BID_NONCE, + INVALID_USER_GLOBAL_ASK_NONCE, + USER_SUBSET_NONCE_CANCELLED, + USER_ORDER_NONCE_IN_EXECUTION_WITH_OTHER_HASH, + USER_ORDER_NONCE_EXECUTED_OR_CANCELLED +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Other utils and tests -import { StrategyTestMultiFillCollectionOrder } from "./utils/StrategyTestMultiFillCollectionOrder.sol"; -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {StrategyTestMultiFillCollectionOrder} from "./utils/StrategyTestMultiFillCollectionOrder.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract NonceInvalidationTest is INonceManager, ProtocolBase { uint256 private constant price = 1 ether; // Fixed price of sale @@ -31,9 +37,8 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { // Mint asset mockERC721.mint(makerUser, itemId); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.subsetNonce = subsetNonce; // Sign order @@ -55,20 +60,14 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { // Taker user actions vm.prank(takerUser); vm.expectRevert(NoncesInvalid.selector); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } /** * Cannot execute an order if maker is at a different global ask nonce than signed */ function testCannotExecuteOrderIfInvalidUserGlobalAskNonce(uint256 userGlobalAskNonce) public { - uint256 quasiRandomNumber = 54570651553685478358117286254199992264; + uint256 quasiRandomNumber = 54_570_651_553_685_478_358_117_286_254_199_992_264; vm.assume(userGlobalAskNonce < quasiRandomNumber); // Change block number vm.roll(1); @@ -81,9 +80,8 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { emit NewBidAskNonces(makerUser, 0, newAskNonce); looksRareProtocol.incrementBidAskNonces(false, true); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); // Mint asset mockERC721.mint(makerUser, makerAsk.itemIds[0]); @@ -99,20 +97,14 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { // Taker user actions vm.prank(takerUser); vm.expectRevert(NoncesInvalid.selector); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } /** * Cannot execute an order if maker is at a different global bid nonce than signed */ function testCannotExecuteOrderIfInvalidUserGlobalBidNonce(uint256 userGlobalBidNonce) public { - uint256 quasiRandomNumber = 54570651553685478358117286254199992264; + uint256 quasiRandomNumber = 54_570_651_553_685_478_358_117_286_254_199_992_264; vm.assume(userGlobalBidNonce < quasiRandomNumber); // Change block number vm.roll(1); @@ -153,13 +145,7 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { // Taker user actions vm.prank(takerUser); vm.expectRevert(NoncesInvalid.selector); - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBid, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBid, signature, _EMPTY_MERKLE_TREE); } /** @@ -169,10 +155,8 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { _setUpUsers(); _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -184,13 +168,13 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { vm.startPrank(takerUser); { - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertMakerOrderReturnValidationCode(makerBid, signature, USER_ORDER_NONCE_EXECUTED_OR_CANCELLED); // Second one fails vm.expectRevert(NoncesInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } vm.stopPrank(); @@ -205,7 +189,8 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { // 0. Add the new strategy bytes4 selector = StrategyTestMultiFillCollectionOrder.executeStrategyWithTakerAsk.selector; - StrategyTestMultiFillCollectionOrder strategyMultiFillCollectionOrder = new StrategyTestMultiFillCollectionOrder( + StrategyTestMultiFillCollectionOrder strategyMultiFillCollectionOrder = + new StrategyTestMultiFillCollectionOrder( address(looksRareProtocol) ); @@ -253,7 +238,7 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { vm.prank(takerUser); // Execute taker ask transaction - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } // 2. Second maker order is signed sharing the same order nonce as the first one @@ -287,16 +272,14 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { _assertMakerOrderReturnValidationCode(makerBid, signature, USER_ORDER_NONCE_IN_EXECUTION_WITH_OTHER_HASH); // Prepare the taker ask - OrderStructs.Taker memory takerAsk = OrderStructs.Taker( - takerUser, - abi.encode(new uint256[](0), new uint256[](0)) - ); + OrderStructs.Taker memory takerAsk = + OrderStructs.Taker(takerUser, abi.encode(new uint256[](0), new uint256[](0))); vm.prank(takerUser); // Second one fails when a taker user tries to execute vm.expectRevert(NoncesInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } } @@ -352,14 +335,12 @@ contract NonceInvalidationTest is INonceManager, ProtocolBase { mockERC721.mint(takerUser, itemId); // Prepare the taker ask - OrderStructs.Taker memory takerAsk = OrderStructs.Taker( - takerUser, - abi.encode(new uint256[](0), new uint256[](0)) - ); + OrderStructs.Taker memory takerAsk = + OrderStructs.Taker(takerUser, abi.encode(new uint256[](0), new uint256[](0))); vm.prank(takerUser); vm.expectRevert(NoncesInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testCancelNoncesRevertIfEmptyArrays() public { diff --git a/contracts/test/foundry/marketplace/OrderValidatorV2A.t.sol b/contracts/test/foundry/marketplace/OrderValidatorV2A.t.sol index 604c9006..ca9a5c9c 100644 --- a/contracts/test/foundry/marketplace/OrderValidatorV2A.t.sol +++ b/contracts/test/foundry/marketplace/OrderValidatorV2A.t.sol @@ -1,35 +1,49 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { LooksRareProtocol } from "@hypercerts/marketplace/LooksRareProtocol.sol"; -import { TransferManager } from "@hypercerts/marketplace/TransferManager.sol"; -import { CreatorFeeManagerWithRoyalties } from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; +import {LooksRareProtocol} from "@hypercerts/marketplace/LooksRareProtocol.sol"; +import {TransferManager} from "@hypercerts/marketplace/TransferManager.sol"; +import {CreatorFeeManagerWithRoyalties} from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; -import { OrderValidatorV2A } from "@hypercerts/marketplace/helpers/OrderValidatorV2A.sol"; +import {OrderValidatorV2A} from "@hypercerts/marketplace/helpers/OrderValidatorV2A.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Shared errors -import { ERC20_APPROVAL_INFERIOR_TO_PRICE, ERC721_ITEM_ID_NOT_IN_BALANCE, ERC721_NO_APPROVAL_FOR_ALL_OR_ITEM_ID, ERC1155_BALANCE_OF_DOES_NOT_EXIST, ERC1155_BALANCE_OF_ITEM_ID_INFERIOR_TO_AMOUNT, ERC1155_IS_APPROVED_FOR_ALL_DOES_NOT_EXIST, ERC1155_NO_APPROVAL_FOR_ALL, MAKER_ORDER_INVALID_STANDARD_SALE, MISSING_IS_VALID_SIGNATURE_FUNCTION_EIP1271, POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC721, POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC1155, STRATEGY_NOT_IMPLEMENTED, TRANSFER_MANAGER_APPROVAL_REVOKED_BY_OWNER_FOR_EXCHANGE } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + ERC20_APPROVAL_INFERIOR_TO_PRICE, + ERC721_ITEM_ID_NOT_IN_BALANCE, + ERC721_NO_APPROVAL_FOR_ALL_OR_ITEM_ID, + ERC1155_BALANCE_OF_DOES_NOT_EXIST, + ERC1155_BALANCE_OF_ITEM_ID_INFERIOR_TO_AMOUNT, + ERC1155_IS_APPROVED_FOR_ALL_DOES_NOT_EXIST, + ERC1155_NO_APPROVAL_FOR_ALL, + MAKER_ORDER_INVALID_STANDARD_SALE, + MISSING_IS_VALID_SIGNATURE_FUNCTION_EIP1271, + POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC721, + POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC1155, + STRATEGY_NOT_IMPLEMENTED, + TRANSFER_MANAGER_APPROVAL_REVOKED_BY_OWNER_FOR_EXCHANGE +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Utils -import { TestParameters } from "./utils/TestParameters.sol"; +import {TestParameters} from "./utils/TestParameters.sol"; // Mocks -import { MockRoyaltyFeeRegistry } from "../../mock/MockRoyaltyFeeRegistry.sol"; -import { MockERC721 } from "../../mock/MockERC721.sol"; -import { MockERC1155 } from "../../mock/MockERC1155.sol"; -import { MockERC1155WithoutBalanceOfBatch } from "../../mock/MockERC1155WithoutBalanceOfBatch.sol"; -import { MockERC1155WithoutAnyBalanceOf } from "../../mock/MockERC1155WithoutAnyBalanceOf.sol"; -import { MockERC1155WithoutIsApprovedForAll } from "../../mock/MockERC1155WithoutIsApprovedForAll.sol"; -import { MockERC721SupportsNoInterface } from "../../mock/MockERC721SupportsNoInterface.sol"; -import { MockERC1155SupportsNoInterface } from "../../mock/MockERC1155SupportsNoInterface.sol"; -import { MockERC20 } from "../../mock/MockERC20.sol"; +import {MockRoyaltyFeeRegistry} from "../../mock/MockRoyaltyFeeRegistry.sol"; +import {MockERC721} from "../../mock/MockERC721.sol"; +import {MockERC1155} from "../../mock/MockERC1155.sol"; +import {MockERC1155WithoutBalanceOfBatch} from "../../mock/MockERC1155WithoutBalanceOfBatch.sol"; +import {MockERC1155WithoutAnyBalanceOf} from "../../mock/MockERC1155WithoutAnyBalanceOf.sol"; +import {MockERC1155WithoutIsApprovedForAll} from "../../mock/MockERC1155WithoutIsApprovedForAll.sol"; +import {MockERC721SupportsNoInterface} from "../../mock/MockERC721SupportsNoInterface.sol"; +import {MockERC1155SupportsNoInterface} from "../../mock/MockERC1155SupportsNoInterface.sol"; +import {MockERC20} from "../../mock/MockERC20.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; /** * @dev Not everything is tested in this file. Most tests live in other files @@ -73,18 +87,15 @@ contract OrderValidatorV2ATest is TestParameters { ); assertEq(address(orderValidator.creatorFeeManager()), address(creatorFeeManager)); - assertEq(orderValidator.maxCreatorFeeBp(), 1_000); + assertEq(orderValidator.maxCreatorFeeBp(), 1000); } function testMakerAskStrategyNotImplemented() public { OrderStructs.Maker memory makerAsk; makerAsk.quoteType = QuoteType.Ask; makerAsk.strategyId = 1; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[0], STRATEGY_NOT_IMPLEMENTED); } @@ -95,11 +106,8 @@ contract OrderValidatorV2ATest is TestParameters { looksRareProtocol.updateCurrencyStatus(currency, true); makerBid.currency = currency; makerBid.strategyId = 1; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerBid, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerBid, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[0], STRATEGY_NOT_IMPLEMENTED); } @@ -120,11 +128,8 @@ contract OrderValidatorV2ATest is TestParameters { transferManager.removeOperator(operators[0]); - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[7], TRANSFER_MANAGER_APPROVAL_REVOKED_BY_OWNER_FOR_EXCHANGE); } @@ -133,11 +138,8 @@ contract OrderValidatorV2ATest is TestParameters { makerAsk.quoteType = QuoteType.Ask; makerAsk.collectionType = CollectionType.ERC721; makerAsk.collection = address(new MockERC721SupportsNoInterface()); - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[6], POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC721); } @@ -146,11 +148,8 @@ contract OrderValidatorV2ATest is TestParameters { makerBid.quoteType = QuoteType.Bid; makerBid.collectionType = CollectionType.ERC721; makerBid.collection = address(new MockERC721SupportsNoInterface()); - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerBid, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerBid, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[6], POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC721); } @@ -173,11 +172,8 @@ contract OrderValidatorV2ATest is TestParameters { uint256[] memory amounts = new uint256[](1); amounts[0] = amount; makerBid.amounts = amounts; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerBid, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerBid, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[1], MAKER_ORDER_INVALID_STANDARD_SALE); } @@ -188,11 +184,8 @@ contract OrderValidatorV2ATest is TestParameters { makerBid.signer = address(this); makerBid.collectionType = CollectionType.ERC721; makerBid.collection = address(new MockERC721()); - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerBid, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerBid, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[3], MISSING_IS_VALID_SIGNATURE_FUNCTION_EIP1271); } @@ -200,11 +193,8 @@ contract OrderValidatorV2ATest is TestParameters { OrderStructs.Maker memory makerAsk; makerAsk.collectionType = CollectionType.ERC1155; makerAsk.collection = address(new MockERC1155SupportsNoInterface()); - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[6], POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC1155); } @@ -213,11 +203,8 @@ contract OrderValidatorV2ATest is TestParameters { makerBid.quoteType = QuoteType.Bid; makerBid.collectionType = CollectionType.ERC1155; makerBid.collection = address(new MockERC1155SupportsNoInterface()); - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerBid, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerBid, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[6], POTENTIAL_INVALID_COLLECTION_TYPE_SHOULD_BE_ERC1155); } @@ -238,11 +225,8 @@ contract OrderValidatorV2ATest is TestParameters { mockERC20.approve(address(orderValidator.looksRareProtocol()), makerBid.price - 1 wei); vm.stopPrank(); - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerBid, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerBid, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[5], ERC20_APPROVAL_INFERIOR_TO_PRICE); } @@ -272,11 +256,8 @@ contract OrderValidatorV2ATest is TestParameters { amounts[1] = 1; makerAsk.amounts = amounts; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[5], ERC721_NO_APPROVAL_FOR_ALL_OR_ITEM_ID); } @@ -292,11 +273,8 @@ contract OrderValidatorV2ATest is TestParameters { uint256[] memory itemIds = new uint256[](1); makerAsk.itemIds = itemIds; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[5], ERC721_ITEM_ID_NOT_IN_BALANCE); } @@ -331,11 +309,8 @@ contract OrderValidatorV2ATest is TestParameters { amounts[0] = 1; makerAsk.amounts = amounts; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[5], ERC1155_BALANCE_OF_ITEM_ID_INFERIOR_TO_AMOUNT); } @@ -354,17 +329,14 @@ contract OrderValidatorV2ATest is TestParameters { amounts[0] = 1; makerAsk.amounts = amounts; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[5], ERC1155_BALANCE_OF_DOES_NOT_EXIST); } function testMakerAskERC1155IsApprovedForAllDoesNotExist() public { MockERC1155WithoutIsApprovedForAll mockERC1155 = new MockERC1155WithoutIsApprovedForAll(); - mockERC1155.mint({ to: makerUser, tokenId: 0, amount: 1 }); + mockERC1155.mint({to: makerUser, tokenId: 0, amount: 1}); OrderStructs.Maker memory makerAsk; makerAsk.quoteType = QuoteType.Ask; @@ -378,17 +350,14 @@ contract OrderValidatorV2ATest is TestParameters { amounts[0] = 1; makerAsk.amounts = amounts; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[5], ERC1155_IS_APPROVED_FOR_ALL_DOES_NOT_EXIST); } function testMakerAskERC1155IsApprovedForAllReturnsFalse() public { MockERC1155 mockERC1155 = new MockERC1155(); - mockERC1155.mint({ to: makerUser, tokenId: 0, amount: 1 }); + mockERC1155.mint({to: makerUser, tokenId: 0, amount: 1}); OrderStructs.Maker memory makerAsk; makerAsk.quoteType = QuoteType.Ask; @@ -402,11 +371,8 @@ contract OrderValidatorV2ATest is TestParameters { amounts[0] = 1; makerAsk.amounts = amounts; - uint256[9] memory validationCodes = orderValidator.checkMakerOrderValidity( - makerAsk, - new bytes(65), - _EMPTY_MERKLE_TREE - ); + uint256[9] memory validationCodes = + orderValidator.checkMakerOrderValidity(makerAsk, new bytes(65), _EMPTY_MERKLE_TREE); assertEq(validationCodes[5], ERC1155_NO_APPROVAL_FOR_ALL); } } diff --git a/contracts/test/foundry/marketplace/ProtocolBase.t.sol b/contracts/test/foundry/marketplace/ProtocolBase.t.sol index 92b090fd..8c3cee4b 100644 --- a/contracts/test/foundry/marketplace/ProtocolBase.t.sol +++ b/contracts/test/foundry/marketplace/ProtocolBase.t.sol @@ -2,28 +2,28 @@ pragma solidity >=0.8.7; // WETH -import { WETH } from "solmate/src/tokens/WETH.sol"; +import {WETH} from "solmate/src/tokens/WETH.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Core contracts -import { LooksRareProtocol, ILooksRareProtocol } from "@hypercerts/marketplace/LooksRareProtocol.sol"; -import { TransferManager } from "@hypercerts/marketplace/TransferManager.sol"; -import { ProtocolFeeRecipient } from "@hypercerts/marketplace/ProtocolFeeRecipient.sol"; +import {LooksRareProtocol, ILooksRareProtocol} from "@hypercerts/marketplace/LooksRareProtocol.sol"; +import {TransferManager} from "@hypercerts/marketplace/TransferManager.sol"; +import {ProtocolFeeRecipient} from "@hypercerts/marketplace/ProtocolFeeRecipient.sol"; // Other contracts -import { OrderValidatorV2A } from "@hypercerts/marketplace/helpers/OrderValidatorV2A.sol"; +import {OrderValidatorV2A} from "@hypercerts/marketplace/helpers/OrderValidatorV2A.sol"; // Mock files -import { MockERC20 } from "../../mock/MockERC20.sol"; -import { MockERC721 } from "../../mock/MockERC721.sol"; -import { MockERC721WithRoyalties } from "../../mock/MockERC721WithRoyalties.sol"; -import { MockERC1155 } from "../../mock/MockERC1155.sol"; -import { MockRoyaltyFeeRegistry } from "../../mock/MockRoyaltyFeeRegistry.sol"; +import {MockERC20} from "../../mock/MockERC20.sol"; +import {MockERC721} from "../../mock/MockERC721.sol"; +import {MockERC721WithRoyalties} from "../../mock/MockERC721WithRoyalties.sol"; +import {MockERC1155} from "../../mock/MockERC1155.sol"; +import {MockRoyaltyFeeRegistry} from "../../mock/MockRoyaltyFeeRegistry.sol"; // Utils -import { MockOrderGenerator } from "./utils/MockOrderGenerator.sol"; +import {MockOrderGenerator} from "./utils/MockOrderGenerator.sol"; contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { address[] public operators; @@ -73,11 +73,8 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { OrderStructs.MerkleTree[] memory merkleTrees = new OrderStructs.MerkleTree[](1); merkleTrees[0] = merkleTree; - uint256[9][] memory validationCodes = orderValidator.checkMultipleMakerOrderValidities( - makerOrders, - signatures, - merkleTrees - ); + uint256[9][] memory validationCodes = + orderValidator.checkMultipleMakerOrderValidities(makerOrders, signatures, merkleTrees); uint256 index = expectedValidationCode / 100; assertEq(validationCodes[0][index - 1], expectedValidationCode); @@ -109,11 +106,8 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { OrderStructs.MerkleTree[] memory merkleTrees = new OrderStructs.MerkleTree[](1); merkleTrees[0] = merkleTree; - uint256[9][] memory validationCodes = orderValidator.checkMultipleMakerOrderValidities( - makerOrders, - signatures, - merkleTrees - ); + uint256[9][] memory validationCodes = + orderValidator.checkMultipleMakerOrderValidities(makerOrders, signatures, merkleTrees); _assertValidationCodesAllZeroes(validationCodes); } @@ -138,7 +132,7 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { // Receive ETH and WETH vm.deal(user, _initialETHBalanceUser + _initialWETHBalanceUser); - weth.deposit{ value: _initialWETHBalanceUser }(); + weth.deposit{value: _initialWETHBalanceUser}(); } function _setUpUsers() internal { @@ -149,10 +143,7 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { function _setupRegistryRoyalties(address collection, uint256 standardRoyaltyFee) internal { vm.prank(royaltyFeeRegistry.owner()); royaltyFeeRegistry.updateRoyaltyInfoForCollection( - collection, - _royaltyRecipient, - _royaltyRecipient, - standardRoyaltyFee + collection, _royaltyRecipient, _royaltyRecipient, standardRoyaltyFee ); } @@ -188,13 +179,13 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { // Distribute ETH and WETH to protocol owner vm.deal(_owner, _initialETHBalanceOwner + _initialWETHBalanceOwner); - weth.deposit{ value: _initialWETHBalanceOwner }(); + weth.deposit{value: _initialWETHBalanceOwner}(); vm.stopPrank(); // Distribute ETH and WETH to royalty recipient vm.deal(_royaltyRecipient, _initialETHBalanceRoyaltyRecipient + _initialWETHBalanceRoyaltyRecipient); vm.startPrank(_royaltyRecipient); - weth.deposit{ value: _initialWETHBalanceRoyaltyRecipient }(); + weth.deposit{value: _initialWETHBalanceRoyaltyRecipient}(); vm.stopPrank(); } @@ -204,12 +195,7 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { function _addStrategy(address strategy, bytes4 selector, bool isMakerBid) internal { looksRareProtocol.addStrategy( - _standardProtocolFeeBp, - _minTotalFeeBp, - _maxProtocolFeeBp, - selector, - isMakerBid, - strategy + _standardProtocolFeeBp, _minTotalFeeBp, _maxProtocolFeeBp, selector, isMakerBid, strategy ); } @@ -251,16 +237,14 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { OrderStructs.Taker calldata takerAsk, OrderStructs.Maker calldata makerBid, bytes calldata makerSignature, - OrderStructs.MerkleTree calldata merkleTree, - address affiliate + OrderStructs.MerkleTree calldata merkleTree ) external {} function executeTakerBid( OrderStructs.Taker calldata takerBid, OrderStructs.Maker calldata makerAsk, bytes calldata makerSignature, - OrderStructs.MerkleTree calldata merkleTree, - address affiliate + OrderStructs.MerkleTree calldata merkleTree ) external payable {} function executeMultipleTakerBids( @@ -268,7 +252,6 @@ contract ProtocolBase is MockOrderGenerator, ILooksRareProtocol { OrderStructs.Maker[] calldata makerAsks, bytes[] calldata makerSignatures, OrderStructs.MerkleTree[] calldata merkleTrees, - address affiliate, bool isAtomic ) external payable {} } diff --git a/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol b/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol index 36f370df..a161feaf 100644 --- a/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol +++ b/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol @@ -2,15 +2,15 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IERC20 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC20.sol"; -import { IWETH } from "@looksrare/contracts-libs/contracts/interfaces/generic/IWETH.sol"; +import {IERC20} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC20.sol"; +import {IWETH} from "@looksrare/contracts-libs/contracts/interfaces/generic/IWETH.sol"; // Core contracts -import { ProtocolFeeRecipient } from "@hypercerts/marketplace/ProtocolFeeRecipient.sol"; +import {ProtocolFeeRecipient} from "@hypercerts/marketplace/ProtocolFeeRecipient.sol"; // Other mocks and utils -import { MockERC20 } from "../../mock/MockERC20.sol"; -import { TestParameters } from "./utils/TestParameters.sol"; +import {MockERC20} from "../../mock/MockERC20.sol"; +import {TestParameters} from "./utils/TestParameters.sol"; contract ProtocolFeeRecipientTest is TestParameters { ProtocolFeeRecipient private protocolFeeRecipient; @@ -47,8 +47,7 @@ contract ProtocolFeeRecipientTest is TestParameters { assertEq(address(protocolFeeRecipient).balance, 0); assertEq(IERC20(WETH_MAINNET).balanceOf(address(protocolFeeRecipient)), 0); assertEq( - IERC20(WETH_MAINNET).balanceOf(FEE_SHARING_SETTER), - feeSharingSetterInitialWETHBalance + 1 ether + DUST + IERC20(WETH_MAINNET).balanceOf(FEE_SHARING_SETTER), feeSharingSetterInitialWETHBalance + 1 ether + DUST ); } @@ -98,13 +97,13 @@ contract ProtocolFeeRecipientTest is TestParameters { } function _sendETHToProtocolFeeRecipient() private { - (bool success, ) = address(protocolFeeRecipient).call{ value: 1 ether }(""); + (bool success,) = address(protocolFeeRecipient).call{value: 1 ether}(""); assertTrue(success); assertEq(address(protocolFeeRecipient).balance, 1 ether); } function _sendWETHToProtocolFeeRecipient() private { - IWETH(WETH_MAINNET).deposit{ value: DUST }(); + IWETH(WETH_MAINNET).deposit{value: DUST}(); IERC20(WETH_MAINNET).transfer(address(protocolFeeRecipient), DUST); assertEq(IERC20(WETH_MAINNET).balanceOf(address(protocolFeeRecipient)), DUST); } diff --git a/contracts/test/foundry/marketplace/Sandbox.t.sol b/contracts/test/foundry/marketplace/Sandbox.t.sol index 6e2a3e36..9a349fd5 100644 --- a/contracts/test/foundry/marketplace/Sandbox.t.sol +++ b/contracts/test/foundry/marketplace/Sandbox.t.sol @@ -2,18 +2,18 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IERC721 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC721.sol"; -import { IERC1155 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC1155.sol"; +import {IERC721} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC721.sol"; +import {IERC1155} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC1155.sol"; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract SandboxTest is ProtocolBase { error ERC721TransferFromFail(); @@ -25,12 +25,12 @@ contract SandboxTest is ProtocolBase { address private constant SANDBOX = 0xa342f5D851E866E18ff98F351f2c6637f4478dB5; // Forked block number to run the tests - uint256 private constant FORKED_BLOCK_NUMBER = 16268000; + uint256 private constant FORKED_BLOCK_NUMBER = 16_268_000; function _transferItemIdToUser(address user) private returns (uint256 itemId) { // @dev This user had 23 of the itemId at the forked block number address ownerOfItemId = 0x7A9fe22691c811ea339D9B73150e6911a5343DcA; - itemId = 55464657044963196816950587289035428064568320970692304673817341489688428423171; + itemId = 55_464_657_044_963_196_816_950_587_289_035_428_064_568_320_970_692_304_673_817_341_489_688_428_423_171; vm.prank(ownerOfItemId); IERC1155(SANDBOX).safeTransferFrom(ownerOfItemId, user, itemId, 23, ""); } @@ -79,7 +79,7 @@ contract SandboxTest is ProtocolBase { // It should fail with collectionType = 0 vm.expectRevert(abi.encodeWithSelector(ERC721TransferFromFail.selector)); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Adjust the collection type and sign order again makerBid.collectionType = CollectionType.ERC1155; @@ -87,7 +87,7 @@ contract SandboxTest is ProtocolBase { // It shouldn't fail with collectionType = 0 vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Maker user has received the Sandbox asset assertEq(IERC1155(SANDBOX).balanceOf(makerUser, itemId), makerBid.amounts[0]); @@ -126,13 +126,7 @@ contract SandboxTest is ProtocolBase { // It should fail with collectionType = 0 vm.expectRevert(abi.encodeWithSelector(ERC721TransferFromFail.selector)); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Adjust the collection type and sign order again makerAsk.collectionType = CollectionType.ERC1155; @@ -140,13 +134,7 @@ contract SandboxTest is ProtocolBase { // It shouldn't fail with collectionType = 0 vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Taker user has received the Sandbox asset assertEq(IERC1155(SANDBOX).balanceOf(takerUser, itemId), makerAsk.amounts[0]); diff --git a/contracts/test/foundry/marketplace/SignaturesEIP2098.t.sol b/contracts/test/foundry/marketplace/SignaturesEIP2098.t.sol index 9a480b0f..ea02561a 100644 --- a/contracts/test/foundry/marketplace/SignaturesEIP2098.t.sol +++ b/contracts/test/foundry/marketplace/SignaturesEIP2098.t.sol @@ -3,17 +3,17 @@ pragma solidity 0.8.17; // Libraries, interfaces, errors import "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract SignaturesEIP2098Test is ProtocolBase { function setUp() public { @@ -26,7 +26,7 @@ contract SignaturesEIP2098Test is ProtocolBase { _setUpUsers(); _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); - (OrderStructs.Maker memory makerAsk, ) = _createMockMakerAskAndTakerBid(address(mockERC721)); + (OrderStructs.Maker memory makerAsk,) = _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.price = price; makerAsk.itemIds[0] = itemId; @@ -48,7 +48,7 @@ contract SignaturesEIP2098Test is ProtocolBase { _setUpUsers(); _setupRegistryRoyalties(address(mockERC721), _standardRoyaltyFee); - (OrderStructs.Maker memory makerBid, ) = _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); + (OrderStructs.Maker memory makerBid,) = _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); makerBid.price = price; makerBid.itemIds[0] = itemId; diff --git a/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC1155.t.sol b/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC1155.t.sol index 60ef310b..2a96743c 100644 --- a/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC1155.t.sol +++ b/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC1155.t.sol @@ -2,27 +2,31 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { IReentrancyGuard } from "@looksrare/contracts-libs/contracts/interfaces/IReentrancyGuard.sol"; -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {IReentrancyGuard} from "@looksrare/contracts-libs/contracts/interfaces/IReentrancyGuard.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Mocks and other utils -import { ERC1271Wallet } from "./utils/ERC1271Wallet.sol"; -import { MaliciousERC1271Wallet } from "./utils/MaliciousERC1271Wallet.sol"; -import { MaliciousOnERC1155ReceivedERC1271Wallet } from "./utils/MaliciousOnERC1155ReceivedERC1271Wallet.sol"; -import { MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet } from "./utils/MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet.sol"; -import { MaliciousIsValidSignatureERC1271Wallet } from "./utils/MaliciousIsValidSignatureERC1271Wallet.sol"; +import {ERC1271Wallet} from "./utils/ERC1271Wallet.sol"; +import {MaliciousERC1271Wallet} from "./utils/MaliciousERC1271Wallet.sol"; +import {MaliciousOnERC1155ReceivedERC1271Wallet} from "./utils/MaliciousOnERC1155ReceivedERC1271Wallet.sol"; +import {MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet} from + "./utils/MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet.sol"; +import {MaliciousIsValidSignatureERC1271Wallet} from "./utils/MaliciousIsValidSignatureERC1271Wallet.sol"; // Errors -import { SignatureERC1271Invalid } from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; -import { ERC1155SafeTransferFromFail, ERC1155SafeBatchTransferFromFail } from "@looksrare/contracts-libs/contracts/errors/LowLevelErrors.sol"; -import { SIGNATURE_INVALID_EIP1271 } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import {SignatureERC1271Invalid} from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; +import { + ERC1155SafeTransferFromFail, + ERC1155SafeBatchTransferFromFail +} from "@looksrare/contracts-libs/contracts/errors/LowLevelErrors.sol"; +import {SIGNATURE_INVALID_EIP1271} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; /** * @dev ERC1271Wallet recovers a signature's signer using ECDSA. If it matches the mock wallet's @@ -53,13 +57,7 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { _assertValidMakerOrder(makerAsk, signature); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); assertEq(mockERC1155.balanceOf(takerUser, itemId), 1); } @@ -80,13 +78,7 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { vm.expectRevert(SignatureERC1271Invalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testTakerBidIsInvalidSignatureReentrancy() public { @@ -96,19 +88,12 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { _setUpUser(address(maliciousERC1271Wallet)); maliciousERC1271Wallet.setFunctionToReenter(MaliciousERC1271Wallet.FunctionToReenter.ExecuteTakerBid); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _takerBidSetup( - address(maliciousERC1271Wallet) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _takerBidSetup(address(maliciousERC1271Wallet)); vm.expectRevert(IReentrancyGuard.ReentrancyFail.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - _EMPTY_SIGNATURE, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE); } function testTakerAsk() public { @@ -125,7 +110,7 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { _assertValidMakerOrder(makerBid, signature); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); assertEq(mockERC1155.balanceOf(address(wallet), itemId), 1); } @@ -146,7 +131,7 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { vm.expectRevert(SignatureERC1271Invalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testTakerAskIsValidSignatureReentrancy() public { @@ -156,13 +141,12 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { _setUpUser(address(maliciousERC1271Wallet)); maliciousERC1271Wallet.setFunctionToReenter(MaliciousERC1271Wallet.FunctionToReenter.ExecuteTakerAsk); - (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = _takerAskSetup( - address(maliciousERC1271Wallet) - ); + (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = + _takerAskSetup(address(maliciousERC1271Wallet)); vm.expectRevert(IReentrancyGuard.ReentrancyFail.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE); } function testTakerAskOnERC1155ReceivedReentrancy() public { @@ -171,15 +155,14 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { ); _setUpUser(address(maliciousERC1271Wallet)); - (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = _takerAskSetup( - address(maliciousERC1271Wallet) - ); + (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = + _takerAskSetup(address(maliciousERC1271Wallet)); maliciousERC1271Wallet.setFunctionToReenter(MaliciousERC1271Wallet.FunctionToReenter.ExecuteTakerAsk); vm.expectRevert(ERC1155SafeTransferFromFail.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE); } function testBatchTakerAsk() public { @@ -194,7 +177,7 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { weth.approve(address(looksRareProtocol), price); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); for (uint256 i; i < 10; i++) { assertEq(mockERC1155.balanceOf(address(wallet), i), 1); @@ -207,9 +190,8 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { ); _setUpUser(address(maliciousERC1271Wallet)); - (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = _batchTakerAskSetup( - address(maliciousERC1271Wallet) - ); + (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = + _batchTakerAskSetup(address(maliciousERC1271Wallet)); bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -222,7 +204,7 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { vm.expectRevert(ERC1155SafeBatchTransferFromFail.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } uint256 private constant numberOfPurchases = 3; @@ -243,13 +225,8 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { vm.stopPrank(); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberOfPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberOfPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); for (uint256 i; i < numberOfPurchases; i++) { @@ -279,13 +256,8 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { vm.expectRevert(SignatureERC1271Invalid.selector); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberOfPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberOfPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); } @@ -305,13 +277,8 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { vm.expectRevert(IReentrancyGuard.ReentrancyFail.selector); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberOfPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberOfPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); for (uint256 i; i < numberOfPurchases - 1; i++) { @@ -320,7 +287,8 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { } function testExecuteMultipleTakerBidsOnERC1155ReceivedReentrancyOnlyInTheLastCall() public { - MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet maliciousERC1271Wallet = new MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet( + MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet maliciousERC1271Wallet = + new MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet( takerUser ); _setUpUser(makerUser); @@ -339,13 +307,8 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { } vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberOfPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberOfPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); // First 2 purchases should go through, but the last one fails silently @@ -355,9 +318,10 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { assertEq(mockERC1155.balanceOf(address(maliciousERC1271Wallet), numberOfPurchases - 1), 0); } - function _takerBidSetup( - address signer - ) private returns (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) { + function _takerBidSetup(address signer) + private + returns (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) + { // Mint asset mockERC1155.mint(signer, itemId, 1); @@ -379,9 +343,10 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { takerBid = _genericTakerOrder(); } - function _takerAskSetup( - address signer - ) private returns (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) { + function _takerAskSetup(address signer) + private + returns (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) + { makerBid = _createSingleItemMakerOrder({ quoteType: QuoteType.Bid, globalNonce: 0, @@ -403,9 +368,10 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { takerAsk = _genericTakerOrder(); } - function _batchTakerAskSetup( - address signer - ) private returns (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) { + function _batchTakerAskSetup(address signer) + private + returns (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) + { uint256[] memory itemIds = new uint256[](10); uint256[] memory amounts = new uint256[](10); @@ -437,9 +403,7 @@ contract SignaturesERC1271WalletForERC1155Test is ProtocolBase { takerAsk = _genericTakerOrder(); } - function _multipleTakerBidsSetup( - address signer - ) + function _multipleTakerBidsSetup(address signer) private returns ( OrderStructs.Maker[] memory makerAsks, diff --git a/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC721.t.sol b/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC721.t.sol index 61df2186..638c416e 100644 --- a/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC721.t.sol +++ b/contracts/test/foundry/marketplace/SignaturesERC1271WalletForERC721.t.sol @@ -2,24 +2,24 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { IReentrancyGuard } from "@looksrare/contracts-libs/contracts/interfaces/IReentrancyGuard.sol"; -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {IReentrancyGuard} from "@looksrare/contracts-libs/contracts/interfaces/IReentrancyGuard.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Mocks and other utils -import { ERC1271Wallet } from "./utils/ERC1271Wallet.sol"; -import { MaliciousERC1271Wallet } from "./utils/MaliciousERC1271Wallet.sol"; -import { MaliciousIsValidSignatureERC1271Wallet } from "./utils/MaliciousIsValidSignatureERC1271Wallet.sol"; +import {ERC1271Wallet} from "./utils/ERC1271Wallet.sol"; +import {MaliciousERC1271Wallet} from "./utils/MaliciousERC1271Wallet.sol"; +import {MaliciousIsValidSignatureERC1271Wallet} from "./utils/MaliciousIsValidSignatureERC1271Wallet.sol"; // Errors -import { SignatureERC1271Invalid } from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; -import { SIGNATURE_INVALID_EIP1271 } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import {SignatureERC1271Invalid} from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; +import {SIGNATURE_INVALID_EIP1271} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; /** * @dev ERC1271Wallet recovers a signature's signer using ECDSA. If it matches the mock wallet's @@ -49,13 +49,7 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { _assertValidMakerOrder(makerAsk, signature); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); assertEq(mockERC721.ownerOf(makerAsk.itemIds[0]), takerUser); } @@ -76,13 +70,7 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { vm.expectRevert(SignatureERC1271Invalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testTakerBidReentrancy() public { @@ -92,19 +80,12 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { _setUpUser(address(maliciousERC1271Wallet)); maliciousERC1271Wallet.setFunctionToReenter(MaliciousERC1271Wallet.FunctionToReenter.ExecuteTakerBid); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _takerBidSetup( - address(maliciousERC1271Wallet) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _takerBidSetup(address(maliciousERC1271Wallet)); vm.expectRevert(IReentrancyGuard.ReentrancyFail.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - _EMPTY_SIGNATURE, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE); } function testTakerAsk() public { @@ -121,7 +102,7 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { _assertValidMakerOrder(makerBid, signature); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); assertEq(mockERC721.ownerOf(makerBid.itemIds[0]), address(wallet)); } @@ -142,7 +123,7 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { vm.expectRevert(SignatureERC1271Invalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testTakerAskReentrancy() public { @@ -152,13 +133,12 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { _setUpUser(address(maliciousERC1271Wallet)); maliciousERC1271Wallet.setFunctionToReenter(MaliciousERC1271Wallet.FunctionToReenter.ExecuteTakerAsk); - (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = _takerAskSetup( - address(maliciousERC1271Wallet) - ); + (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) = + _takerAskSetup(address(maliciousERC1271Wallet)); vm.expectRevert(IReentrancyGuard.ReentrancyFail.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, _EMPTY_SIGNATURE, _EMPTY_MERKLE_TREE); } uint256 private constant numberPurchases = 3; @@ -179,13 +159,8 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { vm.stopPrank(); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); for (uint256 i; i < numberPurchases; i++) { @@ -215,13 +190,8 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { vm.expectRevert(SignatureERC1271Invalid.selector); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); } @@ -241,37 +211,32 @@ contract SignaturesERC1271WalletForERC721Test is ProtocolBase { vm.expectRevert(IReentrancyGuard.ReentrancyFail.selector); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); } - function _takerBidSetup( - address signer - ) private returns (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) { + function _takerBidSetup(address signer) + private + returns (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) + { (makerAsk, takerBid) = _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.signer = signer; // Mint asset mockERC721.mint(signer, makerAsk.itemIds[0]); } - function _takerAskSetup( - address signer - ) private returns (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) { + function _takerAskSetup(address signer) + private + returns (OrderStructs.Taker memory takerAsk, OrderStructs.Maker memory makerBid) + { (makerBid, takerAsk) = _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); makerBid.signer = signer; // Mint asset mockERC721.mint(takerUser, makerBid.itemIds[0]); } - function _multipleTakerBidsSetup( - address signer - ) + function _multipleTakerBidsSetup(address signer) private returns ( OrderStructs.Maker[] memory makerAsks, diff --git a/contracts/test/foundry/marketplace/SignaturesRevertions.t.sol b/contracts/test/foundry/marketplace/SignaturesRevertions.t.sol index 1861c480..c5f1ef18 100644 --- a/contracts/test/foundry/marketplace/SignaturesRevertions.t.sol +++ b/contracts/test/foundry/marketplace/SignaturesRevertions.t.sol @@ -2,23 +2,35 @@ pragma solidity 0.8.17; // Libraries, interfaces, errors -import { SignatureParameterVInvalid, SignatureParameterSInvalid, SignatureEOAInvalid, NullSignerAddress, SignatureLengthInvalid } from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import { + SignatureParameterVInvalid, + SignatureParameterSInvalid, + SignatureEOAInvalid, + NullSignerAddress, + SignatureLengthInvalid +} from "@looksrare/contracts-libs/contracts/errors/SignatureCheckerErrors.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; -import { INVALID_S_PARAMETER_EOA, INVALID_V_PARAMETER_EOA, NULL_SIGNER_EOA, INVALID_SIGNATURE_LENGTH, INVALID_SIGNER_EOA } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import { + INVALID_S_PARAMETER_EOA, + INVALID_V_PARAMETER_EOA, + NULL_SIGNER_EOA, + INVALID_SIGNATURE_LENGTH, + INVALID_SIGNER_EOA +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract SignaturesRevertionsTest is ProtocolBase { uint256 internal constant _MAX_PRIVATE_KEY = - 115792089237316195423570985008687907852837564279074904382605163141518161494337; + 115_792_089_237_316_195_423_570_985_008_687_907_852_837_564_279_074_904_382_605_163_141_518_161_494_337; function setUp() public { _setUp(); @@ -49,13 +61,7 @@ contract SignaturesRevertionsTest is ProtocolBase { vm.expectRevert(SignatureEOAInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid( - _genericTakerOrder(), - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid(_genericTakerOrder(), makerAsk, signature, _EMPTY_MERKLE_TREE); } function testRevertIfInvalidVParameter(uint256 itemId, uint256 price, uint8 v) public { @@ -77,23 +83,15 @@ contract SignaturesRevertionsTest is ProtocolBase { // Sign but replace v by the fuzzed v bytes32 orderHash = _computeOrderHash(makerAsk); - (, bytes32 r, bytes32 s) = vm.sign( - makerUserPK, - keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash)) - ); + (, bytes32 r, bytes32 s) = + vm.sign(makerUserPK, keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash))); bytes memory signature = abi.encodePacked(r, s, v); _assertMakerOrderReturnValidationCode(makerAsk, signature, INVALID_V_PARAMETER_EOA); vm.expectRevert(abi.encodeWithSelector(SignatureParameterVInvalid.selector, v)); vm.prank(takerUser); - looksRareProtocol.executeTakerBid( - _genericTakerOrder(), - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid(_genericTakerOrder(), makerAsk, signature, _EMPTY_MERKLE_TREE); } function testRevertIfInvalidSParameter(uint256 itemId, uint256 price, bytes32 s) public { @@ -115,23 +113,15 @@ contract SignaturesRevertionsTest is ProtocolBase { // Sign but replace s by the fuzzed s bytes32 orderHash = _computeOrderHash(makerAsk); - (uint8 v, bytes32 r, ) = vm.sign( - makerUserPK, - keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash)) - ); + (uint8 v, bytes32 r,) = + vm.sign(makerUserPK, keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash))); bytes memory signature = abi.encodePacked(r, s, v); _assertMakerOrderReturnValidationCode(makerAsk, signature, INVALID_S_PARAMETER_EOA); vm.expectRevert(abi.encodeWithSelector(SignatureParameterSInvalid.selector)); vm.prank(takerUser); - looksRareProtocol.executeTakerBid( - _genericTakerOrder(), - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid(_genericTakerOrder(), makerAsk, signature, _EMPTY_MERKLE_TREE); } function testRevertIfRecoveredSignerIsNullAddress(uint256 itemId, uint256 price) public { @@ -151,10 +141,8 @@ contract SignaturesRevertionsTest is ProtocolBase { // Sign but replace r by empty bytes32 bytes32 orderHash = _computeOrderHash(makerAsk); - (uint8 v, , bytes32 s) = vm.sign( - makerUserPK, - keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash)) - ); + (uint8 v,, bytes32 s) = + vm.sign(makerUserPK, keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash))); bytes32 r; bytes memory signature = abi.encodePacked(r, s, v); @@ -163,22 +151,15 @@ contract SignaturesRevertionsTest is ProtocolBase { vm.expectRevert(abi.encodeWithSelector(NullSignerAddress.selector)); vm.prank(takerUser); - looksRareProtocol.executeTakerBid( - _genericTakerOrder(), - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid(_genericTakerOrder(), makerAsk, signature, _EMPTY_MERKLE_TREE); } function testRevertIfInvalidSignatureLength(uint256 itemId, uint256 price, uint256 length) public { // @dev Getting OutOfGas starting from 16,776,985, probably due to memory cost vm.assume(length != 64 && length != 65 && length < 16_776_985); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.itemIds[0] = itemId; makerAsk.price = price; @@ -187,6 +168,6 @@ contract SignaturesRevertionsTest is ProtocolBase { vm.expectRevert(abi.encodeWithSelector(SignatureLengthInvalid.selector, length)); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } } diff --git a/contracts/test/foundry/marketplace/StandardTransactions.t.sol b/contracts/test/foundry/marketplace/StandardTransactions.t.sol index 3bc01b8e..6d5d8b38 100644 --- a/contracts/test/foundry/marketplace/StandardTransactions.t.sol +++ b/contracts/test/foundry/marketplace/StandardTransactions.t.sol @@ -2,20 +2,20 @@ pragma solidity 0.8.17; // Libraries, interfaces, errors -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { LengthsInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {LengthsInvalid} from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { CreatorFeeManagerWithRoyalties } from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; +import {CreatorFeeManagerWithRoyalties} from "@hypercerts/marketplace/CreatorFeeManagerWithRoyalties.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract StandardTransactionsTest is ProtocolBase { error ERC721TransferFromFail(); @@ -40,9 +40,8 @@ contract StandardTransactionsTest is ProtocolBase { _setUpUsers(); _setupRegistryRoyalties(address(mockERC721), NEW_ROYALTY_FEE); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.price = price; bytes memory signature = _signMakerOrder(makerAsk, makerUserPK); @@ -54,7 +53,7 @@ contract StandardTransactionsTest is ProtocolBase { _assertValidMakerOrder(makerAsk, signature); // Arrays for events - uint256[3] memory expectedFees = _calculateExpectedFees({ price: price, royaltyFeeBp: NEW_ROYALTY_FEE }); + uint256[3] memory expectedFees = _calculateExpectedFees({price: price, royaltyFeeBp: NEW_ROYALTY_FEE}); address[2] memory expectedRecipients; expectedRecipients[0] = makerUser; @@ -81,13 +80,7 @@ contract StandardTransactionsTest is ProtocolBase { expectedFees ); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); _assertSuccessfulExecutionThroughETH(takerUser, makerUser, price, expectedFees); @@ -104,9 +97,8 @@ contract StandardTransactionsTest is ProtocolBase { vm.assume(price <= 2 ether); _setUpUsers(); - (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMockMakerAskAndTakerBid( - address(mockERC721) - ); + (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = + _createMockMakerAskAndTakerBid(address(mockERC721)); makerAsk.price = price; bytes memory signature = _signMakerOrder(makerAsk, makerUserPK); @@ -121,7 +113,7 @@ contract StandardTransactionsTest is ProtocolBase { _assertValidMakerOrder(makerAsk, signature); // Arrays for events - uint256[3] memory expectedFees = _calculateExpectedFees({ price: price, royaltyFeeBp: 0 }); + uint256[3] memory expectedFees = _calculateExpectedFees({price: price, royaltyFeeBp: 0}); address[2] memory expectedRecipients; expectedRecipients[0] = makerUser; @@ -148,13 +140,7 @@ contract StandardTransactionsTest is ProtocolBase { expectedFees ); - looksRareProtocol.executeTakerBid{ value: price }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: price}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); _assertSuccessfulExecutionThroughETH(takerUser, makerUser, price, expectedFees); } @@ -168,10 +154,8 @@ contract StandardTransactionsTest is ProtocolBase { _setUpUsers(); _setupRegistryRoyalties(address(mockERC721), NEW_ROYALTY_FEE); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); makerBid.price = price; bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -183,7 +167,7 @@ contract StandardTransactionsTest is ProtocolBase { mockERC721.mint(takerUser, makerBid.itemIds[0]); // Arrays for events - uint256[3] memory expectedFees = _calculateExpectedFees({ price: price, royaltyFeeBp: NEW_ROYALTY_FEE }); + uint256[3] memory expectedFees = _calculateExpectedFees({price: price, royaltyFeeBp: NEW_ROYALTY_FEE}); address[2] memory expectedRecipients; expectedRecipients[0] = takerUser; @@ -211,7 +195,7 @@ contract StandardTransactionsTest is ProtocolBase { expectedFees ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertSuccessfulExecutionThroughWETH(makerUser, takerUser, price, expectedFees); // Verify the nonce is marked as executed @@ -219,16 +203,15 @@ contract StandardTransactionsTest is ProtocolBase { } /** - * One ERC721 is sold through a taker ask using WETH. Address zero is specified as the recipient in the taker struct. + * One ERC721 is sold through a taker ask using WETH. Address zero is specified as the recipient in the taker + * struct. */ function testTakerAskERC721WithAddressZeroSpecifiedAsRecipient(uint256 price) public { vm.assume(price <= 2 ether); _setUpUsers(); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); makerBid.price = price; bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -243,7 +226,7 @@ contract StandardTransactionsTest is ProtocolBase { mockERC721.mint(takerUser, makerBid.itemIds[0]); // Arrays for events - uint256[3] memory expectedFees = _calculateExpectedFees({ price: price, royaltyFeeBp: 0 }); + uint256[3] memory expectedFees = _calculateExpectedFees({price: price, royaltyFeeBp: 0}); address[2] memory expectedRecipients; expectedRecipients[0] = takerUser; @@ -270,7 +253,7 @@ contract StandardTransactionsTest is ProtocolBase { expectedFees ); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertSuccessfulExecutionThroughWETH(makerUser, takerUser, price, expectedFees); } @@ -317,13 +300,8 @@ contract StandardTransactionsTest is ProtocolBase { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); for (uint256 i; i < numberPurchases; i++) { @@ -338,9 +316,8 @@ contract StandardTransactionsTest is ProtocolBase { // Maker ask user receives 99.5% of the whole price (0.5% protocol) assertEq( address(makerUser).balance, - _initialETHBalanceUser + - ((price * _sellerProceedBpWithStandardProtocolFeeBp) * numberPurchases) / - ONE_HUNDRED_PERCENT_IN_BP + _initialETHBalanceUser + + ((price * _sellerProceedBpWithStandardProtocolFeeBp) * numberPurchases) / ONE_HUNDRED_PERCENT_IN_BP ); // No leftover in the balance of the contract assertEq(address(looksRareProtocol).balance, 0); @@ -397,13 +374,8 @@ contract StandardTransactionsTest is ProtocolBase { vm.expectRevert(abi.encodeWithSelector(ERC721TransferFromFail.selector)); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: 1.4 ether * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - true + looksRareProtocol.executeMultipleTakerBids{value: 1.4 ether * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, true ); } @@ -416,13 +388,8 @@ contract StandardTransactionsTest is ProtocolBase { vm.prank(takerUser); // Execute taker bid transaction - looksRareProtocol.executeMultipleTakerBids{ value: 1.4 ether * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: 1.4 ether * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); } @@ -442,9 +409,9 @@ contract StandardTransactionsTest is ProtocolBase { // Maker ask user receives 99.5% of the whole price (0.5% protocol) assertEq( address(makerUser).balance, - _initialETHBalanceUser + - ((1.4 ether * _sellerProceedBpWithStandardProtocolFeeBp) * (numberPurchases - 1)) / - ONE_HUNDRED_PERCENT_IN_BP + _initialETHBalanceUser + + ((1.4 ether * _sellerProceedBpWithStandardProtocolFeeBp) * (numberPurchases - 1)) + / ONE_HUNDRED_PERCENT_IN_BP ); // 1 wei left in the balance of the contract assertEq(address(looksRareProtocol).balance, 1); @@ -465,13 +432,8 @@ contract StandardTransactionsTest is ProtocolBase { vm.expectRevert(LengthsInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); // 2. Invalid signatures length @@ -480,13 +442,8 @@ contract StandardTransactionsTest is ProtocolBase { vm.expectRevert(LengthsInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); // 3. Invalid merkle trees length @@ -495,20 +452,16 @@ contract StandardTransactionsTest is ProtocolBase { vm.expectRevert(LengthsInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeMultipleTakerBids{ value: price * numberPurchases }( - takerBids, - makerAsks, - signatures, - merkleTrees, - _EMPTY_AFFILIATE, - false + looksRareProtocol.executeMultipleTakerBids{value: price * numberPurchases}( + takerBids, makerAsks, signatures, merkleTrees, false ); } - function _calculateExpectedFees( - uint256 price, - uint256 royaltyFeeBp - ) private pure returns (uint256[3] memory expectedFees) { + function _calculateExpectedFees(uint256 price, uint256 royaltyFeeBp) + private + pure + returns (uint256[3] memory expectedFees) + { expectedFees[2] = (price * _standardProtocolFeeBp) / ONE_HUNDRED_PERCENT_IN_BP; expectedFees[1] = (price * royaltyFeeBp) / ONE_HUNDRED_PERCENT_IN_BP; if (expectedFees[2] + expectedFees[1] < ((price * _minTotalFeeBp) / ONE_HUNDRED_PERCENT_IN_BP)) { diff --git a/contracts/test/foundry/marketplace/StrategyManager.t.sol b/contracts/test/foundry/marketplace/StrategyManager.t.sol index 4d18eba3..e59128f2 100644 --- a/contracts/test/foundry/marketplace/StrategyManager.t.sol +++ b/contracts/test/foundry/marketplace/StrategyManager.t.sol @@ -2,29 +2,31 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IOwnableTwoSteps } from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; +import {IOwnableTwoSteps} from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Interfaces -import { IStrategyManager } from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; -import { IStrategy } from "@hypercerts/marketplace/interfaces/IStrategy.sol"; +import {IStrategyManager} from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; +import {IStrategy} from "@hypercerts/marketplace/interfaces/IStrategy.sol"; // Random strategy -import { StrategyCollectionOffer } from "@hypercerts/marketplace/executionStrategies/StrategyCollectionOffer.sol"; +import {StrategyCollectionOffer} from "@hypercerts/marketplace/executionStrategies/StrategyCollectionOffer.sol"; // Base test -import { ProtocolBase } from "./ProtocolBase.t.sol"; +import {ProtocolBase} from "./ProtocolBase.t.sol"; contract FalseBaseStrategy is IStrategy { /** * @inheritdoc IStrategy */ - function isMakerOrderValid( - OrderStructs.Maker calldata, - bytes4 - ) external view override returns (bool isValid, bytes4 errorSelector) { + function isMakerOrderValid(OrderStructs.Maker calldata, bytes4) + external + view + override + returns (bool isValid, bytes4 errorSelector) + { // } @@ -83,13 +85,7 @@ contract StrategyManagerTest is ProtocolBase, IStrategyManager { vm.expectEmit(true, false, false, true); emit NewStrategy( - strategyId, - _standardProtocolFeeBp, - _minTotalFeeBp, - _maxProtocolFeeBp, - selector, - isMakerBid, - implementation + strategyId, _standardProtocolFeeBp, _minTotalFeeBp, _maxProtocolFeeBp, selector, isMakerBid, implementation ); _addStrategy(implementation, selector, isMakerBid); @@ -131,15 +127,8 @@ contract StrategyManagerTest is ProtocolBase, IStrategyManager { * Owner functions for strategy updates revert as expected under multiple revertion scenarios */ function testOwnerRevertionsForInvalidParametersUpdateStrategy() public asPrankedUser(_owner) { - ( - , - uint16 currentStandardProtocolFee, - uint16 currentMinTotalFee, - uint16 maxProtocolFeeBp, - , - , - - ) = looksRareProtocol.strategyInfo(0); + (, uint16 currentStandardProtocolFee, uint16 currentMinTotalFee, uint16 maxProtocolFeeBp,,,) = + looksRareProtocol.strategyInfo(0); // 1. newStandardProtocolFee is higher than maxProtocolFeeBp uint16 newStandardProtocolFee = maxProtocolFeeBp + 1; @@ -171,36 +160,21 @@ contract StrategyManagerTest is ProtocolBase, IStrategyManager { maxProtocolFeeBp = standardProtocolFeeBp - 1; vm.expectRevert(abi.encodeWithSelector(IStrategyManager.StrategyProtocolFeeTooHigh.selector)); looksRareProtocol.addStrategy( - standardProtocolFeeBp, - minTotalFeeBp, - maxProtocolFeeBp, - _EMPTY_BYTES4, - true, - implementation + standardProtocolFeeBp, minTotalFeeBp, maxProtocolFeeBp, _EMPTY_BYTES4, true, implementation ); // 2. minTotalFeeBp is higher than maxProtocolFeeBp maxProtocolFeeBp = minTotalFeeBp - 1; vm.expectRevert(abi.encodeWithSelector(IStrategyManager.StrategyProtocolFeeTooHigh.selector)); looksRareProtocol.addStrategy( - standardProtocolFeeBp, - minTotalFeeBp, - maxProtocolFeeBp, - _EMPTY_BYTES4, - true, - implementation + standardProtocolFeeBp, minTotalFeeBp, maxProtocolFeeBp, _EMPTY_BYTES4, true, implementation ); // 3. maxProtocolFeeBp is higher than _MAX_PROTOCOL_FEE maxProtocolFeeBp = 500 + 1; vm.expectRevert(abi.encodeWithSelector(IStrategyManager.StrategyProtocolFeeTooHigh.selector)); looksRareProtocol.addStrategy( - standardProtocolFeeBp, - minTotalFeeBp, - maxProtocolFeeBp, - _EMPTY_BYTES4, - true, - implementation + standardProtocolFeeBp, minTotalFeeBp, maxProtocolFeeBp, _EMPTY_BYTES4, true, implementation ); } diff --git a/contracts/test/foundry/marketplace/TransferManager.t.sol b/contracts/test/foundry/marketplace/TransferManager.t.sol index 6d7f4643..d223cc59 100644 --- a/contracts/test/foundry/marketplace/TransferManager.t.sol +++ b/contracts/test/foundry/marketplace/TransferManager.t.sol @@ -2,24 +2,24 @@ pragma solidity 0.8.17; // LooksRare unopinionated libraries -import { IOwnableTwoSteps } from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; +import {IOwnableTwoSteps} from "@looksrare/contracts-libs/contracts/interfaces/IOwnableTwoSteps.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Core contracts -import { LooksRareProtocol } from "@hypercerts/marketplace/LooksRareProtocol.sol"; -import { ITransferManager, TransferManager } from "@hypercerts/marketplace/TransferManager.sol"; -import { AmountInvalid, LengthsInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import {LooksRareProtocol} from "@hypercerts/marketplace/LooksRareProtocol.sol"; +import {ITransferManager, TransferManager} from "@hypercerts/marketplace/TransferManager.sol"; +import {AmountInvalid, LengthsInvalid} from "@hypercerts/marketplace/errors/SharedErrors.sol"; // Mocks and other utils -import { MockERC721 } from "../../mock/MockERC721.sol"; -import { MockERC1155 } from "../../mock/MockERC1155.sol"; -import { TestHelpers } from "./utils/TestHelpers.sol"; -import { TestParameters } from "./utils/TestParameters.sol"; +import {MockERC721} from "../../mock/MockERC721.sol"; +import {MockERC1155} from "../../mock/MockERC1155.sol"; +import {TestHelpers} from "./utils/TestHelpers.sol"; +import {TestParameters} from "./utils/TestParameters.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; contract TransferManagerTest is ITransferManager, TestHelpers, TestParameters { address[] public operators; @@ -398,21 +398,13 @@ contract TransferManagerTest is ITransferManager, TestHelpers, TestParameters { // 1. ERC721 vm.expectRevert(LengthsInvalid.selector); transferManager.transferItemsERC721( - address(mockERC721), - _sender, - _recipient, - emptyArrayUint256, - emptyArrayUint256 + address(mockERC721), _sender, _recipient, emptyArrayUint256, emptyArrayUint256 ); // 2. ERC1155 length is 0 vm.expectRevert(LengthsInvalid.selector); transferManager.transferItemsERC1155( - address(mockERC1155), - _sender, - _recipient, - emptyArrayUint256, - emptyArrayUint256 + address(mockERC1155), _sender, _recipient, emptyArrayUint256, emptyArrayUint256 ); } diff --git a/contracts/test/foundry/marketplace/assembly/VerifyOrderTimestampValidityEquivalence.t.sol b/contracts/test/foundry/marketplace/assembly/VerifyOrderTimestampValidityEquivalence.t.sol index 9a124211..504f0049 100644 --- a/contracts/test/foundry/marketplace/assembly/VerifyOrderTimestampValidityEquivalence.t.sol +++ b/contracts/test/foundry/marketplace/assembly/VerifyOrderTimestampValidityEquivalence.t.sol @@ -1,10 +1,14 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { Test } from "forge-std/Test.sol"; +import {Test} from "forge-std/Test.sol"; // Assembly -import { OutsideOfTimeRange_error_selector, OutsideOfTimeRange_error_length, Error_selector_offset } from "@hypercerts/marketplace/constants/AssemblyConstants.sol"; +import { + OutsideOfTimeRange_error_selector, + OutsideOfTimeRange_error_length, + Error_selector_offset +} from "@hypercerts/marketplace/constants/AssemblyConstants.sol"; contract NonAssemblyCode { error OutsideOfTimeRange(); diff --git a/contracts/test/foundry/marketplace/executionStrategies/Chainlink/USDDynamicAskOrders.t.sol b/contracts/test/foundry/marketplace/executionStrategies/Chainlink/USDDynamicAskOrders.t.sol index df930c71..066df8a6 100644 --- a/contracts/test/foundry/marketplace/executionStrategies/Chainlink/USDDynamicAskOrders.t.sol +++ b/contracts/test/foundry/marketplace/executionStrategies/Chainlink/USDDynamicAskOrders.t.sol @@ -2,26 +2,38 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { IExecutionManager } from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; -import { IStrategyManager } from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {IExecutionManager} from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; +import {IStrategyManager} from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; // Errors and constants -import { AmountInvalid, BidTooLow, OrderInvalid, CurrencyInvalid, FunctionSelectorInvalid, QuoteTypeInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { ChainlinkPriceInvalid, PriceNotRecentEnough } from "@hypercerts/marketplace/errors/ChainlinkErrors.sol"; -import { MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE, MAKER_ORDER_TEMPORARILY_INVALID_NON_STANDARD_SALE, STRATEGY_NOT_ACTIVE } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + AmountInvalid, + BidTooLow, + OrderInvalid, + CurrencyInvalid, + FunctionSelectorInvalid, + QuoteTypeInvalid +} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import {ChainlinkPriceInvalid, PriceNotRecentEnough} from "@hypercerts/marketplace/errors/ChainlinkErrors.sol"; +import { + MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE, + MAKER_ORDER_TEMPORARILY_INVALID_NON_STANDARD_SALE, + STRATEGY_NOT_ACTIVE +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Strategies -import { StrategyChainlinkUSDDynamicAsk } from "@hypercerts/marketplace/executionStrategies/Chainlink/StrategyChainlinkUSDDynamicAsk.sol"; +import {StrategyChainlinkUSDDynamicAsk} from + "@hypercerts/marketplace/executionStrategies/Chainlink/StrategyChainlinkUSDDynamicAsk.sol"; // Mocks and other tests -import { MockChainlinkAggregator } from "../../../../mock/MockChainlinkAggregator.sol"; -import { MockERC20 } from "../../../../mock/MockERC20.sol"; -import { ProtocolBase } from "../../ProtocolBase.t.sol"; +import {MockChainlinkAggregator} from "../../../../mock/MockChainlinkAggregator.sol"; +import {MockERC20} from "../../../../mock/MockERC20.sol"; +import {ProtocolBase} from "../../ProtocolBase.t.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { StrategyChainlinkUSDDynamicAsk public strategyUSDDynamicAsk; @@ -33,10 +45,10 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { // startedAt uint256 : 1665680123 // updatedAt uint256 : 1665680123 // answeredInRound uint80 : 92233720368547793259 - uint256 private constant CHAINLINK_PRICE_UPDATED_AT = 1665680123; - uint256 private constant FORKED_BLOCK_NUMBER = 15740567; - uint256 private constant LATEST_CHAINLINK_ANSWER_IN_WAD = 126533075631 * 1e10; - uint256 private constant MAXIMUM_LATENCY = 3_600 seconds; + uint256 private constant CHAINLINK_PRICE_UPDATED_AT = 1_665_680_123; + uint256 private constant FORKED_BLOCK_NUMBER = 15_740_567; + uint256 private constant LATEST_CHAINLINK_ANSWER_IN_WAD = 126_533_075_631 * 1e10; + uint256 private constant MAXIMUM_LATENCY = 3600 seconds; function setUp() public { vm.createSelectFork(vm.rpcUrl("mainnet"), FORKED_BLOCK_NUMBER); @@ -54,13 +66,12 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { _addStrategy(address(strategyUSDDynamicAsk), selector, false); } - function _createMakerAskAndTakerBid( - uint256 numberOfItems, - uint256 numberOfAmounts, - uint256 desiredSalePriceInUSD - ) private returns (OrderStructs.Maker memory newMakerAsk, OrderStructs.Taker memory newTakerBid) { + function _createMakerAskAndTakerBid(uint256 numberOfItems, uint256 numberOfAmounts, uint256 desiredSalePriceInUSD) + private + returns (OrderStructs.Maker memory newMakerAsk, OrderStructs.Taker memory newTakerBid) + { uint256[] memory itemIds = new uint256[](numberOfItems); - for (uint256 i; i < numberOfItems; ) { + for (uint256 i; i < numberOfItems;) { mockERC721.mint(makerUser, i + 1); itemIds[i] = i + 1; unchecked { @@ -69,7 +80,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { } uint256[] memory amounts = new uint256[](numberOfAmounts); - for (uint256 i; i < numberOfAmounts; ) { + for (uint256 i; i < numberOfAmounts;) { amounts[i] = 1; unchecked { ++i; @@ -102,7 +113,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { } function testMaxLatency() public { - assertEq(strategyUSDDynamicAsk.maxLatency(), 3_600); + assertEq(strategyUSDDynamicAsk.maxLatency(), 3600); } function testUSDDynamicAskChainlinkPriceInvalid() public { @@ -124,7 +135,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); MockChainlinkAggregator(CHAINLINK_ETH_USD_PRICE_FEED).setAnswer(0); (isValid, errorSelector) = strategyUSDDynamicAsk.isMakerOrderValid(makerAsk, selector); @@ -133,7 +144,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testUSDDynamicAskUSDValueGreaterThanOrEqualToMinAcceptedEthValue() public { @@ -151,7 +162,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(1), takerUser); @@ -176,7 +187,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(1), takerUser); @@ -205,7 +216,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(1), takerUser); @@ -239,13 +250,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid{ value: maxPrice }( - takerBid, - makerAsk, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerBid{value: maxPrice}(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(1), takerUser); @@ -277,7 +282,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testCannotExecuteIfNotWETHOrETH() public { @@ -302,7 +307,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testZeroItemIdsLength() public { @@ -320,7 +325,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testItemIdsAndAmountsLengthMismatch() public { @@ -338,7 +343,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testWrongQuoteType() public { @@ -382,7 +387,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testAmountGreaterThanOneForERC721() public { @@ -404,7 +409,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testTakerBidTooLow() public { @@ -425,7 +430,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(BidTooLow.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testInactiveStrategy() public { @@ -446,7 +451,7 @@ contract USDDynamicAskOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(abi.encodeWithSelector(IExecutionManager.StrategyNotAvailable.selector, 1)); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testInvalidSelector() public { diff --git a/contracts/test/foundry/marketplace/executionStrategies/CollectionOffers.t.sol b/contracts/test/foundry/marketplace/executionStrategies/CollectionOffers.t.sol index 429bee91..9f9efa3f 100644 --- a/contracts/test/foundry/marketplace/executionStrategies/CollectionOffers.t.sol +++ b/contracts/test/foundry/marketplace/executionStrategies/CollectionOffers.t.sol @@ -2,27 +2,34 @@ pragma solidity 0.8.17; // Murky (third-party) library is used to compute Merkle trees in Solidity -import { Merkle } from "murky/Merkle.sol"; +import {Merkle} from "murky/Merkle.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Shared errors -import { AmountInvalid, OrderInvalid, FunctionSelectorInvalid, MerkleProofInvalid, QuoteTypeInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + AmountInvalid, + OrderInvalid, + FunctionSelectorInvalid, + MerkleProofInvalid, + QuoteTypeInvalid +} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import {MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE} from + "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Strategies -import { StrategyCollectionOffer } from "@hypercerts/marketplace/executionStrategies/StrategyCollectionOffer.sol"; +import {StrategyCollectionOffer} from "@hypercerts/marketplace/executionStrategies/StrategyCollectionOffer.sol"; // Base test -import { ProtocolBase } from "../ProtocolBase.t.sol"; +import {ProtocolBase} from "../ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract CollectionOrdersTest is ProtocolBase { StrategyCollectionOffer public strategyCollectionOffer; @@ -68,10 +75,8 @@ contract CollectionOrdersTest is ProtocolBase { function testMakerBidAmountsLengthNotOne() public { _setUpUsers(); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); // Adjust strategy for collection order and sign order // Change array to make it bigger than expected @@ -86,7 +91,7 @@ contract CollectionOrdersTest is ProtocolBase { _assertMakerOrderReturnValidationCode(makerBid, signature, MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // With proof makerBid.strategyId = 2; @@ -97,16 +102,14 @@ contract CollectionOrdersTest is ProtocolBase { _assertMakerOrderReturnValidationCode(makerBid, signature, MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testZeroAmount() public { _setUpUsers(); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMockMakerBidAndTakerAsk( - address(mockERC721), - address(weth) - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMockMakerBidAndTakerAsk(address(mockERC721), address(weth)); uint256[] memory amounts = new uint256[](1); amounts[0] = 0; @@ -121,7 +124,7 @@ contract CollectionOrdersTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } /** @@ -159,7 +162,7 @@ contract CollectionOrdersTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertSuccessfulTakerAsk(makerBid, tokenId); } @@ -205,7 +208,7 @@ contract CollectionOrdersTest is ProtocolBase { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); _assertSuccessfulTakerAsk(makerBid, itemIdInMerkleTree); } @@ -249,7 +252,7 @@ contract CollectionOrdersTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(MerkleProofInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testInvalidAmounts() public { @@ -280,7 +283,7 @@ contract CollectionOrdersTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // 2. Amount is too high for ERC721 (without merkle proof) makerBid.amounts[0] = 2; @@ -290,7 +293,7 @@ contract CollectionOrdersTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // 3. Amount is 0 (with merkle proof) makerBid.strategyId = 2; @@ -312,7 +315,7 @@ contract CollectionOrdersTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // 4. Amount is too high for ERC721 (with merkle proof) makerBid.amounts[0] = 2; @@ -322,7 +325,7 @@ contract CollectionOrdersTest is ProtocolBase { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testMerkleRootLengthIsNot32() public { @@ -346,14 +349,9 @@ contract CollectionOrdersTest is ProtocolBase { _assertMakerOrderReturnValidationCode(makerBid, signature, MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE); vm.prank(takerUser); - vm.expectRevert(); // It should revert without data (since the root cannot be extracted since the additionalParameters length is 0) - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBid, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + vm.expectRevert(); // It should revert without data (since the root cannot be extracted since the + // additionalParameters length is 0) + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBid, signature, _EMPTY_MERKLE_TREE); } function testInvalidSelector() public { @@ -391,29 +389,22 @@ contract CollectionOrdersTest is ProtocolBase { itemId: 0 }); - (bool orderIsValid, bytes4 errorSelector) = strategyCollectionOffer.isMakerOrderValid( - makerAsk, - selectorNoProof - ); + (bool orderIsValid, bytes4 errorSelector) = strategyCollectionOffer.isMakerOrderValid(makerAsk, selectorNoProof); assertFalse(orderIsValid); assertEq(errorSelector, QuoteTypeInvalid.selector); } function _assertOrderIsValid(OrderStructs.Maker memory makerBid, bool withProof) private { - (bool orderIsValid, bytes4 errorSelector) = strategyCollectionOffer.isMakerOrderValid( - makerBid, - withProof ? selectorWithProof : selectorNoProof - ); + (bool orderIsValid, bytes4 errorSelector) = + strategyCollectionOffer.isMakerOrderValid(makerBid, withProof ? selectorWithProof : selectorNoProof); assertTrue(orderIsValid); assertEq(errorSelector, _EMPTY_BYTES4); } function _assertOrderIsInvalid(OrderStructs.Maker memory makerBid, bool withProof) private { - (bool orderIsValid, bytes4 errorSelector) = strategyCollectionOffer.isMakerOrderValid( - makerBid, - withProof ? selectorWithProof : selectorNoProof - ); + (bool orderIsValid, bytes4 errorSelector) = + strategyCollectionOffer.isMakerOrderValid(makerBid, withProof ? selectorWithProof : selectorNoProof); assertFalse(orderIsValid); assertEq(errorSelector, OrderInvalid.selector); diff --git a/contracts/test/foundry/marketplace/executionStrategies/DutchAuctionOrders.t.sol b/contracts/test/foundry/marketplace/executionStrategies/DutchAuctionOrders.t.sol index dd8b05c6..4370cb3d 100644 --- a/contracts/test/foundry/marketplace/executionStrategies/DutchAuctionOrders.t.sol +++ b/contracts/test/foundry/marketplace/executionStrategies/DutchAuctionOrders.t.sol @@ -2,26 +2,36 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { IExecutionManager } from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; -import { IStrategyManager } from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {IExecutionManager} from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; +import {IStrategyManager} from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; // Shared errors -import { AmountInvalid, BidTooLow, OrderInvalid, FunctionSelectorInvalid, QuoteTypeInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { STRATEGY_NOT_ACTIVE, MAKER_ORDER_TEMPORARILY_INVALID_NON_STANDARD_SALE, MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + AmountInvalid, + BidTooLow, + OrderInvalid, + FunctionSelectorInvalid, + QuoteTypeInvalid +} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import { + STRATEGY_NOT_ACTIVE, + MAKER_ORDER_TEMPORARILY_INVALID_NON_STANDARD_SALE, + MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Strategies -import { StrategyDutchAuction } from "@hypercerts/marketplace/executionStrategies/StrategyDutchAuction.sol"; +import {StrategyDutchAuction} from "@hypercerts/marketplace/executionStrategies/StrategyDutchAuction.sol"; // Other tests -import { ProtocolBase } from "../ProtocolBase.t.sol"; +import {ProtocolBase} from "../ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { StrategyDutchAuction public strategyDutchAuction; @@ -44,7 +54,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { uint256 endTime ) private returns (OrderStructs.Maker memory newMakerAsk, OrderStructs.Taker memory newTakerBid) { uint256[] memory itemIds = new uint256[](numberOfItems); - for (uint256 i; i < numberOfItems; ) { + for (uint256 i; i < numberOfItems;) { mockERC721.mint(makerUser, i + 1); itemIds[i] = i + 1; unchecked { @@ -53,7 +63,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { } uint256[] memory amounts = new uint256[](numberOfAmounts); - for (uint256 i; i < numberOfAmounts; ) { + for (uint256 i; i < numberOfAmounts;) { amounts[i] = 1; unchecked { ++i; @@ -89,12 +99,10 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { _assertStrategyAttributes(address(strategyDutchAuction), selector, false); } - function _fuzzAssumptions( - uint256 _startPrice, - uint256 _duration, - uint256 _decayPerSecond, - uint256 _elapsedTime - ) private returns (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) { + function _fuzzAssumptions(uint256 _startPrice, uint256 _duration, uint256 _decayPerSecond, uint256 _elapsedTime) + private + returns (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) + { // Bound instead of assume to handle too many rejections // These limits should be realistically way more than enough // vm.assume(duration > 0 && duration <= 31_536_000); @@ -111,38 +119,25 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { elapsedTime = _elapsedTime; } - function _calculatePrices( - uint256 startPrice, - uint256 duration, - uint256 decayPerSecond, - uint256 elapsedTime - ) private pure returns (uint256 endPrice, uint256 executionPrice) { + function _calculatePrices(uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) + private + pure + returns (uint256 endPrice, uint256 executionPrice) + { endPrice = startPrice - decayPerSecond * duration; uint256 discount = decayPerSecond * elapsedTime; executionPrice = startPrice - discount; } - function testDutchAuction( - uint256 _startPrice, - uint256 _duration, - uint256 _decayPerSecond, - uint256 _elapsedTime - ) public { - (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) = _fuzzAssumptions( - _startPrice, - _duration, - _decayPerSecond, - _elapsedTime - ); + function testDutchAuction(uint256 _startPrice, uint256 _duration, uint256 _decayPerSecond, uint256 _elapsedTime) + public + { + (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) = + _fuzzAssumptions(_startPrice, _duration, _decayPerSecond, _elapsedTime); _setUpUsers(); _setUpNewStrategy(); - (uint256 endPrice, uint256 executionPrice) = _calculatePrices( - startPrice, - duration, - decayPerSecond, - elapsedTime - ); + (uint256 endPrice, uint256 executionPrice) = _calculatePrices(startPrice, duration, decayPerSecond, elapsedTime); deal(address(weth), takerUser, executionPrice); @@ -164,7 +159,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { // Execute taker bid transaction vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(1), takerUser); @@ -180,27 +175,15 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { ); } - function testStartPriceTooLow( - uint256 _startPrice, - uint256 _duration, - uint256 _decayPerSecond, - uint256 _elapsedTime - ) public { - (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) = _fuzzAssumptions( - _startPrice, - _duration, - _decayPerSecond, - _elapsedTime - ); + function testStartPriceTooLow(uint256 _startPrice, uint256 _duration, uint256 _decayPerSecond, uint256 _elapsedTime) + public + { + (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) = + _fuzzAssumptions(_startPrice, _duration, _decayPerSecond, _elapsedTime); _setUpUsers(); _setUpNewStrategy(); - (uint256 endPrice, uint256 executionPrice) = _calculatePrices( - startPrice, - duration, - decayPerSecond, - elapsedTime - ); + (uint256 endPrice, uint256 executionPrice) = _calculatePrices(startPrice, duration, decayPerSecond, elapsedTime); deal(address(weth), takerUser, executionPrice); (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMakerAskAndTakerBid({ @@ -221,30 +204,18 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } - function testTakerBidTooLow( - uint256 _startPrice, - uint256 _duration, - uint256 _decayPerSecond, - uint256 _elapsedTime - ) public { - (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) = _fuzzAssumptions( - _startPrice, - _duration, - _decayPerSecond, - _elapsedTime - ); + function testTakerBidTooLow(uint256 _startPrice, uint256 _duration, uint256 _decayPerSecond, uint256 _elapsedTime) + public + { + (uint256 startPrice, uint256 duration, uint256 decayPerSecond, uint256 elapsedTime) = + _fuzzAssumptions(_startPrice, _duration, _decayPerSecond, _elapsedTime); _setUpUsers(); _setUpNewStrategy(); - (uint256 endPrice, uint256 executionPrice) = _calculatePrices( - startPrice, - duration, - decayPerSecond, - elapsedTime - ); + (uint256 endPrice, uint256 executionPrice) = _calculatePrices(startPrice, duration, decayPerSecond, elapsedTime); deal(address(weth), takerUser, executionPrice); (OrderStructs.Maker memory makerAsk, OrderStructs.Taker memory takerBid) = _createMakerAskAndTakerBid({ @@ -266,7 +237,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(BidTooLow.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testInactiveStrategy() public { @@ -291,7 +262,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { vm.prank(takerUser); vm.expectRevert(abi.encodeWithSelector(IExecutionManager.StrategyNotAvailable.selector, 1)); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testZeroItemIdsLength() public { @@ -313,7 +284,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testItemIdsAndAmountsLengthMismatch() public { @@ -335,7 +306,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testInvalidAmounts() public { @@ -361,7 +332,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(AmountInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); // 2. ERC721 amount > 1 makerAsk.amounts[0] = 2; @@ -372,7 +343,7 @@ contract DutchAuctionOrdersTest is ProtocolBase, IStrategyManager { vm.prank(takerUser); vm.expectRevert(AmountInvalid.selector); - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, _EMPTY_MERKLE_TREE); } function testWrongQuoteType() public { diff --git a/contracts/test/foundry/marketplace/executionStrategies/ItemIdsRangeOrders.t.sol b/contracts/test/foundry/marketplace/executionStrategies/ItemIdsRangeOrders.t.sol index 714595d8..07199143 100644 --- a/contracts/test/foundry/marketplace/executionStrategies/ItemIdsRangeOrders.t.sol +++ b/contracts/test/foundry/marketplace/executionStrategies/ItemIdsRangeOrders.t.sol @@ -2,23 +2,29 @@ pragma solidity 0.8.17; // Libraries and interfaces -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; -import { IExecutionManager } from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; -import { IStrategyManager } from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {IExecutionManager} from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; +import {IStrategyManager} from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; // Shared errors -import { OrderInvalid, FunctionSelectorInvalid, QuoteTypeInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; -import { STRATEGY_NOT_ACTIVE, MAKER_ORDER_TEMPORARILY_INVALID_NON_STANDARD_SALE, MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE } from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; +import { + OrderInvalid, FunctionSelectorInvalid, QuoteTypeInvalid +} from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import { + STRATEGY_NOT_ACTIVE, + MAKER_ORDER_TEMPORARILY_INVALID_NON_STANDARD_SALE, + MAKER_ORDER_PERMANENTLY_INVALID_NON_STANDARD_SALE +} from "@hypercerts/marketplace/constants/ValidationCodeConstants.sol"; // Strategies -import { StrategyItemIdsRange } from "@hypercerts/marketplace/executionStrategies/StrategyItemIdsRange.sol"; +import {StrategyItemIdsRange} from "@hypercerts/marketplace/executionStrategies/StrategyItemIdsRange.sol"; // Base test -import { ProtocolBase } from "../ProtocolBase.t.sol"; +import {ProtocolBase} from "../ProtocolBase.t.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { StrategyItemIdsRange public strategyItemIdsRange; @@ -40,10 +46,10 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { } } - function _createMakerBidAndTakerAsk( - uint256 lowerBound, - uint256 upperBound - ) private returns (OrderStructs.Maker memory newMakerBid, OrderStructs.Taker memory newTakerAsk) { + function _createMakerBidAndTakerAsk(uint256 lowerBound, uint256 upperBound) + private + returns (OrderStructs.Maker memory newMakerBid, OrderStructs.Taker memory newTakerAsk) + { uint256 mid = (lowerBound + upperBound) / 2; newMakerBid = _createMultiItemMakerOrder({ @@ -82,7 +88,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { newTakerAsk = OrderStructs.Taker({ recipient: takerUser, - additionalParameters: abi.encode(takerAskItemIds, _offeredAmounts({ length: 3, amount: 1 })) + additionalParameters: abi.encode(takerAskItemIds, _offeredAmounts({length: 3, amount: 1})) }); } @@ -98,10 +104,8 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { _setUpUsers(); _setUpNewStrategy(); - (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = _createMakerBidAndTakerAsk( - lowerBound, - upperBound - ); + (OrderStructs.Maker memory makerBid, OrderStructs.Taker memory takerAsk) = + _createMakerBidAndTakerAsk(lowerBound, upperBound); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -111,7 +115,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Maker user has received the asset assertEq(mockERC721.ownerOf(lowerBound), makerUser); @@ -160,7 +164,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { OrderStructs.Taker memory takerAsk = OrderStructs.Taker({ recipient: takerUser, - additionalParameters: abi.encode(takerAskItemIds, _offeredAmounts({ length: 3, amount: 2 })) + additionalParameters: abi.encode(takerAskItemIds, _offeredAmounts({length: 3, amount: 2})) }); // Sign order @@ -171,7 +175,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { // Execute taker ask transaction vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Maker user has received the asset assertEq(mockERC1155.balanceOf(makerUser, lowerBound), 2); @@ -201,7 +205,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(); // EVM revert vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testZeroDesiredAmount() public { @@ -218,12 +222,12 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testWrongQuoteType() public { _setUpNewStrategy(); - (OrderStructs.Maker memory makerBid, ) = _createMakerBidAndTakerAsk(5, 10); + (OrderStructs.Maker memory makerBid,) = _createMakerBidAndTakerAsk(5, 10); makerBid.quoteType = QuoteType.Ask; (bool isValid, bytes4 errorSelector) = strategyItemIdsRange.isMakerOrderValid(makerBid, selector); @@ -246,11 +250,11 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { takerAskItemIds[0] = 5; takerAskItemIds[1] = 7; takerAskItemIds[2] = 10; - takerAsk.additionalParameters = abi.encode(takerAskItemIds, _offeredAmounts({ length: 4, amount: 1 })); + takerAsk.additionalParameters = abi.encode(takerAskItemIds, _offeredAmounts({length: 4, amount: 1})); vm.prank(takerUser); vm.expectRevert(OrderInvalid.selector); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testTakerAskRevertIfAmountIsZeroOrGreaterThanOneERC721() public { @@ -280,7 +284,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { // It fails at 2nd item in the array (greater than 1) vm.expectRevert(OrderInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Re-adjust the amounts invalidAmounts[0] = 0; @@ -292,7 +296,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { // It now fails at 1st item in the array (equal to 0) vm.expectRevert(OrderInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testMakerBidItemIdsLowerBandHigherThanOrEqualToUpperBand() public { @@ -311,7 +315,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(errorSelector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // lower band == upper band makerBid.additionalParameters = abi.encode(5, 5, 1); @@ -321,7 +325,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(OrderInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testTakerAskDuplicatedItemIds() public { @@ -334,7 +338,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { invalidItemIds[1] = 7; invalidItemIds[2] = 7; - takerAsk.additionalParameters = abi.encode(invalidItemIds, _offeredAmounts({ length: 3, amount: 1 })); + takerAsk.additionalParameters = abi.encode(invalidItemIds, _offeredAmounts({length: 3, amount: 1})); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -345,7 +349,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(OrderInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testTakerAskUnsortedItemIds() public { @@ -358,7 +362,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { invalidItemIds[1] = 10; invalidItemIds[2] = 7; - takerAsk.additionalParameters = abi.encode(invalidItemIds, _offeredAmounts({ length: 3, amount: 1 })); + takerAsk.additionalParameters = abi.encode(invalidItemIds, _offeredAmounts({length: 3, amount: 1})); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -369,7 +373,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(OrderInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testTakerAskOfferedAmountNotEqualToDesiredAmount() public { @@ -381,7 +385,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { itemIds[0] = 5; itemIds[1] = 10; - takerAsk.additionalParameters = abi.encode(itemIds, _offeredAmounts({ length: 2, amount: 1 })); + takerAsk.additionalParameters = abi.encode(itemIds, _offeredAmounts({length: 2, amount: 1})); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -392,7 +396,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(OrderInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testTakerAskOfferedItemIdTooLow() public { @@ -411,7 +415,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { itemIds[0] = itemIdOne; itemIds[1] = itemIdTwo; - takerAsk.additionalParameters = abi.encode(itemIds, _offeredAmounts({ length: 2, amount: 1 })); + takerAsk.additionalParameters = abi.encode(itemIds, _offeredAmounts({length: 2, amount: 1})); // Sign order bytes memory signature = _signMakerOrder(makerBid, makerUserPK); @@ -421,7 +425,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(OrderInvalid.selector); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testInactiveStrategy() public { @@ -442,7 +446,7 @@ contract ItemIdsRangeOrdersTest is ProtocolBase, IStrategyManager { vm.expectRevert(abi.encodeWithSelector(IExecutionManager.StrategyNotAvailable.selector, 1)); vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); } function testInvalidSelector() public { diff --git a/contracts/test/foundry/marketplace/executionStrategies/MultiFillCollectionOrders.t.sol b/contracts/test/foundry/marketplace/executionStrategies/MultiFillCollectionOrders.t.sol index 4e8f9f37..5fd15bda 100644 --- a/contracts/test/foundry/marketplace/executionStrategies/MultiFillCollectionOrders.t.sol +++ b/contracts/test/foundry/marketplace/executionStrategies/MultiFillCollectionOrders.t.sol @@ -2,22 +2,22 @@ pragma solidity >=0.8.7; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Interfaces -import { IExecutionManager } from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; -import { IStrategyManager } from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; +import {IExecutionManager} from "@hypercerts/marketplace/interfaces/IExecutionManager.sol"; +import {IStrategyManager} from "@hypercerts/marketplace/interfaces/IStrategyManager.sol"; // Mock files and other tests -import { StrategyTestMultiFillCollectionOrder } from "../utils/StrategyTestMultiFillCollectionOrder.sol"; -import { ProtocolBase } from "../ProtocolBase.t.sol"; +import {StrategyTestMultiFillCollectionOrder} from "../utils/StrategyTestMultiFillCollectionOrder.sol"; +import {ProtocolBase} from "../ProtocolBase.t.sol"; // Constants -import { ONE_HUNDRED_PERCENT_IN_BP } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {ONE_HUNDRED_PERCENT_IN_BP} from "@hypercerts/marketplace/constants/NumericConstants.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract MultiFillCollectionOrdersTest is ProtocolBase, IStrategyManager { uint256 private constant price = 1 ether; // Fixed price of sale @@ -85,7 +85,7 @@ contract MultiFillCollectionOrdersTest is ProtocolBase, IStrategyManager { // Execute the first taker ask transaction by the first taker user vm.prank(takerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Taker user has received the asset assertEq(mockERC721.ownerOf(0), makerUser); @@ -120,7 +120,7 @@ contract MultiFillCollectionOrdersTest is ProtocolBase, IStrategyManager { // Execute a second taker ask transaction from the second taker user vm.prank(secondTakerUser); - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE, _EMPTY_AFFILIATE); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, _EMPTY_MERKLE_TREE); // Taker user has received the 3 assets assertEq(mockERC721.ownerOf(1), makerUser); @@ -132,9 +132,8 @@ contract MultiFillCollectionOrdersTest is ProtocolBase, IStrategyManager { // Taker ask user receives 99.5% of the whole price (0.5% protocol) assertEq( weth.balanceOf(secondTakerUser), - _initialWETHBalanceUser + - 3 * - ((price * _sellerProceedBpWithStandardProtocolFeeBp) / ONE_HUNDRED_PERCENT_IN_BP) + _initialWETHBalanceUser + + 3 * ((price * _sellerProceedBpWithStandardProtocolFeeBp) / ONE_HUNDRED_PERCENT_IN_BP) ); // Verify the nonce is now marked as executed assertEq(looksRareProtocol.userOrderNonce(makerUser, makerBid.orderNonce), MAGIC_VALUE_ORDER_NONCE_EXECUTED); @@ -182,13 +181,7 @@ contract MultiFillCollectionOrdersTest is ProtocolBase, IStrategyManager { // It should revert if strategy is not available vm.prank(takerUser); vm.expectRevert(abi.encodeWithSelector(IExecutionManager.StrategyNotAvailable.selector, 1)); - looksRareProtocol.executeTakerAsk( - _genericTakerOrder(), - makerBid, - signature, - _EMPTY_MERKLE_TREE, - _EMPTY_AFFILIATE - ); + looksRareProtocol.executeTakerAsk(_genericTakerOrder(), makerBid, signature, _EMPTY_MERKLE_TREE); } } } diff --git a/contracts/test/foundry/marketplace/utils/BytesLib.sol b/contracts/test/foundry/marketplace/utils/BytesLib.sol index d4140def..7d0a3ffa 100644 --- a/contracts/test/foundry/marketplace/utils/BytesLib.sol +++ b/contracts/test/foundry/marketplace/utils/BytesLib.sol @@ -47,9 +47,7 @@ library BytesLib { } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) - } { - mstore(mc, mload(cc)) - } + } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) diff --git a/contracts/test/foundry/marketplace/utils/EIP712MerkleTree.sol b/contracts/test/foundry/marketplace/utils/EIP712MerkleTree.sol index a17c3275..00e89a30 100644 --- a/contracts/test/foundry/marketplace/utils/EIP712MerkleTree.sol +++ b/contracts/test/foundry/marketplace/utils/EIP712MerkleTree.sol @@ -2,20 +2,20 @@ pragma solidity 0.8.17; // Forge test -import { Test } from "forge-std/Test.sol"; +import {Test} from "forge-std/Test.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Core contracts -import { LooksRareProtocol } from "@hypercerts/marketplace/LooksRareProtocol.sol"; +import {LooksRareProtocol} from "@hypercerts/marketplace/LooksRareProtocol.sol"; // Utils -import { MerkleWithPosition } from "./MerkleWithPosition.sol"; -import { MathLib } from "./MathLib.sol"; +import {MerkleWithPosition} from "./MerkleWithPosition.sol"; +import {MathLib} from "./MathLib.sol"; // Constants -import { MAX_CALLDATA_PROOF_LENGTH } from "@hypercerts/marketplace/constants/NumericConstants.sol"; +import {MAX_CALLDATA_PROOF_LENGTH} from "@hypercerts/marketplace/constants/NumericConstants.sol"; contract EIP712MerkleTree is Test { using OrderStructs for OrderStructs.Maker; @@ -26,11 +26,10 @@ contract EIP712MerkleTree is Test { looksRareProtocol = _looksRareProtocol; } - function sign( - uint256 privateKey, - OrderStructs.Maker[] memory makerOrders, - uint256 makerOrderIndex - ) external returns (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) { + function sign(uint256 privateKey, OrderStructs.Maker[] memory makerOrders, uint256 makerOrderIndex) + external + returns (bytes memory signature, OrderStructs.MerkleTree memory merkleTree) + { uint256 bidCount = makerOrders.length; uint256 treeHeight = MathLib.log2(bidCount); if (2 ** treeHeight != bidCount || treeHeight == 0) { @@ -43,9 +42,7 @@ contract EIP712MerkleTree is Test { for (uint256 i; i < bidCount; i++) { leaves[i] = OrderStructs.MerkleTreeNode({ value: makerOrders[i].hash(), - position: i % 2 == 0 - ? OrderStructs.MerkleTreeNodePosition.Left - : OrderStructs.MerkleTreeNodePosition.Right + position: i % 2 == 0 ? OrderStructs.MerkleTreeNodePosition.Left : OrderStructs.MerkleTreeNodePosition.Right }); } @@ -53,9 +50,7 @@ contract EIP712MerkleTree is Test { for (uint256 i = bidCount; i < leafCount; i++) { leaves[i] = OrderStructs.MerkleTreeNode({ value: emptyMakerOrderHash, - position: i % 2 == 0 - ? OrderStructs.MerkleTreeNodePosition.Left - : OrderStructs.MerkleTreeNodePosition.Right + position: i % 2 == 0 ? OrderStructs.MerkleTreeNodePosition.Left : OrderStructs.MerkleTreeNodePosition.Right }); } @@ -64,7 +59,7 @@ contract EIP712MerkleTree is Test { bytes32 root = merkle.getRoot(leaves); signature = _sign(privateKey, batchOrderTypehash, root); - merkleTree = OrderStructs.MerkleTree({ root: root, proof: proof }); + merkleTree = OrderStructs.MerkleTree({root: root, proof: proof}); } function _emptyMakerOrderHash() private pure returns (bytes32 makerOrderHash) { @@ -72,19 +67,17 @@ contract EIP712MerkleTree is Test { makerOrderHash = makerOrder.hash(); } - function _sign( - uint256 privateKey, - bytes32 batchOrderTypehash, - bytes32 root - ) private view returns (bytes memory signature) { + function _sign(uint256 privateKey, bytes32 batchOrderTypehash, bytes32 root) + private + view + returns (bytes memory signature) + { bytes32 digest = keccak256(abi.encode(batchOrderTypehash, root)); bytes32 domainSeparator = looksRareProtocol.domainSeparator(); - (uint8 v, bytes32 r, bytes32 s) = vm.sign( - privateKey, - keccak256(abi.encodePacked("\x19\x01", domainSeparator, digest)) - ); + (uint8 v, bytes32 r, bytes32 s) = + vm.sign(privateKey, keccak256(abi.encodePacked("\x19\x01", domainSeparator, digest))); signature = abi.encodePacked(r, s, v); } diff --git a/contracts/test/foundry/marketplace/utils/ERC1271Wallet.sol b/contracts/test/foundry/marketplace/utils/ERC1271Wallet.sol index ee76287f..f6eaf418 100644 --- a/contracts/test/foundry/marketplace/utils/ERC1271Wallet.sol +++ b/contracts/test/foundry/marketplace/utils/ERC1271Wallet.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { ERC1271WalletMock } from "openzeppelin-contracts/contracts/mocks/ERC1271WalletMock.sol"; +import {ERC1271WalletMock} from "openzeppelin-contracts/contracts/mocks/ERC1271WalletMock.sol"; contract ERC1271Wallet is ERC1271WalletMock { constructor(address originalOwner) ERC1271WalletMock(originalOwner) {} @@ -10,13 +10,11 @@ contract ERC1271Wallet is ERC1271WalletMock { return this.onERC1155Received.selector; } - function onERC1155BatchReceived( - address, - address, - uint256[] calldata, - uint256[] calldata, - bytes calldata - ) external pure returns (bytes4) { + function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata) + external + pure + returns (bytes4) + { return this.onERC1155BatchReceived.selector; } } diff --git a/contracts/test/foundry/marketplace/utils/MaliciousERC1271Wallet.sol b/contracts/test/foundry/marketplace/utils/MaliciousERC1271Wallet.sol index 965149b3..c13ff909 100644 --- a/contracts/test/foundry/marketplace/utils/MaliciousERC1271Wallet.sol +++ b/contracts/test/foundry/marketplace/utils/MaliciousERC1271Wallet.sol @@ -1,8 +1,8 @@ /// SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { ILooksRareProtocol } from "@hypercerts/marketplace/interfaces/ILooksRareProtocol.sol"; -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {ILooksRareProtocol} from "@hypercerts/marketplace/interfaces/ILooksRareProtocol.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; abstract contract MaliciousERC1271Wallet { enum FunctionToReenter { @@ -31,13 +31,11 @@ abstract contract MaliciousERC1271Wallet { return this.onERC1155Received.selector; } - function onERC1155BatchReceived( - address, - address, - uint256[] calldata, - uint256[] calldata, - bytes calldata - ) external virtual returns (bytes4) { + function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata) + external + virtual + returns (bytes4) + { return this.onERC1155BatchReceived.selector; } @@ -46,7 +44,7 @@ abstract contract MaliciousERC1271Wallet { OrderStructs.Maker memory makerBid; OrderStructs.MerkleTree memory merkleTree; - looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, merkleTree, address(this)); + looksRareProtocol.executeTakerAsk(takerAsk, makerBid, signature, merkleTree); } function _executeTakerBid(bytes memory signature) internal { @@ -54,7 +52,7 @@ abstract contract MaliciousERC1271Wallet { OrderStructs.Maker memory makerAsk; OrderStructs.MerkleTree memory merkleTree; - looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, merkleTree, address(this)); + looksRareProtocol.executeTakerBid(takerBid, makerAsk, signature, merkleTree); } function _executeMultipleTakerBids() internal { @@ -63,6 +61,6 @@ abstract contract MaliciousERC1271Wallet { bytes[] memory signatures = new bytes[](2); OrderStructs.MerkleTree[] memory merkleTrees = new OrderStructs.MerkleTree[](2); - looksRareProtocol.executeMultipleTakerBids(takerBids, makerAsks, signatures, merkleTrees, address(this), false); + looksRareProtocol.executeMultipleTakerBids(takerBids, makerAsks, signatures, merkleTrees, false); } } diff --git a/contracts/test/foundry/marketplace/utils/MaliciousIsValidSignatureERC1271Wallet.sol b/contracts/test/foundry/marketplace/utils/MaliciousIsValidSignatureERC1271Wallet.sol index d8c557ff..c8aaf1ef 100644 --- a/contracts/test/foundry/marketplace/utils/MaliciousIsValidSignatureERC1271Wallet.sol +++ b/contracts/test/foundry/marketplace/utils/MaliciousIsValidSignatureERC1271Wallet.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { MaliciousERC1271Wallet } from "./MaliciousERC1271Wallet.sol"; +import {MaliciousERC1271Wallet} from "./MaliciousERC1271Wallet.sol"; contract MaliciousIsValidSignatureERC1271Wallet is MaliciousERC1271Wallet { constructor(address _looksRareProtocol) MaliciousERC1271Wallet(_looksRareProtocol) {} diff --git a/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedERC1271Wallet.sol b/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedERC1271Wallet.sol index 4881535a..cc790326 100644 --- a/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedERC1271Wallet.sol +++ b/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedERC1271Wallet.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { MaliciousERC1271Wallet } from "./MaliciousERC1271Wallet.sol"; +import {MaliciousERC1271Wallet} from "./MaliciousERC1271Wallet.sol"; contract MaliciousOnERC1155ReceivedERC1271Wallet is MaliciousERC1271Wallet { constructor(address _looksRareProtocol) MaliciousERC1271Wallet(_looksRareProtocol) {} @@ -18,13 +18,11 @@ contract MaliciousOnERC1155ReceivedERC1271Wallet is MaliciousERC1271Wallet { return this.onERC1155Received.selector; } - function onERC1155BatchReceived( - address, - address, - uint256[] calldata, - uint256[] calldata, - bytes calldata - ) external override returns (bytes4) { + function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata) + external + override + returns (bytes4) + { if (functionToReenter == FunctionToReenter.ExecuteTakerAsk) { _executeTakerAsk(new bytes(0)); } else if (functionToReenter == FunctionToReenter.ExecuteTakerBid) { diff --git a/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet.sol b/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet.sol index 544aeb28..95ba4347 100644 --- a/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet.sol +++ b/contracts/test/foundry/marketplace/utils/MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { MaliciousERC1271Wallet } from "./MaliciousERC1271Wallet.sol"; +import {MaliciousERC1271Wallet} from "./MaliciousERC1271Wallet.sol"; contract MaliciousOnERC1155ReceivedTheThirdTimeERC1271Wallet is MaliciousERC1271Wallet { uint256 private isValidSignatureEnterCount; diff --git a/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol b/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol index 3b7cf871..43857193 100644 --- a/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol +++ b/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; /** * @dev Modified from MurkyBase to add each node's position after hashing. @@ -22,10 +22,11 @@ contract MerkleWithPosition { return data[0].value; } - function getProof( - OrderStructs.MerkleTreeNode[] memory data, - uint256 node - ) public pure returns (OrderStructs.MerkleTreeNode[] memory result) { + function getProof(OrderStructs.MerkleTreeNode[] memory data, uint256 node) + public + pure + returns (OrderStructs.MerkleTreeNode[] memory result) + { require(data.length > 1, "won't generate proof for single leaf"); // The size of the proof is equal to the ceiling of log2(numLeaves) result = new OrderStructs.MerkleTreeNode[](log2ceilBitMagic(data.length)); @@ -56,9 +57,11 @@ contract MerkleWithPosition { } ///@dev function is private to prevent unsafe data from being passed - function hashLevel( - OrderStructs.MerkleTreeNode[] memory data - ) private pure returns (OrderStructs.MerkleTreeNode[] memory result) { + function hashLevel(OrderStructs.MerkleTreeNode[] memory data) + private + pure + returns (OrderStructs.MerkleTreeNode[] memory result) + { // Function is private, and all internal callers check that data.length >=2. // Underflow is not possible as lowest possible value for data/result index is 1 // overflow should be safe as length is / 2 always. @@ -67,10 +70,8 @@ contract MerkleWithPosition { if (length & 0x1 == 1) { result = new OrderStructs.MerkleTreeNode[](length / 2 + 1); bytes32 hashed = hashLeafPairs(data[length - 1].value, bytes32(0)); - result[result.length - 1] = OrderStructs.MerkleTreeNode({ - value: hashed, - position: OrderStructs.MerkleTreeNodePosition.Left - }); + result[result.length - 1] = + OrderStructs.MerkleTreeNode({value: hashed, position: OrderStructs.MerkleTreeNodePosition.Left}); } else { result = new OrderStructs.MerkleTreeNode[](length / 2); } diff --git a/contracts/test/foundry/marketplace/utils/MockOrderGenerator.sol b/contracts/test/foundry/marketplace/utils/MockOrderGenerator.sol index 7f6fd135..d6e695f5 100644 --- a/contracts/test/foundry/marketplace/utils/MockOrderGenerator.sol +++ b/contracts/test/foundry/marketplace/utils/MockOrderGenerator.sol @@ -2,22 +2,24 @@ pragma solidity 0.8.17; // Generic interfaces -import { IERC165 } from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC165.sol"; +import {IERC165} from "@looksrare/contracts-libs/contracts/interfaces/generic/IERC165.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Other helpers -import { ProtocolHelpers } from "../utils/ProtocolHelpers.sol"; +import {ProtocolHelpers} from "../utils/ProtocolHelpers.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract MockOrderGenerator is ProtocolHelpers { - function _createMockMakerAskAndTakerBid( - address collection - ) internal view returns (OrderStructs.Maker memory newMakerAsk, OrderStructs.Taker memory newTakerBid) { + function _createMockMakerAskAndTakerBid(address collection) + internal + view + returns (OrderStructs.Maker memory newMakerAsk, OrderStructs.Taker memory newTakerBid) + { CollectionType collectionType = _getCollectionType(collection); newMakerAsk = _createSingleItemMakerOrder({ @@ -37,10 +39,11 @@ contract MockOrderGenerator is ProtocolHelpers { newTakerBid = OrderStructs.Taker(takerUser, abi.encode()); } - function _createMockMakerBidAndTakerAsk( - address collection, - address currency - ) internal view returns (OrderStructs.Maker memory newMakerBid, OrderStructs.Taker memory newTakerAsk) { + function _createMockMakerBidAndTakerAsk(address collection, address currency) + internal + view + returns (OrderStructs.Maker memory newMakerBid, OrderStructs.Taker memory newTakerAsk) + { CollectionType collectionType = _getCollectionType(collection); newMakerBid = _createSingleItemMakerOrder({ @@ -60,16 +63,14 @@ contract MockOrderGenerator is ProtocolHelpers { newTakerAsk = OrderStructs.Taker(takerUser, abi.encode()); } - function _createMockMakerAskAndTakerBidWithBundle( - address collection, - uint256 numberTokens - ) internal view returns (OrderStructs.Maker memory newMakerAsk, OrderStructs.Taker memory newTakerBid) { + function _createMockMakerAskAndTakerBidWithBundle(address collection, uint256 numberTokens) + internal + view + returns (OrderStructs.Maker memory newMakerAsk, OrderStructs.Taker memory newTakerBid) + { CollectionType collectionType = _getCollectionType(collection); - (uint256[] memory itemIds, uint256[] memory amounts) = _setBundleItemIdsAndAmounts( - collectionType, - numberTokens - ); + (uint256[] memory itemIds, uint256[] memory amounts) = _setBundleItemIdsAndAmounts(collectionType, numberTokens); newMakerAsk = _createMultiItemMakerOrder({ quoteType: QuoteType.Ask, @@ -89,17 +90,14 @@ contract MockOrderGenerator is ProtocolHelpers { newTakerBid = OrderStructs.Taker(takerUser, abi.encode()); } - function _createMockMakerBidAndTakerAskWithBundle( - address collection, - address currency, - uint256 numberTokens - ) internal view returns (OrderStructs.Maker memory newMakerBid, OrderStructs.Taker memory newTakerAsk) { + function _createMockMakerBidAndTakerAskWithBundle(address collection, address currency, uint256 numberTokens) + internal + view + returns (OrderStructs.Maker memory newMakerBid, OrderStructs.Taker memory newTakerAsk) + { CollectionType collectionType = _getCollectionType(collection); - (uint256[] memory itemIds, uint256[] memory amounts) = _setBundleItemIdsAndAmounts( - collectionType, - numberTokens - ); + (uint256[] memory itemIds, uint256[] memory amounts) = _setBundleItemIdsAndAmounts(collectionType, numberTokens); newMakerBid = _createMultiItemMakerOrder({ quoteType: QuoteType.Bid, @@ -128,10 +126,11 @@ contract MockOrderGenerator is ProtocolHelpers { } } - function _setBundleItemIdsAndAmounts( - CollectionType collectionType, - uint256 numberTokens - ) private pure returns (uint256[] memory itemIds, uint256[] memory amounts) { + function _setBundleItemIdsAndAmounts(CollectionType collectionType, uint256 numberTokens) + private + pure + returns (uint256[] memory itemIds, uint256[] memory amounts) + { itemIds = new uint256[](numberTokens); amounts = new uint256[](numberTokens); diff --git a/contracts/test/foundry/marketplace/utils/ProtocolHelpers.sol b/contracts/test/foundry/marketplace/utils/ProtocolHelpers.sol index 066bf9b3..a8c092b6 100644 --- a/contracts/test/foundry/marketplace/utils/ProtocolHelpers.sol +++ b/contracts/test/foundry/marketplace/utils/ProtocolHelpers.sol @@ -2,18 +2,18 @@ pragma solidity 0.8.17; // Dependencies -import { BatchOrderTypehashRegistry } from "@hypercerts/marketplace/BatchOrderTypehashRegistry.sol"; +import {BatchOrderTypehashRegistry} from "@hypercerts/marketplace/BatchOrderTypehashRegistry.sol"; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Other tests -import { TestHelpers } from "./TestHelpers.sol"; -import { TestParameters } from "./TestParameters.sol"; +import {TestHelpers} from "./TestHelpers.sol"; +import {TestParameters} from "./TestParameters.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; -import { QuoteType } from "@hypercerts/marketplace/enums/QuoteType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {QuoteType} from "@hypercerts/marketplace/enums/QuoteType.sol"; contract ProtocolHelpers is TestHelpers, TestParameters { using OrderStructs for OrderStructs.Maker; @@ -95,10 +95,8 @@ contract ProtocolHelpers is TestHelpers, TestParameters { function _signMakerOrder(OrderStructs.Maker memory maker, uint256 signerKey) internal view returns (bytes memory) { bytes32 orderHash = _computeOrderHash(maker); - (uint8 v, bytes32 r, bytes32 s) = vm.sign( - signerKey, - keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash)) - ); + (uint8 v, bytes32 r, bytes32 s) = + vm.sign(signerKey, keccak256(abi.encodePacked("\x19\x01", _domainSeparator, orderHash))); return abi.encodePacked(r, s, v); } diff --git a/contracts/test/foundry/marketplace/utils/StrategyTestMultiFillCollectionOrder.sol b/contracts/test/foundry/marketplace/utils/StrategyTestMultiFillCollectionOrder.sol index ea76b14c..80323455 100644 --- a/contracts/test/foundry/marketplace/utils/StrategyTestMultiFillCollectionOrder.sol +++ b/contracts/test/foundry/marketplace/utils/StrategyTestMultiFillCollectionOrder.sol @@ -2,16 +2,16 @@ pragma solidity 0.8.17; // Libraries -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; // Custom errors -import { OrderInvalid } from "@hypercerts/marketplace/errors/SharedErrors.sol"; +import {OrderInvalid} from "@hypercerts/marketplace/errors/SharedErrors.sol"; // Base strategy contracts -import { BaseStrategy, IStrategy } from "@hypercerts/marketplace/executionStrategies/BaseStrategy.sol"; +import {BaseStrategy, IStrategy} from "@hypercerts/marketplace/executionStrategies/BaseStrategy.sol"; // Enums -import { CollectionType } from "@hypercerts/marketplace/enums/CollectionType.sol"; +import {CollectionType} from "@hypercerts/marketplace/enums/CollectionType.sol"; contract StrategyTestMultiFillCollectionOrder is BaseStrategy { using OrderStructs for OrderStructs.Maker; @@ -35,10 +35,10 @@ contract StrategyTestMultiFillCollectionOrder is BaseStrategy { * @param takerAsk Taker ask struct (taker ask-specific parameters for the execution) * @param makerBid Maker bid struct (maker bid-specific parameters for the execution) */ - function executeStrategyWithTakerAsk( - OrderStructs.Taker calldata takerAsk, - OrderStructs.Maker calldata makerBid - ) external returns (uint256 price, uint256[] memory itemIds, uint256[] memory amounts, bool isNonceInvalidated) { + function executeStrategyWithTakerAsk(OrderStructs.Taker calldata takerAsk, OrderStructs.Maker calldata makerBid) + external + returns (uint256 price, uint256[] memory itemIds, uint256[] memory amounts, bool isNonceInvalidated) + { if (msg.sender != LOOKSRARE_PROTOCOL) revert OrderInvalid(); // Only available for ERC721 if (makerBid.collectionType != CollectionType.ERC721) revert OrderInvalid(); @@ -52,10 +52,8 @@ contract StrategyTestMultiFillCollectionOrder is BaseStrategy { uint256 countItemsToFill = amounts.length; if ( - countItemsToFill == 0 || - makerBid.amounts.length != 1 || - itemIds.length != countItemsToFill || - countItemsFillable < countItemsToFill + countItemsFilled + countItemsToFill == 0 || makerBid.amounts.length != 1 || itemIds.length != countItemsToFill + || countItemsFillable < countItemsToFill + countItemsFilled ) revert OrderInvalid(); price *= countItemsToFill; @@ -68,10 +66,12 @@ contract StrategyTestMultiFillCollectionOrder is BaseStrategy { } } - function isMakerOrderValid( - OrderStructs.Maker calldata, - bytes4 - ) external view override returns (bool isValid, bytes4 errorSelector) { + function isMakerOrderValid(OrderStructs.Maker calldata, bytes4) + external + view + override + returns (bool isValid, bytes4 errorSelector) + { // } } diff --git a/contracts/test/foundry/marketplace/utils/TestHelpers.sol b/contracts/test/foundry/marketplace/utils/TestHelpers.sol index 32f9b9b6..66270688 100644 --- a/contracts/test/foundry/marketplace/utils/TestHelpers.sol +++ b/contracts/test/foundry/marketplace/utils/TestHelpers.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { Test } from "forge-std/Test.sol"; -import { BytesLib } from "./BytesLib.sol"; +import {Test} from "forge-std/Test.sol"; +import {BytesLib} from "./BytesLib.sol"; abstract contract TestHelpers is Test { using BytesLib for bytes; diff --git a/contracts/test/foundry/marketplace/utils/TestParameters.sol b/contracts/test/foundry/marketplace/utils/TestParameters.sol index cb073095..44d29cf9 100644 --- a/contracts/test/foundry/marketplace/utils/TestParameters.sol +++ b/contracts/test/foundry/marketplace/utils/TestParameters.sol @@ -1,14 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.17; -import { Test } from "forge-std/Test.sol"; -import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol"; +import {Test} from "forge-std/Test.sol"; +import {OrderStructs} from "@hypercerts/marketplace/libraries/OrderStructs.sol"; abstract contract TestParameters is Test { // Empty constants OrderStructs.MerkleTree internal _EMPTY_MERKLE_TREE; bytes4 internal constant _EMPTY_BYTES4 = bytes4(0); - address internal constant _EMPTY_AFFILIATE = address(0); bytes32 public constant MAGIC_VALUE_ORDER_NONCE_EXECUTED = keccak256("ORDER_NONCE_EXECUTED"); // Addresses @@ -17,7 +16,6 @@ abstract contract TestParameters is Test { address internal constant _recipient = address(90); address internal constant _transferrer = address(100); address internal constant _royaltyRecipient = address(22); - address internal constant _affiliate = address(2); // Currencies address internal constant ETH = address(0); @@ -29,7 +27,7 @@ abstract contract TestParameters is Test { uint16 internal constant _maxProtocolFeeBp = uint16(200); uint16 internal constant _standardRoyaltyFee = uint16(0); - uint256 internal constant _sellerProceedBpWithStandardProtocolFeeBp = 9_950; + uint256 internal constant _sellerProceedBpWithStandardProtocolFeeBp = 9950; // Public/Private keys for maker/taker user uint256 internal constant makerUserPK = 1; @@ -40,15 +38,14 @@ abstract contract TestParameters is Test { address internal constant takerUser = 0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF; // Initial balances - // @dev The balances are on purpose different across users to make sure the tests are properly checking the assertion + // @dev The balances are on purpose different across users to make sure the tests are properly checking the + // assertion uint256 internal constant _initialETHBalanceUser = 100 ether; uint256 internal constant _initialWETHBalanceUser = 10 ether; uint256 internal constant _initialETHBalanceRoyaltyRecipient = 10 ether; uint256 internal constant _initialWETHBalanceRoyaltyRecipient = 25 ether; uint256 internal constant _initialETHBalanceOwner = 50 ether; uint256 internal constant _initialWETHBalanceOwner = 15 ether; - uint256 internal constant _initialETHBalanceAffiliate = 30 ether; - uint256 internal constant _initialWETHBalanceAffiliate = 12 ether; // Chainlink ETH/USD price feed (Ethereum mainnet) address internal constant CHAINLINK_ETH_USD_PRICE_FEED = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419; diff --git a/contracts/test/foundry/protocol/AllowlistMinter.t.sol b/contracts/test/foundry/protocol/AllowlistMinter.t.sol index 8aecd6e7..a16c343c 100644 --- a/contracts/test/foundry/protocol/AllowlistMinter.t.sol +++ b/contracts/test/foundry/protocol/AllowlistMinter.t.sol @@ -1,20 +1,21 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; -import { AllowlistMinter } from "@hypercerts/protocol/AllowlistMinter.sol"; -import { Errors } from "@hypercerts/protocol/libs/Errors.sol"; +import {AllowlistMinter} from "@hypercerts/protocol/AllowlistMinter.sol"; +import {Errors} from "@hypercerts/protocol/libs/Errors.sol"; -import { Merkle } from "murky/Merkle.sol"; +import {Merkle} from "murky/Merkle.sol"; contract MerkleHelper is AllowlistMinter, Merkle { - function generateCustomData( - address[] calldata addresses, - uint256[] calldata units - ) public pure returns (bytes32[] memory data) { + function generateCustomData(address[] calldata addresses, uint256[] calldata units) + public + pure + returns (bytes32[] memory data) + { data = new bytes32[](addresses.length); for (uint256 i = 0; i < addresses.length; i++) { data[i] = _calculateLeaf(addresses[i], units[i]); @@ -39,7 +40,7 @@ contract MerkleHelper is AllowlistMinter, Merkle { function _getSum(uint256[] memory array) public pure returns (uint256 sum) { uint256 len = array.length; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { sum += array[i]; unchecked { ++i; @@ -159,7 +160,7 @@ contract AllowlistTest is PRBTest, StdCheats, StdUtils { } function testBasicAllowlistFuzz(uint256 size) public { - size = bound(size, 4, 5_000); + size = bound(size, 4, 5000); uint256 units = 10_000; bytes32[] memory data = merkle.generateData(size, 10_000); bytes32 root = merkle.getRoot(data); @@ -173,7 +174,7 @@ contract AllowlistTest is PRBTest, StdCheats, StdUtils { } function testProcessClaimFuzz(uint256 size) public { - size = bound(size, 4, 5_000); + size = bound(size, 4, 5000); uint256 value = 10_000; bytes32[] memory data = merkle.generateData(size, value); bytes32 root = merkle.getRoot(data); diff --git a/contracts/test/foundry/protocol/Bitshifting.t.sol b/contracts/test/foundry/protocol/Bitshifting.t.sol index 68bc2cc8..6c4d9fe2 100644 --- a/contracts/test/foundry/protocol/Bitshifting.t.sol +++ b/contracts/test/foundry/protocol/Bitshifting.t.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; contract Bitshifter { /// @dev Bitmask used to expose only upper 128 bits of uint256 @@ -47,21 +47,24 @@ contract BitshiftingTest is PRBTest, StdCheats, StdUtils, Bitshifter { function testTypeMask() public { // 128 1s, 128 0s - assertEq(TYPE_MASK, 115792089237316195423570985008687907852929702298719625575994209400481361428480); + assertEq( + TYPE_MASK, + 115_792_089_237_316_195_423_570_985_008_687_907_852_929_702_298_719_625_575_994_209_400_481_361_428_480 + ); // 128 0s, 128 1s - assertEq(NF_INDEX_MASK, 340282366920938463463374607431768211455); + assertEq(NF_INDEX_MASK, 340_282_366_920_938_463_463_374_607_431_768_211_455); } function testBaseType() public { uint256 baseID = 1 << 128; uint256 baseType = getBaseType(baseID); assertEq(baseID, baseType); - assertEq(baseID, 340282366920938463463374607431768211456); + assertEq(baseID, 340_282_366_920_938_463_463_374_607_431_768_211_456); assertTrue(isBaseType(baseID)); assertEq(getItemIndex(baseID), 0); - assertEq(getBaseType(baseID), 340282366920938463463374607431768211456); + assertEq(getBaseType(baseID), 340_282_366_920_938_463_463_374_607_431_768_211_456); assertFalse(isTypedItem(baseID)); } diff --git a/contracts/test/foundry/protocol/HypercertMinter.batchminting.t.sol b/contracts/test/foundry/protocol/HypercertMinter.batchminting.t.sol index d58f0276..3f8502d6 100644 --- a/contracts/test/foundry/protocol/HypercertMinter.batchminting.t.sol +++ b/contracts/test/foundry/protocol/HypercertMinter.batchminting.t.sol @@ -1,14 +1,15 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { HypercertMinter } from "@hypercerts/protocol/HypercertMinter.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {HypercertMinter} from "@hypercerts/protocol/HypercertMinter.sol"; //solhint-disable-next-line max-line-length -import { ERC1155HolderUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/token/ERC1155/utils/ERC1155HolderUpgradeable.sol"; -import { Merkle } from "murky/Merkle.sol"; -import { IHypercertToken } from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; +import {ERC1155HolderUpgradeable} from + "openzeppelin-contracts-upgradeable/contracts/token/ERC1155/utils/ERC1155HolderUpgradeable.sol"; +import {Merkle} from "murky/Merkle.sol"; +import {IHypercertToken} from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; contract BatchMintingHelper is Merkle, ERC1155HolderUpgradeable { event BatchValueTransfer(uint256[] claimIDs, uint256[] fromTokenIDs, uint256[] toTokenIDs, uint256[] values); @@ -20,10 +21,11 @@ contract BatchMintingHelper is Merkle, ERC1155HolderUpgradeable { bytes32 root; } - function generateCustomData( - address[] memory addresses, - uint256[] memory units - ) public pure returns (bytes32[] memory data) { + function generateCustomData(address[] memory addresses, uint256[] memory units) + public + pure + returns (bytes32[] memory data) + { data = new bytes32[](addresses.length); for (uint256 i = 0; i < addresses.length; i++) { data[i] = _calculateLeaf(addresses[i], units[i]); @@ -62,7 +64,7 @@ contract BatchMintingHelper is Merkle, ERC1155HolderUpgradeable { function _getSum(uint256[] memory array) public pure returns (uint256 sum) { uint256 len = array.length; - for (uint256 i; i < len; ) { + for (uint256 i; i < len;) { sum += array[i]; unchecked { ++i; @@ -107,7 +109,7 @@ contract HypercertBatchMintingTest is PRBTest, StdCheats, StdUtils, BatchMinting proofs[i] = getProof(dataset.data, index); ids[i] = (i + 1) << 128; units[i] = dataset.units[index]; - minter.createAllowlist(user, 10000, dataset.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); + minter.createAllowlist(user, 10_000, dataset.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); } units[3] = 0; @@ -151,8 +153,8 @@ contract HypercertBatchMintingTest is PRBTest, StdCheats, StdUtils, BatchMinting uint256[] memory zeroes = new uint256[](2); - minter.createAllowlist(user, 10000, one.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); - minter.createAllowlist(user, 10000, two.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); + minter.createAllowlist(user, 10_000, one.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); + minter.createAllowlist(user, 10_000, two.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); startHoax(user, 10 ether); @@ -179,7 +181,7 @@ contract HypercertBatchMintingTest is PRBTest, StdCheats, StdUtils, BatchMinting ids[i] = (i + 1) << 128; tokenIDs[i] = ids[i] + 1; units[i] = dataset.units[index]; - minter.createAllowlist(user, 10000, dataset.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); + minter.createAllowlist(user, 10_000, dataset.root, _uri, IHypercertToken.TransferRestrictions.AllowAll); } startHoax(user, 10 ether); @@ -215,11 +217,7 @@ contract HypercertBatchMintingTest is PRBTest, StdCheats, StdUtils, BatchMinting tokenIDs[i] = ids[i] + 1; units[i] = dataset.units[index]; minter.createAllowlist( - user, - _getSum(units), - dataset.root, - _uri, - IHypercertToken.TransferRestrictions.AllowAll + user, _getSum(units), dataset.root, _uri, IHypercertToken.TransferRestrictions.AllowAll ); } @@ -254,7 +252,7 @@ contract HypercertBatchMintingTest is PRBTest, StdCheats, StdUtils, BatchMinting ids[i] = (i + 1) << 128; tokenIDs[i] = ids[i] + 1; units[i] = dataset.units[index]; - minter.createAllowlist(user, 10000, dataset.root, _uri, IHypercertToken.TransferRestrictions.DisallowAll); + minter.createAllowlist(user, 10_000, dataset.root, _uri, IHypercertToken.TransferRestrictions.DisallowAll); } startHoax(user, 10 ether); @@ -289,11 +287,7 @@ contract HypercertBatchMintingTest is PRBTest, StdCheats, StdUtils, BatchMinting tokenIDs[i] = ids[i] + 1; units[i] = dataset.units[index]; minter.createAllowlist( - user, - 10000, - dataset.root, - _uri, - IHypercertToken.TransferRestrictions.FromCreatorOnly + user, 10_000, dataset.root, _uri, IHypercertToken.TransferRestrictions.FromCreatorOnly ); } diff --git a/contracts/test/foundry/protocol/HypercertMinter.pausable.t.sol b/contracts/test/foundry/protocol/HypercertMinter.pausable.t.sol index ae849161..a4b63061 100644 --- a/contracts/test/foundry/protocol/HypercertMinter.pausable.t.sol +++ b/contracts/test/foundry/protocol/HypercertMinter.pausable.t.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { HypercertMinter } from "@hypercerts/protocol/HypercertMinter.sol"; -import { IHypercertToken } from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {HypercertMinter} from "@hypercerts/protocol/HypercertMinter.sol"; +import {IHypercertToken} from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; contract PausableTestHelper { /** @@ -86,13 +86,7 @@ contract HypercertMinterPausableTest is PRBTest, StdCheats, StdUtils, PausableTe hypercertMinter.mintClaim(owner, 1, _uri, IHypercertToken.TransferRestrictions.AllowAll); vm.expectRevert("Pausable: paused"); - hypercertMinter.mintClaimWithFractions( - owner, - 1, - fractions, - _uri, - IHypercertToken.TransferRestrictions.AllowAll - ); + hypercertMinter.mintClaimWithFractions(owner, 1, fractions, _uri, IHypercertToken.TransferRestrictions.AllowAll); vm.expectRevert("Pausable: paused"); hypercertMinter.mintClaimFromAllowlist(owner, proofs, 2, 1000); diff --git a/contracts/test/foundry/protocol/HypercertMinter.t.sol b/contracts/test/foundry/protocol/HypercertMinter.t.sol index 86364b56..86bbe1d5 100644 --- a/contracts/test/foundry/protocol/HypercertMinter.t.sol +++ b/contracts/test/foundry/protocol/HypercertMinter.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { Merkle } from "murky/Merkle.sol"; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { HypercertMinter } from "@hypercerts/protocol/HypercertMinter.sol"; -import { IHypercertToken } from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {Merkle} from "murky/Merkle.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {HypercertMinter} from "@hypercerts/protocol/HypercertMinter.sol"; +import {IHypercertToken} from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; contract MinterTestHelper { event ClaimStored(uint256 indexed claimID, string uri, uint256 totalUnits); @@ -78,7 +78,7 @@ contract HypercertMinterTest is PRBTest, StdCheats, StdUtils, MinterTestHelper { } function testClaimSingleFraction() public { - uint256 units = 10000; + uint256 units = 10_000; vm.expectEmit(true, true, true, true); emit ClaimStored(1 << 128, _uri, units); @@ -91,11 +91,7 @@ contract HypercertMinterTest is PRBTest, StdCheats, StdUtils, MinterTestHelper { vm.expectEmit(true, true, true, true); emit ClaimStored(1 << 128, _uri, totalUnits); hypercertMinter.mintClaimWithFractions( - alice, - totalUnits, - fractions, - _uri, - IHypercertToken.TransferRestrictions.AllowAll + alice, totalUnits, fractions, _uri, IHypercertToken.TransferRestrictions.AllowAll ); } @@ -106,11 +102,7 @@ contract HypercertMinterTest is PRBTest, StdCheats, StdUtils, MinterTestHelper { vm.expectEmit(true, true, true, true); emit ClaimStored(1 << 128, _uri, totalUnits); hypercertMinter.mintClaimWithFractions( - alice, - totalUnits, - fractions, - _uri, - IHypercertToken.TransferRestrictions.AllowAll + alice, totalUnits, fractions, _uri, IHypercertToken.TransferRestrictions.AllowAll ); } @@ -120,11 +112,7 @@ contract HypercertMinterTest is PRBTest, StdCheats, StdUtils, MinterTestHelper { vm.expectEmit(true, true, true, true); emit ClaimStored(1 << 128, _uri, totalUnits); hypercertMinter.mintClaimWithFractions( - alice, - totalUnits, - fractions, - _uri, - IHypercertToken.TransferRestrictions.DisallowAll + alice, totalUnits, fractions, _uri, IHypercertToken.TransferRestrictions.DisallowAll ); } @@ -134,11 +122,7 @@ contract HypercertMinterTest is PRBTest, StdCheats, StdUtils, MinterTestHelper { vm.expectEmit(true, true, true, true); emit ClaimStored(1 << 128, _uri, totalUnits); hypercertMinter.mintClaimWithFractions( - alice, - totalUnits, - fractions, - _uri, - IHypercertToken.TransferRestrictions.FromCreatorOnly + alice, totalUnits, fractions, _uri, IHypercertToken.TransferRestrictions.FromCreatorOnly ); } } diff --git a/contracts/test/foundry/protocol/HypercertMinter.transfers.t.sol b/contracts/test/foundry/protocol/HypercertMinter.transfers.t.sol index f4b3ff9b..cd2f1773 100644 --- a/contracts/test/foundry/protocol/HypercertMinter.transfers.t.sol +++ b/contracts/test/foundry/protocol/HypercertMinter.transfers.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { Errors } from "@hypercerts/protocol/libs/Errors.sol"; -import { HypercertMinter } from "@hypercerts/protocol/HypercertMinter.sol"; -import { IHypercertToken } from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {Errors} from "@hypercerts/protocol/libs/Errors.sol"; +import {HypercertMinter} from "@hypercerts/protocol/HypercertMinter.sol"; +import {IHypercertToken} from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; /// @dev Testing transfer restrictions on hypercerts contract HypercertMinterTransferTest is PRBTest, StdCheats, StdUtils { @@ -22,7 +22,7 @@ contract HypercertMinterTransferTest is PRBTest, StdCheats, StdUtils { function setUp() public { hypercertMinter = new HypercertMinter(); _uri = "ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi"; - _units = 10000; + _units = 10_000; baseID = 1 << 128; tokenIndex = 1; tokenID = baseID + tokenIndex; diff --git a/contracts/test/foundry/protocol/PerformanceTesting.t.sol b/contracts/test/foundry/protocol/PerformanceTesting.t.sol index 7b2a71d3..956fd3bb 100644 --- a/contracts/test/foundry/protocol/PerformanceTesting.t.sol +++ b/contracts/test/foundry/protocol/PerformanceTesting.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { HypercertMinter } from "@hypercerts/protocol/HypercertMinter.sol"; -import { Merkle } from "murky/Merkle.sol"; -import { IHypercertToken } from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {HypercertMinter} from "@hypercerts/protocol/HypercertMinter.sol"; +import {Merkle} from "murky/Merkle.sol"; +import {IHypercertToken} from "@hypercerts/protocol/interfaces/IHypercertToken.sol"; // forge test -vv --match-path test/foundry/PerformanceTesting.t.sol @@ -78,10 +78,11 @@ contract PerformanceTestHelper is Merkle { leaf = keccak256(bytes.concat(keccak256(abi.encode(account, amount)))); } - function generateCustomData( - address[] memory addresses, - uint256[] memory units - ) public pure returns (bytes32[] memory data) { + function generateCustomData(address[] memory addresses, uint256[] memory units) + public + pure + returns (bytes32[] memory data) + { data = new bytes32[](addresses.length); for (uint256 i = 0; i < addresses.length; i++) { data[i] = _calculateLeaf(addresses[i], units[i]); @@ -129,7 +130,7 @@ contract PerformanceTesting is PRBTest, StdCheats, StdUtils, PerformanceTestHelp function setUp() public { alice = address(1); hypercertMinter = new HypercertMinter(); - bytes32[] memory data = generateData(12, 10000); + bytes32[] memory data = generateData(12, 10_000); rootHash = getRoot(data); proof = getProof(data, 6); @@ -149,11 +150,7 @@ contract PerformanceTesting is PRBTest, StdCheats, StdUtils, PerformanceTestHelp ids[i] = (i + 1) << 128; units[i] = dataset.units[index]; hypercertMinter.createAllowlist( - alice, - dataset.units[index], - dataset.root, - _uri, - IHypercertToken.TransferRestrictions.AllowAll + alice, dataset.units[index], dataset.root, _uri, IHypercertToken.TransferRestrictions.AllowAll ); } } @@ -170,7 +167,7 @@ contract PerformanceTesting is PRBTest, StdCheats, StdUtils, PerformanceTestHelp // Mint Hypercert with 1 fraction function testClaimSingleFraction() public { - hypercertMinter.mintClaim(alice, 10000, _uri, IHypercertToken.TransferRestrictions.AllowAll); + hypercertMinter.mintClaim(alice, 10_000, _uri, IHypercertToken.TransferRestrictions.AllowAll); } function testClaimSingleFractionFuzz(address account, uint256 value) public { @@ -188,11 +185,7 @@ contract PerformanceTesting is PRBTest, StdCheats, StdUtils, PerformanceTestHelp uint256 totalUnits = getSum(fractions); hypercertMinter.mintClaimWithFractions( - alice, - totalUnits, - fractions, - _uri, - IHypercertToken.TransferRestrictions.AllowAll + alice, totalUnits, fractions, _uri, IHypercertToken.TransferRestrictions.AllowAll ); } @@ -201,11 +194,7 @@ contract PerformanceTesting is PRBTest, StdCheats, StdUtils, PerformanceTestHelp uint256 totalUnits = getSum(fractions); hypercertMinter.mintClaimWithFractions( - alice, - totalUnits, - fractions, - _uri, - IHypercertToken.TransferRestrictions.AllowAll + alice, totalUnits, fractions, _uri, IHypercertToken.TransferRestrictions.AllowAll ); } @@ -215,11 +204,7 @@ contract PerformanceTesting is PRBTest, StdCheats, StdUtils, PerformanceTestHelp uint256 totalUnits = getSum(fractions); hypercertMinter.mintClaimWithFractions( - alice, - totalUnits, - fractions, - "https://example.com/ipfsHash", - IHypercertToken.TransferRestrictions.AllowAll + alice, totalUnits, fractions, "https://example.com/ipfsHash", IHypercertToken.TransferRestrictions.AllowAll ); } diff --git a/contracts/test/foundry/protocol/SemiFungible1155.allowances.t.sol b/contracts/test/foundry/protocol/SemiFungible1155.allowances.t.sol index 438b1893..efe78bef 100644 --- a/contracts/test/foundry/protocol/SemiFungible1155.allowances.t.sol +++ b/contracts/test/foundry/protocol/SemiFungible1155.allowances.t.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { SemiFungible1155Helper } from "./SemiFungibleHelper.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {SemiFungible1155Helper} from "./SemiFungibleHelper.sol"; /// @dev See the "Writing Tests" section in the Foundry Book if this is your first time with Forge. /// https://book.getfoundry.sh/forge/writing-tests diff --git a/contracts/test/foundry/protocol/SemiFungible1155.burning.t.sol b/contracts/test/foundry/protocol/SemiFungible1155.burning.t.sol index a5db0bd6..1e3c21a4 100644 --- a/contracts/test/foundry/protocol/SemiFungible1155.burning.t.sol +++ b/contracts/test/foundry/protocol/SemiFungible1155.burning.t.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { SemiFungible1155Helper } from "./SemiFungibleHelper.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {SemiFungible1155Helper} from "./SemiFungibleHelper.sol"; /// @dev See the "Writing Tests" section in the Foundry Book if this is your first time with Forge. /// https://book.getfoundry.sh/forge/writing-tests diff --git a/contracts/test/foundry/protocol/SemiFungible1155.minting.t.sol b/contracts/test/foundry/protocol/SemiFungible1155.minting.t.sol index ae7f78d6..9458a8cc 100644 --- a/contracts/test/foundry/protocol/SemiFungible1155.minting.t.sol +++ b/contracts/test/foundry/protocol/SemiFungible1155.minting.t.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { stdError } from "forge-std/StdError.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { SemiFungible1155Helper } from "./SemiFungibleHelper.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {stdError} from "forge-std/StdError.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {SemiFungible1155Helper} from "./SemiFungibleHelper.sol"; /// @dev See the "Writing Tests" section in the Foundry Book if this is your first time with Forge. /// https://book.getfoundry.sh/forge/writing-tests @@ -64,7 +64,7 @@ contract SemiFungible1155MintingTest is PRBTest, StdCheats, StdUtils, SemiFungib semiFungible.setMaxType(); vm.expectRevert(stdError.arithmeticError); - semiFungible.mintValue(alice, 10000, _uri); + semiFungible.mintValue(alice, 10_000, _uri); } // HAPPY MINTING @@ -81,17 +81,17 @@ contract SemiFungible1155MintingTest is PRBTest, StdCheats, StdUtils, SemiFungib // uint256 value vm.expectEmit(true, true, true, true); emit TransferSingle(alice, address(0), address(0), _baseID, 0); - uint256 baseID = semiFungible.mintValue(alice, 10000, _uri); + uint256 baseID = semiFungible.mintValue(alice, 10_000, _uri); assertEq(baseID, _baseID); assertEq(semiFungible.ownerOf(baseID), address(0)); assertEq(semiFungible.creator(baseID), alice); - assertEq(semiFungible.unitsOf(baseID), 10000); + assertEq(semiFungible.unitsOf(baseID), 10_000); - semiFungible.validateOwnerBalanceUnits(baseID + 1, alice, 1, 10000); + semiFungible.validateOwnerBalanceUnits(baseID + 1, alice, 1, 10_000); - assertEq(semiFungible.tokenValue(baseID), 10000); - assertEq(semiFungible.tokenValue(baseID + 1), 10000); + assertEq(semiFungible.tokenValue(baseID), 10_000); + assertEq(semiFungible.tokenValue(baseID + 1), 10_000); assertEq(semiFungible.tokenValue(baseID + 2), 0); } @@ -123,7 +123,7 @@ contract SemiFungible1155MintingTest is PRBTest, StdCheats, StdUtils, SemiFungib values[2] = 5000; uint256 baseID = semiFungible.mintValue(alice, values, _uri); - assertEq(semiFungible.unitsOf(baseID), 15000); + assertEq(semiFungible.unitsOf(baseID), 15_000); assertEq(semiFungible.ownerOf(baseID), address(0)); // Swap because of splitting logic diff --git a/contracts/test/foundry/protocol/SemiFungible1155.t.sol b/contracts/test/foundry/protocol/SemiFungible1155.t.sol index 09918e69..ea5746c1 100644 --- a/contracts/test/foundry/protocol/SemiFungible1155.t.sol +++ b/contracts/test/foundry/protocol/SemiFungible1155.t.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { SemiFungible1155Helper } from "./SemiFungibleHelper.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {SemiFungible1155Helper} from "./SemiFungibleHelper.sol"; /// @dev See the "Writing Tests" section in the Foundry Book if this is your first time with Forge. /// https://book.getfoundry.sh/forge/writing-tests @@ -35,16 +35,16 @@ contract SemiFungible1155DefaultTest is PRBTest, StdCheats, StdUtils, SemiFungib startHoax(alice, 100 ether); - semiFungible.mintValue(alice, 10000, _uri); + semiFungible.mintValue(alice, 10_000, _uri); semiFungible.splitValue(alice, tokenID, values); - assertEq(semiFungible.unitsOf(baseID), 10000); + assertEq(semiFungible.unitsOf(baseID), 10_000); semiFungible.validateOwnerBalanceUnits(tokenID, alice, 1, values[0]); semiFungible.validateOwnerBalanceUnits(tokenID + 1, alice, 1, values[1]); // Units - assertEq(semiFungible.unitsOf(baseID), 10000); + assertEq(semiFungible.unitsOf(baseID), 10_000); assertEq(semiFungible.unitsOf(tokenID), 7000); assertEq(semiFungible.unitsOf(tokenID + 1), 3000); } diff --git a/contracts/test/foundry/protocol/SemiFungible1155.transfers.t.sol b/contracts/test/foundry/protocol/SemiFungible1155.transfers.t.sol index 5a910740..bcad3900 100644 --- a/contracts/test/foundry/protocol/SemiFungible1155.transfers.t.sol +++ b/contracts/test/foundry/protocol/SemiFungible1155.transfers.t.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { SemiFungible1155Helper } from "./SemiFungibleHelper.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {SemiFungible1155Helper} from "./SemiFungibleHelper.sol"; /// @dev See the "Writing Tests" section in the Foundry Book if this is your first time with Forge. /// https://book.getfoundry.sh/forge/writing-tests @@ -24,14 +24,14 @@ contract SemiFungible1155TransferTest is PRBTest, StdCheats, StdUtils { // UNHAPPY PATHS function testFailTransferTypeIDToken() public { - semiFungible.mintValue(alice, 10000, _uri); + semiFungible.mintValue(alice, 10_000, _uri); //NotApprovedOrOWner, since no owner semiFungible.safeTransferFrom(alice, bob, 1 << 128, 1, ""); } function testFailTransferNonExistingFractionToken() public { - semiFungible.mintValue(alice, 10000, _uri); + semiFungible.mintValue(alice, 10_000, _uri); //NotApprovedOrOWner, since no owner semiFungible.safeTransferFrom(alice, bob, 1 << (128 + 2), 1, ""); @@ -59,10 +59,10 @@ contract SemiFungible1155TransferTest is PRBTest, StdCheats, StdUtils { uint256 baseID = 1 << 128; uint128 tokenID = 1; - semiFungible.mintValue(alice, 10000, _uri); + semiFungible.mintValue(alice, 10_000, _uri); assertEq(semiFungible.balanceOf(alice, baseID), 0); - semiFungible.validateOwnerBalanceUnits(baseID + tokenID, alice, 1, 10000); + semiFungible.validateOwnerBalanceUnits(baseID + tokenID, alice, 1, 10_000); assertEq(semiFungible.balanceOf(bob, baseID), 0); semiFungible.validateNotOwnerNoBalanceNoUnits(baseID + tokenID, bob); @@ -78,7 +78,7 @@ contract SemiFungible1155TransferTest is PRBTest, StdCheats, StdUtils { semiFungible.validateNotOwnerNoBalanceNoUnits(baseID + tokenID, alice); // Updates token ownership - semiFungible.validateOwnerBalanceUnits(baseID + tokenID, bob, 1, 10000); + semiFungible.validateOwnerBalanceUnits(baseID + tokenID, bob, 1, 10_000); } function testFuzzTransferFullToken(address from, address to, uint256 units) public { diff --git a/contracts/test/foundry/protocol/SemiFungible1155.units.sol b/contracts/test/foundry/protocol/SemiFungible1155.units.sol index 654c1dbb..384bcdfb 100644 --- a/contracts/test/foundry/protocol/SemiFungible1155.units.sol +++ b/contracts/test/foundry/protocol/SemiFungible1155.units.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; -import { SemiFungible1155Helper } from "./SemiFungibleHelper.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; +import {SemiFungible1155Helper} from "./SemiFungibleHelper.sol"; /// @dev See the "Writing Tests" section in the Foundry Book if this is your first time with Forge. /// https://book.getfoundry.sh/forge/writing-tests @@ -28,11 +28,11 @@ contract SemiFungible1155UnitsTest is PRBTest, StdCheats, StdUtils { uint256 baseID = 1 << 128; uint128 tokenID = 1; - semiFungible.mintValue(alice, 10000, _uri); + semiFungible.mintValue(alice, 10_000, _uri); assertEq(semiFungible.unitsOf(baseID), 10_000); - semiFungible.validateOwnerBalanceUnits(baseID + tokenID, alice, 1, 10000); + semiFungible.validateOwnerBalanceUnits(baseID + tokenID, alice, 1, 10_000); semiFungible.validateNotOwnerNoBalanceNoUnits(baseID + tokenID, bob); @@ -51,7 +51,7 @@ contract SemiFungible1155UnitsTest is PRBTest, StdCheats, StdUtils { semiFungible.validateNotOwnerNoBalanceNoUnits(baseID + tokenID, alice); assertEq(semiFungible.balanceOf(bob, baseID), 0); - semiFungible.validateOwnerBalanceUnits(baseID + tokenID, bob, 1, 10000); + semiFungible.validateOwnerBalanceUnits(baseID + tokenID, bob, 1, 10_000); } function testUnitsMultipleFractions() public { diff --git a/contracts/test/foundry/protocol/SemiFungibleHelper.sol b/contracts/test/foundry/protocol/SemiFungibleHelper.sol index 7555bc9d..82a1c264 100644 --- a/contracts/test/foundry/protocol/SemiFungibleHelper.sol +++ b/contracts/test/foundry/protocol/SemiFungibleHelper.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.16; -import { SemiFungible1155 } from "@hypercerts/protocol/SemiFungible1155.sol"; -import { PRBTest } from "prb-test/PRBTest.sol"; -import { StdCheats } from "forge-std/StdCheats.sol"; -import { StdUtils } from "forge-std/StdUtils.sol"; +import {SemiFungible1155} from "@hypercerts/protocol/SemiFungible1155.sol"; +import {PRBTest} from "prb-test/PRBTest.sol"; +import {StdCheats} from "forge-std/StdCheats.sol"; +import {StdUtils} from "forge-std/StdUtils.sol"; contract SemiFungible1155Helper is SemiFungible1155, PRBTest, StdCheats, StdUtils { error FractionalBurn(); diff --git a/docs/docs/developer/api/contracts/HypercertMinter.md b/docs/docs/developer/api/contracts/HypercertMinter.md index 012e3d60..518efa42 100644 --- a/docs/docs/developer/api/contracts/HypercertMinter.md +++ b/docs/docs/developer/api/contracts/HypercertMinter.md @@ -99,7 +99,7 @@ _Calls AllowlistMinter to verify `proofs`.Mints the `amount` of units for the hy ### burn ```solidity -function burn(address account, uint256 id, uint256 value) external nonpayable +function burn(address account, uint256 id, uint256) external nonpayable ``` Burn a claimtoken; override is needed to update units/values @@ -112,12 +112,12 @@ _see {ERC1155Burnable}_ | ------- | ------- | ----------- | | account | address | undefined | | id | uint256 | undefined | -| value | uint256 | undefined | +| \_2 | uint256 | undefined | ### burnBatch ```solidity -function burnBatch(address account, uint256[] ids, uint256[] values) external nonpayable +function burnBatch(address account, uint256[] ids, uint256[]) external nonpayable ``` Batch burn claimtokens; override is needed to update units/values @@ -130,7 +130,7 @@ _see {ERC1155Burnable}_ | ------- | --------- | ----------- | | account | address | undefined | | ids | uint256[] | undefined | -| values | uint256[] | undefined | +| \_2 | uint256[] | undefined | ### burnFraction diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 988958cc..a353eed7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -195,9 +195,6 @@ importers: solhint-plugin-prettier: specifier: ^0.0.5 version: 0.0.5(prettier-plugin-solidity@1.1.3)(prettier@2.8.8) - solidity-coverage: - specifier: ^0.8.2 - version: 0.8.5(hardhat@2.13.1) solmate: specifier: ^6.2.0 version: 6.2.0