From 53a2cdaffeaeb3943343f235b3c4097a78df52a3 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 9 Oct 2023 17:11:23 +0200 Subject: [PATCH] renaming variable --- .../deploy/marketplace/10_deploy_exchange.ts | 4 +-- .../contracts/exchange/Exchange.sol | 10 +++--- .../contracts/exchange/ExchangeCore.sol | 27 ++++++++-------- .../test/exchange/ExchangeSettings.test.ts | 31 ++++++++++++++----- packages/marketplace/test/fixtures.ts | 4 +-- 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/packages/deploy/deploy/marketplace/10_deploy_exchange.ts b/packages/deploy/deploy/marketplace/10_deploy_exchange.ts index 1c64f3be6b..86c7b7e904 100644 --- a/packages/deploy/deploy/marketplace/10_deploy_exchange.ts +++ b/packages/deploy/deploy/marketplace/10_deploy_exchange.ts @@ -20,7 +20,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const newProtocolFeePrimary = 0; const newProtocolFeeSecondary = 250; - const newMaxTransfer = 150; + const newMatchOrdersLimit = 150; await deploy('Exchange', { from: deployer, @@ -38,7 +38,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { exchangeFeeRecipient, royaltiesRegistry.address, orderValidator.address, - newMaxTransfer, + newMatchOrdersLimit, ], }, upgradeIndex: 0, diff --git a/packages/marketplace/contracts/exchange/Exchange.sol b/packages/marketplace/contracts/exchange/Exchange.sol index 96c6faee2d..467b0da985 100644 --- a/packages/marketplace/contracts/exchange/Exchange.sol +++ b/packages/marketplace/contracts/exchange/Exchange.sol @@ -60,7 +60,7 @@ contract Exchange is address newDefaultFeeReceiver, IRoyaltiesProvider newRoyaltiesProvider, IOrderValidator orderValidatorAddress, - uint256 maxTransfer + uint256 matchOrdersLimit ) external initializer { __ERC2771Handler_init_unchained(newTrustedForwarder); __AccessControlEnumerable_init_unchained(); @@ -71,7 +71,7 @@ contract Exchange is newDefaultFeeReceiver, newRoyaltiesProvider ); - __ExchangeCoreInitialize(orderValidatorAddress, maxTransfer); + __ExchangeCoreInitialize(orderValidatorAddress, matchOrdersLimit); _grantRole(DEFAULT_ADMIN_ROLE, admin); } @@ -115,9 +115,9 @@ contract Exchange is } /// @notice setter for max transfer value - /// @param maxTransfer new vaue of max transfers - function setMaxTransferValue(uint256 maxTransfer) external onlyRole(EXCHANGE_ADMIN_ROLE) { - _setMaxTransferValue(maxTransfer); + /// @param matchOrdersLimit new vaue of max orders that can be matched + function setMatchOrdersLimit(uint256 matchOrdersLimit) external onlyRole(EXCHANGE_ADMIN_ROLE) { + _setMatchOrdersLimit(matchOrdersLimit); } /// @notice Change the address of the trusted forwarder for meta-transactions diff --git a/packages/marketplace/contracts/exchange/ExchangeCore.sol b/packages/marketplace/contracts/exchange/ExchangeCore.sol index ddf353c2c0..6d50fb8492 100644 --- a/packages/marketplace/contracts/exchange/ExchangeCore.sol +++ b/packages/marketplace/contracts/exchange/ExchangeCore.sol @@ -28,7 +28,7 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana IOrderValidator public orderValidator; uint256 private constant UINT256_MAX = type(uint256).max; - uint256 private transferMax; + uint256 private matchOrdersLimit; /// @notice stores the fills for orders /// @return order fill @@ -59,21 +59,21 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana ); event OrderValidatorSet(IOrderValidator indexed contractAddress); - /// @notice event for setting new maximum for transfers - /// @param newMaxTransferValue new maximum - event MaxTransferSet(uint256 newMaxTransferValue); + /// @notice event for setting a new limit for orders that can be matched in one transaction + /// @param newMatchOrdersLimit new limit + event MatchOrdersLimitSet(uint256 newMatchOrdersLimit); /// @notice initializer for ExchangeCore /// @param newOrderValidatorAddress new OrderValidator contract address - /// @param maxTransfer max number of transfers + /// @param newMatchOrdersLimit limit of orders that can be matched in one transaction /// @dev initialize permissions for native token exchange // solhint-disable-next-line func-name-mixedcase function __ExchangeCoreInitialize( IOrderValidator newOrderValidatorAddress, - uint256 maxTransfer + uint256 newMatchOrdersLimit ) internal onlyInitializing { _setOrderValidatorContract(newOrderValidatorAddress); - _setMaxTransferValue(maxTransfer); + _setMatchOrdersLimit(newMatchOrdersLimit); } /// @notice set OrderValidator address @@ -84,11 +84,12 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana emit OrderValidatorSet(contractAddress); } - /// @notice setter for max transfer value - /// @param maxTransfer new vaue of max transfers - function _setMaxTransferValue(uint256 maxTransfer) internal { - transferMax = maxTransfer; - emit MaxTransferSet(transferMax); + /// @notice setter for limit of orders that can be matched in one transaction + /// @param newMatchOrdersLimit new limit + function _setMatchOrdersLimit(uint256 newMatchOrdersLimit) internal { + require(newMatchOrdersLimit > 0, "invalid quantity"); + matchOrdersLimit = newMatchOrdersLimit; + emit MatchOrdersLimitSet(matchOrdersLimit); } /// @notice cancel order @@ -109,7 +110,7 @@ abstract contract ExchangeCore is Initializable, TransferExecutor, ITransferMana /// @dev validate orders through validateOrders before matchAndTransfer function _matchOrders(address sender, ExchangeMatch[] calldata matchedOrders) internal { uint256 len = matchedOrders.length; - require(len > 0 && len < transferMax, "invalid exchange match quantities"); + require(len > 0 && len < matchOrdersLimit, "invalid exchange match quantities"); for (uint256 i; i < len; i++) { ExchangeMatch calldata m = matchedOrders[i]; _validateOrders(sender, m.orderLeft, m.signatureLeft, m.orderRight, m.signatureRight); diff --git a/packages/marketplace/test/exchange/ExchangeSettings.test.ts b/packages/marketplace/test/exchange/ExchangeSettings.test.ts index b8561f1be2..09372231a0 100644 --- a/packages/marketplace/test/exchange/ExchangeSettings.test.ts +++ b/packages/marketplace/test/exchange/ExchangeSettings.test.ts @@ -160,28 +160,43 @@ describe('Exchange.sol settings', function () { .to.emit(ExchangeContractAsAdmin, 'DefaultFeeReceiverSet') .withArgs(user.address); }); - it('should not set setMaxTransferValue if caller is not in the role', async function () { + it('should not set setMatchOrdersLimit if caller is not in the role', async function () { const {EXCHANGE_ADMIN_ROLE, ExchangeContractAsUser, user} = await loadFixture(deployFixtures); - const newMaxTransfer = 200; + const newMatchOrdersLimit = 200; await expect( - ExchangeContractAsUser.setMaxTransferValue(newMaxTransfer) + ExchangeContractAsUser.setMatchOrdersLimit(newMatchOrdersLimit) ).to.be.revertedWith( `AccessControl: account ${user.address.toLowerCase()} is missing role ${EXCHANGE_ADMIN_ROLE}` ); }); - it('should be able to set setMaxTransferValue', async function () { + it('should be able to set setMatchOrdersLimit', async function () { const { EXCHANGE_ADMIN_ROLE, ExchangeContractAsAdmin, ExchangeContractAsUser, user, } = await loadFixture(deployFixtures); - const newMaxTransfer = 200; + const newMatchOrdersLimit = 200; await ExchangeContractAsAdmin.grantRole(EXCHANGE_ADMIN_ROLE, user); - await expect(ExchangeContractAsUser.setMaxTransferValue(newMaxTransfer)) - .to.emit(ExchangeContractAsAdmin, 'MaxTransferSet') - .withArgs(newMaxTransfer); + await expect( + ExchangeContractAsUser.setMatchOrdersLimit(newMatchOrdersLimit) + ) + .to.emit(ExchangeContractAsAdmin, 'MatchOrdersLimitSet') + .withArgs(newMatchOrdersLimit); + }); + it('MatchOrdersLimit cannot be set to zero', async function () { + const { + EXCHANGE_ADMIN_ROLE, + ExchangeContractAsAdmin, + ExchangeContractAsUser, + user, + } = await loadFixture(deployFixtures); + const newMatchOrdersLimit = 0; + await ExchangeContractAsAdmin.grantRole(EXCHANGE_ADMIN_ROLE, user); + await expect( + ExchangeContractAsUser.setMatchOrdersLimit(newMatchOrdersLimit) + ).to.be.revertedWith('invalid quantity'); }); }); diff --git a/packages/marketplace/test/fixtures.ts b/packages/marketplace/test/fixtures.ts index ccdacf12a4..3746135c00 100644 --- a/packages/marketplace/test/fixtures.ts +++ b/packages/marketplace/test/fixtures.ts @@ -38,7 +38,7 @@ async function deploy() { const OrderValidatorAsAdmin = await OrderValidatorAsDeployer.connect(admin); const protocolFeePrimary = 123; const protocolFeeSecondary = 250; - const maxTransfers = 150; + const matchOrdersLimit = 150; const ExchangeFactory = await ethers.getContractFactory('Exchange'); const ExchangeContractAsDeployer = await upgrades.deployProxy( ExchangeFactory, @@ -50,7 +50,7 @@ async function deploy() { defaultFeeReceiver.address, await RoyaltiesRegistryAsDeployer.getAddress(), await OrderValidatorAsAdmin.getAddress(), - maxTransfers, + matchOrdersLimit, ], { initializer: '__Exchange_init',