Skip to content

Commit

Permalink
renaming variable
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasMSg committed Oct 9, 2023
1 parent 71295bc commit 53a2cda
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/deploy/deploy/marketplace/10_deploy_exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,7 +38,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
exchangeFeeRecipient,
royaltiesRegistry.address,
orderValidator.address,
newMaxTransfer,
newMatchOrdersLimit,
],
},
upgradeIndex: 0,
Expand Down
10 changes: 5 additions & 5 deletions packages/marketplace/contracts/exchange/Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -71,7 +71,7 @@ contract Exchange is
newDefaultFeeReceiver,
newRoyaltiesProvider
);
__ExchangeCoreInitialize(orderValidatorAddress, maxTransfer);
__ExchangeCoreInitialize(orderValidatorAddress, matchOrdersLimit);
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}

Expand Down Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions packages/marketplace/contracts/exchange/ExchangeCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand Down
31 changes: 23 additions & 8 deletions packages/marketplace/test/exchange/ExchangeSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/marketplace/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,7 +50,7 @@ async function deploy() {
defaultFeeReceiver.address,
await RoyaltiesRegistryAsDeployer.getAddress(),
await OrderValidatorAsAdmin.getAddress(),
maxTransfers,
matchOrdersLimit,
],
{
initializer: '__Exchange_init',
Expand Down

1 comment on commit 53a2cda

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

86.99%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/marketplace/contracts/exchange
   Exchange.sol80.82%71.88%88.24%87.50%100, 182, 64, 80, 91, 91, 91, 91–92, 92, 92–93
   ExchangeCore.sol87.21%67.86%100%95.83%137–138, 138, 138, 141, 207, 209, 213, 234–235, 74
   OrderValidator.sol89.29%84.62%100%92%41, 71–72, 72, 72, 76
   WhiteList.sol97.62%93.75%100%100%64
packages/marketplace/contracts/exchange/libraries
   LibFill.sol60.87%33.33%75%69.23%32–33, 58, 68–69, 69, 69–70
   LibMath.sol27.50%18.75%50%30%100–103, 17–18, 33–34, 50, 50, 50–51, 72, 72, 72–73, 75, 88, 88, 88–89, 93, 93, 93, 93, 93, 97
packages/marketplace/contracts/interfaces
   IOrderValidator.sol100%100%100%100%
   IRoyaltiesProvider.sol100%100%100%100%
   IWhiteList.sol100%100%100%100%
packages/marketplace/contracts/lib-asset
   LibAsset.sol100%100%100%100%
packages/marketplace/contracts/lib-bp
   BpLibrary.sol100%100%100%100%
packages/marketplace/contracts/lib-order
   LibOrder.sol73.33%50%100%100%64, 64, 66, 66
packages/marketplace/contracts/lib-part
   LibPart.sol0%100%0%0%21
packages/marketplace/contracts/royalties
   IERC2981.sol100%100%100%100%
   LibRoyalties2981.sol78.57%50%100%88.89%19–20, 23
packages/marketplace/contracts/royalties-registry
   IMultiRoyaltyRecipients.sol100%100%100%100%
   RoyaltiesRegistry.sol90.40%85.29%100%90.79%158, 162, 208–209, 212–213, 247, 250, 256, 259, 276, 60
packages/marketplace/contracts/transfer-manager
   TransferExecutor.sol90.48%75%100%100%25, 31
   TransferManager.sol80.41%65.38%100%86.75%100–101, 174, 177, 180–181, 181, 181–182, 186, 194, 201–202, 226, 243, 247–249, 249, 249–251, 256–257, 280, 284–285, 293, 63
packages/marketplace/contracts/transfer-manager/interfaces
   IRoyaltyUGC.sol100%100%100%100%
   ITransferExecutor.sol100%100%100%100%
   ITransferManager.sol100%100%100%100%

Please sign in to comment.