Skip to content

Commit

Permalink
[FLB-02C] Repetitive Value Literal (#881)
Browse files Browse the repository at this point in the history
* Introduce HUNDRED_PERCENT constant

* Another case
  • Loading branch information
zajck committed Jan 9, 2024
1 parent b13ec66 commit bed7579
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions contracts/domain/BosonConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ bytes32 constant CLIENT = keccak256("CLIENT"); // Role for clients of the Protoc
bytes32 constant UPGRADER = keccak256("UPGRADER"); // Role for performing contract and config upgrades
bytes32 constant FEE_COLLECTOR = keccak256("FEE_COLLECTOR"); // Role for collecting fees from the protocol

// Generic
uint256 constant HUNDRED_PERCENT = 10000; // 100% in basis points

// Pause Handler
uint256 constant ALL_REGIONS_MASK = (1 << (uint256(type(BosonTypes.PausableRegion).max) + 1)) - 1;

Expand Down
6 changes: 3 additions & 3 deletions contracts/protocol/bases/OfferBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ contract OfferBase is ProtocolBase, IBosonOfferEvents {
disputeResolutionTerms.feeAmount = feeAmount;
disputeResolutionTerms.buyerEscalationDeposit =
(feeAmount * fees.buyerEscalationDepositPercentage) /
10000;
HUNDRED_PERCENT;
}
protocolEntities().disputeResolutionTerms[_offer.id] = disputeResolutionTerms;
}
Expand Down Expand Up @@ -236,9 +236,9 @@ contract OfferBase is ProtocolBase, IBosonOfferEvents {
uint256 protocolFee = getProtocolFee(_offer.exchangeToken, offerPrice);

// Calculate the agent fee amount
uint256 agentFeeAmount = (agent.feePercentage * offerPrice) / 10000;
uint256 agentFeeAmount = (agent.feePercentage * offerPrice) / HUNDRED_PERCENT;

uint256 totalOfferFeeLimit = (limits.maxTotalOfferFeePercentage * offerPrice) / 10000;
uint256 totalOfferFeeLimit = (limits.maxTotalOfferFeePercentage * offerPrice) / HUNDRED_PERCENT;

// Sum of agent fee amount and protocol fee amount should be <= offer fee limit and less that fee limit set by seller
uint256 totalFeeAmount = agentFeeAmount + protocolFee;
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/bases/ProtocolBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ abstract contract ProtocolBase is PausableBase, ReentrancyGuardBase, BosonErrors
return
_exchangeToken == protocolAddresses().token
? protocolFees().flatBoson
: (protocolFees().percentage * _price) / 10000;
: (protocolFees().percentage * _price) / HUNDRED_PERCENT;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/clients/voucher/BosonVoucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ contract BosonVoucherBase is IBosonVoucher, BeaconClientBase, OwnableUpgradeable
!isPreminted
);

royaltyAmount = (_salePrice * royaltyPercentage) / 10000;
royaltyAmount = (_salePrice * royaltyPercentage) / HUNDRED_PERCENT;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/facets/ConfigHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,6 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase {
* Reverts if the value more than 10000
*/
function checkMaxPercententage(uint256 _percentage) internal pure {
if (_percentage > 10000) revert InvalidFeePercentage();
if (_percentage > HUNDRED_PERCENT) revert InvalidFeePercentage();
}
}
4 changes: 2 additions & 2 deletions contracts/protocol/facets/DisputeHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ contract DisputeHandlerFacet is DisputeBase, IBosonDisputeHandler {
uint8 _sigV
) external override nonReentrant {
// buyer should get at most 100%
if (_buyerPercent > 10000) revert InvalidBuyerPercent();
if (_buyerPercent > HUNDRED_PERCENT) revert InvalidBuyerPercent();

// Get the exchange, should be in disputed state
(Exchange storage exchange, ) = getValidExchange(_exchangeId, ExchangeState.Disputed);
Expand Down Expand Up @@ -340,7 +340,7 @@ contract DisputeHandlerFacet is DisputeBase, IBosonDisputeHandler {
*/
function decideDispute(uint256 _exchangeId, uint256 _buyerPercent) external override nonReentrant {
// Buyer should get at most 100%
if (_buyerPercent > 10000) revert InvalidBuyerPercent();
if (_buyerPercent > HUNDRED_PERCENT) revert InvalidBuyerPercent();

// Make sure the dispute is valid and the caller is the dispute resolver
(Exchange storage exchange, Dispute storage dispute, DisputeDates storage disputeDates) = disputeResolverChecks(
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/facets/PriceDiscoveryHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ contract PriceDiscoveryHandlerFacet is IBosonPriceDiscoveryHandler, PriceDiscove
{
// Calculate royalties
(RoyaltyInfo storage royaltyInfo, uint256 royaltyInfoIndex, ) = fetchRoyalties(offerId, false);
uint256 royaltyAmount = (getTotalRoyaltyPercentage(royaltyInfo.bps) * actualPrice) / 10000;
uint256 royaltyAmount = (getTotalRoyaltyPercentage(royaltyInfo.bps) * actualPrice) / HUNDRED_PERCENT;

// Verify that fees and royalties are not higher than the price.
if (protocolFeeAmount + royaltyAmount > actualPrice) revert FeeAmountTooHigh();
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/facets/SequentialCommitHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ contract SequentialCommitHandlerFacet is IBosonSequentialCommitHandler, PriceDis
(royaltyInfo, exchangeCost.royaltyInfoIndex, ) = fetchRoyalties(offerId, false);
exchangeCost.royaltyAmount =
(getTotalRoyaltyPercentage(royaltyInfo.bps) * exchangeCost.price) /
10000;
HUNDRED_PERCENT;
}

// Verify that fees and royalties are not higher than the price.
Expand Down
20 changes: 10 additions & 10 deletions contracts/protocol/libs/FundsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ library FundsLib {
} else {
// RESOLVED or DECIDED
uint256 pot = price + sellerDeposit + buyerEscalationDeposit;
buyerPayoff = (pot * dispute.buyerPercent) / 10000;
buyerPayoff = (pot * dispute.buyerPercent) / HUNDRED_PERCENT;
sellerPayoff = pot - buyerPayoff;
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ library FundsLib {
{
if (_exchangeState == BosonTypes.ExchangeState.Completed) {
// COMPLETED, buyer pays full price
effectivePriceMultiplier = 10000;
effectivePriceMultiplier = HUNDRED_PERCENT;
} else if (
_exchangeState == BosonTypes.ExchangeState.Revoked ||
_exchangeState == BosonTypes.ExchangeState.Canceled
Expand All @@ -272,13 +272,13 @@ library FundsLib {

if (disputeState == BosonTypes.DisputeState.Retracted) {
// RETRACTED - same as "COMPLETED"
effectivePriceMultiplier = 10000;
effectivePriceMultiplier = HUNDRED_PERCENT;
} else if (disputeState == BosonTypes.DisputeState.Refused) {
// REFUSED, buyer pays nothing
effectivePriceMultiplier = 0;
} else {
// RESOLVED or DECIDED
effectivePriceMultiplier = 10000 - dispute.buyerPercent;
effectivePriceMultiplier = HUNDRED_PERCENT - dispute.buyerPercent;
}
}
}
Expand Down Expand Up @@ -318,9 +318,9 @@ library FundsLib {
(
reducedSecondaryPrice > resellerBuyPrice
? effectivePriceMultiplier * (reducedSecondaryPrice - resellerBuyPrice)
: (10000 - effectivePriceMultiplier) * (resellerBuyPrice - reducedSecondaryPrice)
: (HUNDRED_PERCENT - effectivePriceMultiplier) * (resellerBuyPrice - reducedSecondaryPrice)
) /
10000;
HUNDRED_PERCENT;

resellerBuyPrice = price;
}
Expand All @@ -341,7 +341,7 @@ library FundsLib {
}

// protocolFee and sellerRoyalties can be multiplied by effectivePriceMultiplier just at the end
protocolFee = (protocolFee * effectivePriceMultiplier) / 10000;
protocolFee = (protocolFee * effectivePriceMultiplier) / HUNDRED_PERCENT;
}

/**
Expand Down Expand Up @@ -561,10 +561,10 @@ library FundsLib {
BosonTypes.RoyaltyInfo storage _royaltyInfo = _offer.royaltyInfo[_royaltyInfoIndex];
uint256 len = _royaltyInfo.recipients.length;
uint256 totalAmount;
uint256 effectivePrice = (_price * _effectivePriceMultiplier) / 10000;
uint256 effectivePrice = (_price * _effectivePriceMultiplier) / HUNDRED_PERCENT;
for (uint256 i = 0; i < len; ) {
address payable recipient = _royaltyInfo.recipients[i];
uint256 amount = (_royaltyInfo.bps[i] * effectivePrice) / 10000;
uint256 amount = (_royaltyInfo.bps[i] * effectivePrice) / HUNDRED_PERCENT;
totalAmount += amount;
if (recipient == address(0)) {
// goes to seller's treasury
Expand All @@ -580,6 +580,6 @@ library FundsLib {
}

// if there is a remainder due to rounding, it goes to the seller's treasury
sellerRoyalties += (_effectivePriceMultiplier * _escrowedRoyaltyAmount) / 10000 - totalAmount;
sellerRoyalties += (_effectivePriceMultiplier * _escrowedRoyaltyAmount) / HUNDRED_PERCENT - totalAmount;
}
}

0 comments on commit bed7579

Please sign in to comment.