Skip to content

Commit a64ca6b

Browse files
PlatformFee: Sync extensions in /upgradeable and non-upgradeable (#530)
* sync extensions * prettier * SignatureDrop uses legacy PlatformFee and PrimarySale --------- Co-authored-by: nkrishang <62195808+nkrishang@users.noreply.github.com> Co-authored-by: Krishang <krishang@thirdweb.com>
1 parent 9ce0b55 commit a64ca6b

File tree

10 files changed

+270
-7
lines changed

10 files changed

+270
-7
lines changed

contracts/extension/BurnToClaim.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ abstract contract BurnToClaim is IBurnToClaim {
1717

1818
function setBurnToClaimInfo(BurnToClaimInfo calldata _burnToClaimInfo) external virtual {
1919
require(_canSetBurnToClaim(), "Not authorized.");
20+
require(_burnToClaimInfo.originContractAddress != address(0), "Origin contract not set.");
21+
require(_burnToClaimInfo.currency != address(0), "Currency not set.");
2022

2123
burnToClaimInfo = _burnToClaimInfo;
2224
}
@@ -30,12 +32,15 @@ abstract contract BurnToClaim is IBurnToClaim {
3032

3133
if (_burnToClaimInfo.tokenType == IBurnToClaim.TokenType.ERC721) {
3234
require(_quantity == 1, "Invalid amount");
33-
require(IERC721(_burnToClaimInfo.originContractAddress).ownerOf(_tokenId) == _tokenOwner);
35+
require(IERC721(_burnToClaimInfo.originContractAddress).ownerOf(_tokenId) == _tokenOwner, "!Owner");
3436
} else if (_burnToClaimInfo.tokenType == IBurnToClaim.TokenType.ERC1155) {
3537
uint256 _eligible1155TokenId = _burnToClaimInfo.tokenId;
3638

37-
require(_tokenId == _eligible1155TokenId || _eligible1155TokenId == type(uint256).max);
38-
require(IERC1155(_burnToClaimInfo.originContractAddress).balanceOf(_tokenOwner, _tokenId) >= _quantity);
39+
require(_tokenId == _eligible1155TokenId, "Invalid token Id");
40+
require(
41+
IERC1155(_burnToClaimInfo.originContractAddress).balanceOf(_tokenOwner, _tokenId) >= _quantity,
42+
"!Balance"
43+
);
3944
}
4045

4146
// TODO: check if additional verification steps are required / override in main contract

contracts/extension/PlatformFee.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract contract PlatformFee is IPlatformFee {
3535
return (platformFeeRecipient, flatPlatformFee);
3636
}
3737

38-
/// @dev Returns the platform fee bps and recipient.
38+
/// @dev Returns the platform fee type.
3939
function getPlatformFeeType() public view returns (PlatformFeeType) {
4040
return platformFeeType;
4141
}
@@ -61,6 +61,9 @@ abstract contract PlatformFee is IPlatformFee {
6161
if (_platformFeeBps > 10_000) {
6262
revert("Exceeds max bps");
6363
}
64+
if (_platformFeeRecipient == address(0)) {
65+
revert("Invalid recipient");
66+
}
6467

6568
platformFeeBps = uint16(_platformFeeBps);
6669
platformFeeRecipient = _platformFeeRecipient;

contracts/extension/PrimarySale.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ abstract contract PrimarySale is IPrimarySale {
3838

3939
/// @dev Lets a contract admin set the recipient for all primary sales.
4040
function _setupPrimarySaleRecipient(address _saleRecipient) internal {
41+
if (_saleRecipient == address(0)) {
42+
revert("Invalid recipient");
43+
}
4144
recipient = _saleRecipient;
4245
emit PrimarySaleRecipientUpdated(_saleRecipient);
4346
}

contracts/extension/upgradeable/PlatformFee.sol

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ library PlatformFeeStorage {
1919
address platformFeeRecipient;
2020
/// @dev The % of primary sales collected as platform fees.
2121
uint16 platformFeeBps;
22+
/// @dev Fee type variants: percentage fee and flat fee
23+
IPlatformFee.PlatformFeeType platformFeeType;
24+
/// @dev The flat amount collected by the contract as fees on primary sales.
25+
uint256 flatPlatformFee;
2226
}
2327

2428
function data() internal pure returns (Data storage data_) {
@@ -44,6 +48,16 @@ abstract contract PlatformFee is IPlatformFee {
4448
return (_platformFeeStorage().platformFeeRecipient, uint16(_platformFeeStorage().platformFeeBps));
4549
}
4650

51+
/// @dev Returns the platform fee bps and recipient.
52+
function getFlatPlatformFeeInfo() public view returns (address, uint256) {
53+
return (_platformFeeStorage().platformFeeRecipient, _platformFeeStorage().flatPlatformFee);
54+
}
55+
56+
/// @dev Returns the platform fee type.
57+
function getPlatformFeeType() public view returns (PlatformFeeType) {
58+
return _platformFeeStorage().platformFeeType;
59+
}
60+
4761
/**
4862
* @notice Updates the platform fee recipient and bps.
4963
* @dev Caller should be authorized to set platform fee info.
@@ -75,6 +89,38 @@ abstract contract PlatformFee is IPlatformFee {
7589
emit PlatformFeeInfoUpdated(_platformFeeRecipient, _platformFeeBps);
7690
}
7791

92+
/// @notice Lets a module admin set a flat fee on primary sales.
93+
function setFlatPlatformFeeInfo(address _platformFeeRecipient, uint256 _flatFee) external {
94+
if (!_canSetPlatformFeeInfo()) {
95+
revert("Not authorized");
96+
}
97+
98+
_setupFlatPlatformFeeInfo(_platformFeeRecipient, _flatFee);
99+
}
100+
101+
/// @dev Sets a flat fee on primary sales.
102+
function _setupFlatPlatformFeeInfo(address _platformFeeRecipient, uint256 _flatFee) internal {
103+
_platformFeeStorage().flatPlatformFee = _flatFee;
104+
_platformFeeStorage().platformFeeRecipient = _platformFeeRecipient;
105+
106+
emit FlatPlatformFeeUpdated(_platformFeeRecipient, _flatFee);
107+
}
108+
109+
/// @notice Lets a module admin set platform fee type.
110+
function setPlatformFeeType(PlatformFeeType _feeType) external {
111+
if (!_canSetPlatformFeeInfo()) {
112+
revert("Not authorized");
113+
}
114+
_setupPlatformFeeType(_feeType);
115+
}
116+
117+
/// @dev Sets platform fee type.
118+
function _setupPlatformFeeType(PlatformFeeType _feeType) internal {
119+
_platformFeeStorage().platformFeeType = _feeType;
120+
121+
emit PlatformFeeTypeUpdated(_feeType);
122+
}
123+
78124
/// @dev Returns the PlatformFee storage.
79125
function _platformFeeStorage() internal pure returns (PlatformFeeStorage.Data storage data) {
80126
data = PlatformFeeStorage.data();
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
/// @author thirdweb
5+
6+
import "./interface/IPlatformFee_V1.sol";
7+
8+
/**
9+
* @title Platform Fee
10+
* @notice Thirdweb's `PlatformFee` is a contract extension to be used with any base contract. It exposes functions for setting and reading
11+
* the recipient of platform fee and the platform fee basis points, and lets the inheriting contract perform conditional logic
12+
* that uses information about platform fees, if desired.
13+
*/
14+
15+
abstract contract PlatformFee is IPlatformFee {
16+
/// @dev The address that receives all platform fees from all sales.
17+
address private platformFeeRecipient;
18+
19+
/// @dev The % of primary sales collected as platform fees.
20+
uint16 private platformFeeBps;
21+
22+
/// @dev Fee type variants: percentage fee and flat fee
23+
PlatformFeeType private platformFeeType;
24+
25+
/// @dev The flat amount collected by the contract as fees on primary sales.
26+
uint256 private flatPlatformFee;
27+
28+
/// @dev Returns the platform fee recipient and bps.
29+
function getPlatformFeeInfo() public view override returns (address, uint16) {
30+
return (platformFeeRecipient, uint16(platformFeeBps));
31+
}
32+
33+
/// @dev Returns the platform fee bps and recipient.
34+
function getFlatPlatformFeeInfo() public view returns (address, uint256) {
35+
return (platformFeeRecipient, flatPlatformFee);
36+
}
37+
38+
/// @dev Returns the platform fee bps and recipient.
39+
function getPlatformFeeType() public view returns (PlatformFeeType) {
40+
return platformFeeType;
41+
}
42+
43+
/**
44+
* @notice Updates the platform fee recipient and bps.
45+
* @dev Caller should be authorized to set platform fee info.
46+
* See {_canSetPlatformFeeInfo}.
47+
* Emits {PlatformFeeInfoUpdated Event}; See {_setupPlatformFeeInfo}.
48+
*
49+
* @param _platformFeeRecipient Address to be set as new platformFeeRecipient.
50+
* @param _platformFeeBps Updated platformFeeBps.
51+
*/
52+
function setPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) external override {
53+
if (!_canSetPlatformFeeInfo()) {
54+
revert("Not authorized");
55+
}
56+
_setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps);
57+
}
58+
59+
/// @dev Sets the platform fee recipient and bps
60+
function _setupPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) internal {
61+
if (_platformFeeBps > 10_000) {
62+
revert("Exceeds max bps");
63+
}
64+
65+
platformFeeBps = uint16(_platformFeeBps);
66+
platformFeeRecipient = _platformFeeRecipient;
67+
68+
emit PlatformFeeInfoUpdated(_platformFeeRecipient, _platformFeeBps);
69+
}
70+
71+
/// @notice Lets a module admin set a flat fee on primary sales.
72+
function setFlatPlatformFeeInfo(address _platformFeeRecipient, uint256 _flatFee) external {
73+
if (!_canSetPlatformFeeInfo()) {
74+
revert("Not authorized");
75+
}
76+
77+
_setupFlatPlatformFeeInfo(_platformFeeRecipient, _flatFee);
78+
}
79+
80+
/// @dev Sets a flat fee on primary sales.
81+
function _setupFlatPlatformFeeInfo(address _platformFeeRecipient, uint256 _flatFee) internal {
82+
flatPlatformFee = _flatFee;
83+
platformFeeRecipient = _platformFeeRecipient;
84+
85+
emit FlatPlatformFeeUpdated(_platformFeeRecipient, _flatFee);
86+
}
87+
88+
/// @notice Lets a module admin set platform fee type.
89+
function setPlatformFeeType(PlatformFeeType _feeType) external {
90+
if (!_canSetPlatformFeeInfo()) {
91+
revert("Not authorized");
92+
}
93+
_setupPlatformFeeType(_feeType);
94+
}
95+
96+
/// @dev Sets platform fee type.
97+
function _setupPlatformFeeType(PlatformFeeType _feeType) internal {
98+
platformFeeType = _feeType;
99+
100+
emit PlatformFeeTypeUpdated(_feeType);
101+
}
102+
103+
/// @dev Returns whether platform fee info can be set in the given execution context.
104+
function _canSetPlatformFeeInfo() internal view virtual returns (bool);
105+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
/// @author thirdweb
5+
6+
import "./interface/IPrimarySale_V1.sol";
7+
8+
/**
9+
* @title Primary Sale
10+
* @notice Thirdweb's `PrimarySale` is a contract extension to be used with any base contract. It exposes functions for setting and reading
11+
* the recipient of primary sales, and lets the inheriting contract perform conditional logic that uses information about
12+
* primary sales, if desired.
13+
*/
14+
15+
abstract contract PrimarySale is IPrimarySale {
16+
/// @dev The address that receives all primary sales value.
17+
address private recipient;
18+
19+
/// @dev Returns primary sale recipient address.
20+
function primarySaleRecipient() public view override returns (address) {
21+
return recipient;
22+
}
23+
24+
/**
25+
* @notice Updates primary sale recipient.
26+
* @dev Caller should be authorized to set primary sales info.
27+
* See {_canSetPrimarySaleRecipient}.
28+
* Emits {PrimarySaleRecipientUpdated Event}; See {_setupPrimarySaleRecipient}.
29+
*
30+
* @param _saleRecipient Address to be set as new recipient of primary sales.
31+
*/
32+
function setPrimarySaleRecipient(address _saleRecipient) external override {
33+
if (!_canSetPrimarySaleRecipient()) {
34+
revert("Not authorized");
35+
}
36+
_setupPrimarySaleRecipient(_saleRecipient);
37+
}
38+
39+
/// @dev Lets a contract admin set the recipient for all primary sales.
40+
function _setupPrimarySaleRecipient(address _saleRecipient) internal {
41+
recipient = _saleRecipient;
42+
emit PrimarySaleRecipientUpdated(_saleRecipient);
43+
}
44+
45+
/// @dev Returns whether primary sale recipient can be set in the given execution context.
46+
function _canSetPrimarySaleRecipient() internal view virtual returns (bool);
47+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
/// @author thirdweb
5+
6+
/**
7+
* Thirdweb's `PlatformFee` is a contract extension to be used with any base contract. It exposes functions for setting and reading
8+
* the recipient of platform fee and the platform fee basis points, and lets the inheriting contract perform conditional logic
9+
* that uses information about platform fees, if desired.
10+
*/
11+
12+
interface IPlatformFee {
13+
/// @dev Fee type variants: percentage fee and flat fee
14+
enum PlatformFeeType {
15+
Bps,
16+
Flat
17+
}
18+
19+
/// @dev Returns the platform fee bps and recipient.
20+
function getPlatformFeeInfo() external view returns (address, uint16);
21+
22+
/// @dev Lets a module admin update the fees on primary sales.
23+
function setPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) external;
24+
25+
/// @dev Emitted when fee on primary sales is updated.
26+
event PlatformFeeInfoUpdated(address indexed platformFeeRecipient, uint256 platformFeeBps);
27+
28+
/// @dev Emitted when the flat platform fee is updated.
29+
event FlatPlatformFeeUpdated(address platformFeeRecipient, uint256 flatFee);
30+
31+
/// @dev Emitted when the platform fee type is updated.
32+
event PlatformFeeTypeUpdated(PlatformFeeType feeType);
33+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
/// @author thirdweb
5+
6+
/**
7+
* Thirdweb's `Primary` is a contract extension to be used with any base contract. It exposes functions for setting and reading
8+
* the recipient of primary sales, and lets the inheriting contract perform conditional logic that uses information about
9+
* primary sales, if desired.
10+
*/
11+
12+
interface IPrimarySale {
13+
/// @dev The adress that receives all primary sales value.
14+
function primarySaleRecipient() external view returns (address);
15+
16+
/// @dev Lets a module admin set the default recipient of all primary sales.
17+
function setPrimarySaleRecipient(address _saleRecipient) external;
18+
19+
/// @dev Emitted when a new sale recipient is set.
20+
event PrimarySaleRecipientUpdated(address indexed recipient);
21+
}

contracts/prebuilts/signature-drop/SignatureDrop.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import "../../lib/CurrencyTransferLib.sol";
2828
// ========== Features ==========
2929

3030
import "../../extension/ContractMetadata.sol";
31-
import "../../extension/PlatformFee.sol";
31+
import "../../legacy-contracts/extension/PlatformFee_V1.sol";
3232
import "../../extension/Royalty.sol";
33-
import "../../extension/PrimarySale.sol";
33+
import "../../legacy-contracts/extension/PrimarySale_V1.sol";
3434
import "../../extension/Ownable.sol";
3535
import "../../extension/DelayedReveal.sol";
3636
import "../../extension/LazyMint.sol";

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
solc-version = "0.8.12"
33
#auto_detect_solc = false
44
cache = true
5-
evm_version = 'london'
5+
evm_version = 'shanghai'
66
force = false
77
gas_reports = [
88
"DropERC721Benchmark",

0 commit comments

Comments
 (0)