Skip to content

Commit 884c906

Browse files
authored
Default configs (#677)
* default configs * apply to all contracts * fix platform fee calculation * add default fee recipient addr * make the constant public * fix tests * fix tests * fix test
1 parent 389f945 commit 884c906

File tree

27 files changed

+397
-81
lines changed

27 files changed

+397
-81
lines changed

contracts/prebuilts/drop/DropERC1155.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ contract DropERC1155 is
7272
/// @dev Max bps in the thirdweb system.
7373
uint256 private constant MAX_BPS = 10_000;
7474

75+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
76+
uint16 private constant DEFAULT_FEE_BPS = 250;
77+
7578
/*///////////////////////////////////////////////////////////////
7679
Mappings
7780
//////////////////////////////////////////////////////////////*/
@@ -250,6 +253,7 @@ contract DropERC1155 is
250253
: _primarySaleRecipient;
251254

252255
uint256 totalPrice = _quantityToClaim * _pricePerToken;
256+
uint256 platformFeesTw = (totalPrice * DEFAULT_FEE_BPS) / MAX_BPS;
253257
uint256 platformFees = (totalPrice * platformFeeBps) / MAX_BPS;
254258

255259
bool validMsgValue;
@@ -260,8 +264,14 @@ contract DropERC1155 is
260264
}
261265
require(validMsgValue, "!V");
262266

267+
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), DEFAULT_FEE_RECIPIENT, platformFeesTw);
263268
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), platformFeeRecipient, platformFees);
264-
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), _saleRecipient, totalPrice - platformFees);
269+
CurrencyTransferLib.transferCurrency(
270+
_currency,
271+
_msgSender(),
272+
_saleRecipient,
273+
totalPrice - platformFees - platformFeesTw
274+
);
265275
}
266276

267277
/// @dev Transfers the NFTs being claimed.

contracts/prebuilts/drop/DropERC20.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ contract DropERC20 is
5656
/// @dev Max bps in the thirdweb system.
5757
uint256 private constant MAX_BPS = 10_000;
5858

59+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
60+
uint16 private constant DEFAULT_FEE_BPS = 250;
61+
5962
/// @dev Global max total supply of tokens.
6063
uint256 public maxTotalSupply;
6164

@@ -157,6 +160,7 @@ contract DropERC20 is
157160
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
158161
require(totalPrice > 0, "quantity too low");
159162

163+
uint256 platformFeesTw = (totalPrice * DEFAULT_FEE_BPS) / MAX_BPS;
160164
uint256 platformFees = (totalPrice * platformFeeBps) / MAX_BPS;
161165

162166
bool validMsgValue;
@@ -167,8 +171,14 @@ contract DropERC20 is
167171
}
168172
require(validMsgValue, "Invalid msg value");
169173

174+
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), DEFAULT_FEE_RECIPIENT, platformFeesTw);
170175
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), platformFeeRecipient, platformFees);
171-
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), saleRecipient, totalPrice - platformFees);
176+
CurrencyTransferLib.transferCurrency(
177+
_currency,
178+
_msgSender(),
179+
saleRecipient,
180+
totalPrice - platformFees - platformFeesTw
181+
);
172182
}
173183

174184
/// @dev Transfers the tokens being claimed.

contracts/prebuilts/drop/DropERC721.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ contract DropERC721 is
6868
/// @dev Max bps in the thirdweb system.
6969
uint256 private constant MAX_BPS = 10_000;
7070

71+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
72+
uint16 private constant DEFAULT_FEE_BPS = 250;
73+
7174
/// @dev Global max total supply of NFTs.
7275
uint256 public maxTotalSupply;
7376

@@ -261,6 +264,7 @@ contract DropERC721 is
261264
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
262265

263266
uint256 totalPrice = _quantityToClaim * _pricePerToken;
267+
uint256 platformFeesTw = (totalPrice * DEFAULT_FEE_BPS) / MAX_BPS;
264268
uint256 platformFees = (totalPrice * platformFeeBps) / MAX_BPS;
265269

266270
bool validMsgValue;
@@ -271,8 +275,14 @@ contract DropERC721 is
271275
}
272276
require(validMsgValue, "!V");
273277

278+
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), DEFAULT_FEE_RECIPIENT, platformFeesTw);
274279
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), platformFeeRecipient, platformFees);
275-
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), saleRecipient, totalPrice - platformFees);
280+
CurrencyTransferLib.transferCurrency(
281+
_currency,
282+
_msgSender(),
283+
saleRecipient,
284+
totalPrice - platformFees - platformFeesTw
285+
);
276286
}
277287

278288
/// @dev Transfers the NFTs being claimed.

contracts/prebuilts/loyalty/LoyaltyCard.sol

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ contract LoyaltyCard is
7373
/// @dev Max bps in the thirdweb system.
7474
uint256 private constant MAX_BPS = 10_000;
7575

76+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
77+
uint16 private constant DEFAULT_FEE_BPS = 250;
78+
7679
/*///////////////////////////////////////////////////////////////
7780
Constructor + initializer
7881
//////////////////////////////////////////////////////////////*/
@@ -226,6 +229,8 @@ contract LoyaltyCard is
226229
uint256 fees;
227230
address feeRecipient;
228231

232+
uint256 platformFeesTw = (totalPrice * DEFAULT_FEE_BPS) / MAX_BPS;
233+
229234
PlatformFeeType feeType = getPlatformFeeType();
230235
if (feeType == PlatformFeeType.Flat) {
231236
(feeRecipient, fees) = getFlatPlatformFeeInfo();
@@ -235,10 +240,16 @@ contract LoyaltyCard is
235240
fees = (totalPrice * platformFeeBps) / MAX_BPS;
236241
}
237242

238-
require(totalPrice >= fees, "Fees greater than price");
243+
require(totalPrice >= fees + platformFeesTw, "Fees greater than price");
239244

245+
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), DEFAULT_FEE_RECIPIENT, platformFeesTw);
240246
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), feeRecipient, fees);
241-
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), saleRecipient, totalPrice - fees);
247+
CurrencyTransferLib.transferCurrency(
248+
_currency,
249+
_msgSender(),
250+
saleRecipient,
251+
totalPrice - fees - platformFeesTw
252+
);
242253
}
243254

244255
/// @dev Mints an NFT to `to`

contracts/prebuilts/marketplace/direct-listings/DirectListingsLogic.sol

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ contract DirectListingsLogic is IDirectListings, ReentrancyGuard, ERC2771Context
3636
/// @dev The max bps of the contract. So, 10_000 == 100 %
3737
uint64 private constant MAX_BPS = 10_000;
3838

39+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
40+
uint16 private constant DEFAULT_FEE_BPS = 250;
41+
3942
/// @dev The address of the native token wrapper contract.
4043
address private immutable nativeTokenWrapper;
4144

@@ -500,10 +503,18 @@ contract DirectListingsLogic is IDirectListings, ReentrancyGuard, ERC2771Context
500503

501504
// Payout platform fee
502505
{
506+
uint256 platformFeesTw = (_totalPayoutAmount * DEFAULT_FEE_BPS) / MAX_BPS;
503507
(address platformFeeRecipient, uint16 platformFeeBps) = IPlatformFee(address(this)).getPlatformFeeInfo();
504508
uint256 platformFeeCut = (_totalPayoutAmount * platformFeeBps) / MAX_BPS;
505509

506510
// Transfer platform fee
511+
CurrencyTransferLib.transferCurrencyWithWrapper(
512+
_currencyToUse,
513+
_payer,
514+
DEFAULT_FEE_RECIPIENT,
515+
platformFeesTw,
516+
_nativeTokenWrapper
517+
);
507518
CurrencyTransferLib.transferCurrencyWithWrapper(
508519
_currencyToUse,
509520
_payer,
@@ -512,7 +523,7 @@ contract DirectListingsLogic is IDirectListings, ReentrancyGuard, ERC2771Context
512523
_nativeTokenWrapper
513524
);
514525

515-
amountRemaining = _totalPayoutAmount - platformFeeCut;
526+
amountRemaining = _totalPayoutAmount - platformFeeCut - platformFeesTw;
516527
}
517528

518529
// Payout royalties

contracts/prebuilts/marketplace/english-auctions/EnglishAuctionsLogic.sol

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ contract EnglishAuctionsLogic is IEnglishAuctions, ReentrancyGuard, ERC2771Conte
3838
/// @dev The max bps of the contract. So, 10_000 == 100 %
3939
uint64 private constant MAX_BPS = 10_000;
4040

41+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
42+
uint16 private constant DEFAULT_FEE_BPS = 250;
43+
4144
/// @dev The address of the native token wrapper contract.
4245
address private immutable nativeTokenWrapper;
4346

@@ -467,10 +470,18 @@ contract EnglishAuctionsLogic is IEnglishAuctions, ReentrancyGuard, ERC2771Conte
467470

468471
// Payout platform fee
469472
{
473+
uint256 platformFeesTw = (_totalPayoutAmount * DEFAULT_FEE_BPS) / MAX_BPS;
470474
(address platformFeeRecipient, uint16 platformFeeBps) = IPlatformFee(address(this)).getPlatformFeeInfo();
471475
uint256 platformFeeCut = (_totalPayoutAmount * platformFeeBps) / MAX_BPS;
472476

473477
// Transfer platform fee
478+
CurrencyTransferLib.transferCurrencyWithWrapper(
479+
_currencyToUse,
480+
_payer,
481+
DEFAULT_FEE_RECIPIENT,
482+
platformFeesTw,
483+
_nativeTokenWrapper
484+
);
474485
CurrencyTransferLib.transferCurrencyWithWrapper(
475486
_currencyToUse,
476487
_payer,
@@ -479,7 +490,7 @@ contract EnglishAuctionsLogic is IEnglishAuctions, ReentrancyGuard, ERC2771Conte
479490
_nativeTokenWrapper
480491
);
481492

482-
amountRemaining = _totalPayoutAmount - platformFeeCut;
493+
amountRemaining = _totalPayoutAmount - platformFeeCut - platformFeesTw;
483494
}
484495

485496
// Payout royalties

contracts/prebuilts/marketplace/offers/OffersLogic.sol

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ contract OffersLogic is IOffers, ReentrancyGuard, ERC2771ContextConsumer {
3535
/// @dev The max bps of the contract. So, 10_000 == 100 %
3636
uint64 private constant MAX_BPS = 10_000;
3737

38+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
39+
uint16 private constant DEFAULT_FEE_BPS = 250;
40+
3841
/*///////////////////////////////////////////////////////////////
3942
Modifiers
4043
//////////////////////////////////////////////////////////////*/
@@ -285,10 +288,18 @@ contract OffersLogic is IOffers, ReentrancyGuard, ERC2771ContextConsumer {
285288

286289
// Payout platform fee
287290
{
291+
uint256 platformFeesTw = (_totalPayoutAmount * DEFAULT_FEE_BPS) / MAX_BPS;
288292
(address platformFeeRecipient, uint16 platformFeeBps) = IPlatformFee(address(this)).getPlatformFeeInfo();
289293
uint256 platformFeeCut = (_totalPayoutAmount * platformFeeBps) / MAX_BPS;
290294

291295
// Transfer platform fee
296+
CurrencyTransferLib.transferCurrencyWithWrapper(
297+
_currencyToUse,
298+
_payer,
299+
DEFAULT_FEE_RECIPIENT,
300+
platformFeesTw,
301+
address(0)
302+
);
292303
CurrencyTransferLib.transferCurrencyWithWrapper(
293304
_currencyToUse,
294305
_payer,
@@ -297,7 +308,7 @@ contract OffersLogic is IOffers, ReentrancyGuard, ERC2771ContextConsumer {
297308
address(0)
298309
);
299310

300-
amountRemaining = _totalPayoutAmount - platformFeeCut;
311+
amountRemaining = _totalPayoutAmount - platformFeeCut - platformFeesTw;
301312
}
302313

303314
// Payout royalties

contracts/prebuilts/open-edition/OpenEditionERC721FlatFee.sol

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ contract OpenEditionERC721FlatFee is
6464
/// @dev Max bps in the thirdweb system.
6565
uint256 private constant MAX_BPS = 10_000;
6666

67+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
68+
uint16 private constant DEFAULT_FEE_BPS = 250;
69+
6770
/*///////////////////////////////////////////////////////////////
6871
Constructor + initializer logic
6972
//////////////////////////////////////////////////////////////*/
@@ -157,14 +160,16 @@ contract OpenEditionERC721FlatFee is
157160
uint256 platformFees;
158161
address platformFeeRecipient;
159162

163+
uint256 platformFeesTw = (totalPrice * DEFAULT_FEE_BPS) / MAX_BPS;
164+
160165
if (getPlatformFeeType() == IPlatformFee.PlatformFeeType.Flat) {
161166
(platformFeeRecipient, platformFees) = getFlatPlatformFeeInfo();
162167
} else {
163168
(address recipient, uint16 platformFeeBps) = getPlatformFeeInfo();
164169
platformFeeRecipient = recipient;
165170
platformFees = ((totalPrice * platformFeeBps) / MAX_BPS);
166171
}
167-
require(totalPrice >= platformFees, "price less than platform fee");
172+
require(totalPrice >= platformFees + platformFeesTw, "price less than platform fee");
168173

169174
bool validMsgValue;
170175
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
@@ -176,8 +181,14 @@ contract OpenEditionERC721FlatFee is
176181

177182
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
178183

184+
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), DEFAULT_FEE_RECIPIENT, platformFeesTw);
179185
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), platformFeeRecipient, platformFees);
180-
CurrencyTransferLib.transferCurrency(_currency, _msgSender(), saleRecipient, totalPrice - platformFees);
186+
CurrencyTransferLib.transferCurrency(
187+
_currency,
188+
_msgSender(),
189+
saleRecipient,
190+
totalPrice - platformFees - platformFeesTw
191+
);
181192
}
182193

183194
/// @dev Transfers the NFTs being claimed.

contracts/prebuilts/token/TokenERC1155.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ contract TokenERC1155 is
6666
bytes32 private constant MODULE_TYPE = bytes32("TokenERC1155");
6767
uint256 private constant VERSION = 1;
6868

69+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
70+
uint16 private constant DEFAULT_FEE_BPS = 250;
71+
6972
// Token name
7073
string public name;
7174

@@ -447,10 +450,11 @@ contract TokenERC1155 is
447450
}
448451

449452
uint256 totalPrice = _req.pricePerToken * _req.quantity;
453+
uint256 platformFeesTw = (totalPrice * DEFAULT_FEE_BPS) / MAX_BPS;
450454
uint256 platformFees = platformFeeType == PlatformFeeType.Flat
451455
? flatPlatformFee
452456
: ((totalPrice * platformFeeBps) / MAX_BPS);
453-
require(totalPrice >= platformFees, "price less than platform fee");
457+
require(totalPrice >= platformFees + platformFeesTw, "price less than platform fee");
454458

455459
if (_req.currency == CurrencyTransferLib.NATIVE_TOKEN) {
456460
require(msg.value == totalPrice, "must send total price.");
@@ -462,8 +466,14 @@ contract TokenERC1155 is
462466
? primarySaleRecipient
463467
: _req.primarySaleRecipient;
464468

469+
CurrencyTransferLib.transferCurrency(_req.currency, _msgSender(), DEFAULT_FEE_RECIPIENT, platformFeesTw);
465470
CurrencyTransferLib.transferCurrency(_req.currency, _msgSender(), platformFeeRecipient, platformFees);
466-
CurrencyTransferLib.transferCurrency(_req.currency, _msgSender(), saleRecipient, totalPrice - platformFees);
471+
CurrencyTransferLib.transferCurrency(
472+
_req.currency,
473+
_msgSender(),
474+
saleRecipient,
475+
totalPrice - platformFees - platformFeesTw
476+
);
467477
}
468478

469479
/// ===== Low-level overrides =====

contracts/prebuilts/token/TokenERC20.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ contract TokenERC20 is
5757
bytes32 private constant MODULE_TYPE = bytes32("TokenERC20");
5858
uint256 private constant VERSION = 1;
5959

60+
address public constant DEFAULT_FEE_RECIPIENT = 0x1Af20C6B23373350aD464700B5965CE4B0D2aD94;
61+
uint16 private constant DEFAULT_FEE_BPS = 250;
62+
6063
bytes32 private constant TYPEHASH =
6164
keccak256(
6265
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 price,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
@@ -215,6 +218,7 @@ contract TokenERC20 is
215218
return;
216219
}
217220

221+
uint256 platformFeesTw = (_req.price * DEFAULT_FEE_BPS) / MAX_BPS;
218222
uint256 platformFees = (_req.price * platformFeeBps) / MAX_BPS;
219223

220224
if (_req.currency == CurrencyTransferLib.NATIVE_TOKEN) {
@@ -227,8 +231,14 @@ contract TokenERC20 is
227231
? primarySaleRecipient
228232
: _req.primarySaleRecipient;
229233

234+
CurrencyTransferLib.transferCurrency(_req.currency, _msgSender(), DEFAULT_FEE_RECIPIENT, platformFeesTw);
230235
CurrencyTransferLib.transferCurrency(_req.currency, _msgSender(), platformFeeRecipient, platformFees);
231-
CurrencyTransferLib.transferCurrency(_req.currency, _msgSender(), saleRecipient, _req.price - platformFees);
236+
CurrencyTransferLib.transferCurrency(
237+
_req.currency,
238+
_msgSender(),
239+
saleRecipient,
240+
_req.price - platformFees - platformFeesTw
241+
);
232242
}
233243

234244
/// @dev Mints `amount` of tokens to `to`

0 commit comments

Comments
 (0)