Skip to content

Commit

Permalink
Code423n4 #10, 1000 as a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Splidge committed Jun 15, 2021
1 parent c0a3776 commit 4b4cf6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
5 changes: 3 additions & 2 deletions contracts/RCFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ contract RCFactory is Ownable, NativeMetaTransaction, IRCFactory {
uint256 public nftMintingLimit;

///// OTHER /////
uint256 public constant PER_MILLE = 1000; // in MegaBip so (1000 = 100%)
/// @dev counts the total NFTs minted across all events
/// @dev ... so the appropriate token id is used when upgrading to mainnet
uint256 public totalNftMintCount;
Expand Down Expand Up @@ -225,7 +226,7 @@ contract RCFactory is Ownable, NativeMetaTransaction, IRCFactory {
└────────────────────────────────────┘*/

/// @notice update stakeholder payouts
/// @dev in basis points (so 1000 = 100%)
/// @dev in MegaBip (so 1000 = 100%)
/// @param _artistCut The artist that designed the card
/// @param _winnerCut Extra cut for the longest owner
/// @param _creatorCut The creator of the market
Expand All @@ -244,7 +245,7 @@ contract RCFactory is Ownable, NativeMetaTransaction, IRCFactory {
_creatorCut +
_affiliateCut +
_cardAffiliateCut <=
1000,
PER_MILLE,
"Cuts too big"
);
potDistribution[0] = _artistCut;
Expand Down
25 changes: 15 additions & 10 deletions contracts/RCMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {

// CONTRACT SETUP
/// @dev = how many outcomes/teams/NFTs etc
uint256 public constant PER_MILLE = 1000; // in MegaBip so (1000 = 100%)
uint256 public numberOfCards;
uint256 public constant MAX_UINT256 = type(uint256).max;
uint256 public constant MIN_RENTAL_VALUE = 1 ether;
Expand Down Expand Up @@ -260,7 +261,8 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {
// if winner takes all mode, set winnerCut to max
if (_mode == uint8(Mode.WINNER_TAKES_ALL)) {
winnerCut =
(((uint256(1000) - artistCut) - creatorCut) - affiliateCut) -
(((uint256(PER_MILLE) - artistCut) - creatorCut) -
affiliateCut) -
cardAffiliateCut;
}

Expand Down Expand Up @@ -501,25 +503,27 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {
function _payoutWinnings() internal {
uint256 _winningsToTransfer = 0;
uint256 _remainingCut =
((((uint256(1000) - artistCut) - affiliateCut) - cardAffiliateCut) -
winnerCut) - creatorCut;
((((uint256(PER_MILLE) - artistCut) - affiliateCut) -
cardAffiliateCut) - winnerCut) - creatorCut;
// calculate longest owner's extra winnings, if relevant
if (longestOwner[winningOutcome] == msgSender() && winnerCut > 0) {
_winningsToTransfer = (totalRentCollected * winnerCut) / (1000);
_winningsToTransfer =
(totalRentCollected * winnerCut) /
(PER_MILLE);
}
uint256 _remainingPot = 0;
if (mode == Mode.SAFE_MODE) {
// return all rent paid on winning card
_remainingPot =
((totalRentCollected - rentCollectedPerCard[winningOutcome]) *
_remainingCut) /
(1000);
(PER_MILLE);
_winningsToTransfer += rentCollectedPerUserPerCard[msgSender()][
winningOutcome
];
} else {
// calculate normal winnings, if any
_remainingPot = (totalRentCollected * _remainingCut) / (1000);
_remainingPot = (totalRentCollected * _remainingCut) / (PER_MILLE);
}
uint256 _winnersTimeHeld = timeHeld[winningOutcome][msgSender()];
uint256 _numerator = _remainingPot * _winnersTimeHeld;
Expand All @@ -535,11 +539,12 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {
function _returnRent() internal {
// deduct artist share and card specific share if relevant but NOT market creator share or winner's share (no winner, market creator does not deserve)
uint256 _remainingCut =
((uint256(1000) - artistCut) - affiliateCut) - cardAffiliateCut;
((uint256(PER_MILLE) - artistCut) - affiliateCut) -
cardAffiliateCut;
uint256 _rentCollected = rentCollectedPerUser[msgSender()];
require(_rentCollected > 0, "Paid no rent");
uint256 _rentCollectedAdjusted =
(_rentCollected * _remainingCut) / (1000);
(_rentCollected * _remainingCut) / (PER_MILLE);
_payout(msgSender(), _rentCollectedAdjusted);
emit LogRentReturned(msgSender(), _rentCollectedAdjusted);
}
Expand Down Expand Up @@ -586,7 +591,7 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {
require(!cardAffiliatePaid[_card], "Card affiliate already paid");
cardAffiliatePaid[_card] = true;
uint256 _cardAffiliatePayment =
(rentCollectedPerCard[_card] * cardAffiliateCut) / (1000);
(rentCollectedPerCard[_card] * cardAffiliateCut) / (PER_MILLE);
if (_cardAffiliatePayment > 0) {
_payout(cardAffiliateAddresses[_card], _cardAffiliatePayment);
emit LogStakeholderPaid(
Expand All @@ -600,7 +605,7 @@ contract RCMarket is Initializable, NativeMetaTransaction, IRCMarket {
internal
{
if (_cut > 0) {
uint256 _payment = (totalRentCollected * _cut) / (1000);
uint256 _payment = (totalRentCollected * _cut) / (PER_MILLE);
_payout(_recipient, _payment);
emit LogStakeholderPaid(_recipient, _payment);
}
Expand Down

0 comments on commit 4b4cf6d

Please sign in to comment.