-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into BTT-drop-1155
- Loading branch information
Showing
24 changed files
with
1,195 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
contracts/legacy-contracts/extension/PlatformFee_V1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
/// @author thirdweb | ||
|
||
import "./interface/IPlatformFee_V1.sol"; | ||
|
||
/** | ||
* @title Platform Fee | ||
* @notice Thirdweb's `PlatformFee` is a contract extension to be used with any base contract. It exposes functions for setting and reading | ||
* the recipient of platform fee and the platform fee basis points, and lets the inheriting contract perform conditional logic | ||
* that uses information about platform fees, if desired. | ||
*/ | ||
|
||
abstract contract PlatformFee is IPlatformFee { | ||
/// @dev The address that receives all platform fees from all sales. | ||
address private platformFeeRecipient; | ||
|
||
/// @dev The % of primary sales collected as platform fees. | ||
uint16 private platformFeeBps; | ||
|
||
/// @dev Fee type variants: percentage fee and flat fee | ||
PlatformFeeType private platformFeeType; | ||
|
||
/// @dev The flat amount collected by the contract as fees on primary sales. | ||
uint256 private flatPlatformFee; | ||
|
||
/// @dev Returns the platform fee recipient and bps. | ||
function getPlatformFeeInfo() public view override returns (address, uint16) { | ||
return (platformFeeRecipient, uint16(platformFeeBps)); | ||
} | ||
|
||
/// @dev Returns the platform fee bps and recipient. | ||
function getFlatPlatformFeeInfo() public view returns (address, uint256) { | ||
return (platformFeeRecipient, flatPlatformFee); | ||
} | ||
|
||
/// @dev Returns the platform fee bps and recipient. | ||
function getPlatformFeeType() public view returns (PlatformFeeType) { | ||
return platformFeeType; | ||
} | ||
|
||
/** | ||
* @notice Updates the platform fee recipient and bps. | ||
* @dev Caller should be authorized to set platform fee info. | ||
* See {_canSetPlatformFeeInfo}. | ||
* Emits {PlatformFeeInfoUpdated Event}; See {_setupPlatformFeeInfo}. | ||
* | ||
* @param _platformFeeRecipient Address to be set as new platformFeeRecipient. | ||
* @param _platformFeeBps Updated platformFeeBps. | ||
*/ | ||
function setPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) external override { | ||
if (!_canSetPlatformFeeInfo()) { | ||
revert("Not authorized"); | ||
} | ||
_setupPlatformFeeInfo(_platformFeeRecipient, _platformFeeBps); | ||
} | ||
|
||
/// @dev Sets the platform fee recipient and bps | ||
function _setupPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) internal { | ||
if (_platformFeeBps > 10_000) { | ||
revert("Exceeds max bps"); | ||
} | ||
|
||
platformFeeBps = uint16(_platformFeeBps); | ||
platformFeeRecipient = _platformFeeRecipient; | ||
|
||
emit PlatformFeeInfoUpdated(_platformFeeRecipient, _platformFeeBps); | ||
} | ||
|
||
/// @notice Lets a module admin set a flat fee on primary sales. | ||
function setFlatPlatformFeeInfo(address _platformFeeRecipient, uint256 _flatFee) external { | ||
if (!_canSetPlatformFeeInfo()) { | ||
revert("Not authorized"); | ||
} | ||
|
||
_setupFlatPlatformFeeInfo(_platformFeeRecipient, _flatFee); | ||
} | ||
|
||
/// @dev Sets a flat fee on primary sales. | ||
function _setupFlatPlatformFeeInfo(address _platformFeeRecipient, uint256 _flatFee) internal { | ||
flatPlatformFee = _flatFee; | ||
platformFeeRecipient = _platformFeeRecipient; | ||
|
||
emit FlatPlatformFeeUpdated(_platformFeeRecipient, _flatFee); | ||
} | ||
|
||
/// @notice Lets a module admin set platform fee type. | ||
function setPlatformFeeType(PlatformFeeType _feeType) external { | ||
if (!_canSetPlatformFeeInfo()) { | ||
revert("Not authorized"); | ||
} | ||
_setupPlatformFeeType(_feeType); | ||
} | ||
|
||
/// @dev Sets platform fee type. | ||
function _setupPlatformFeeType(PlatformFeeType _feeType) internal { | ||
platformFeeType = _feeType; | ||
|
||
emit PlatformFeeTypeUpdated(_feeType); | ||
} | ||
|
||
/// @dev Returns whether platform fee info can be set in the given execution context. | ||
function _canSetPlatformFeeInfo() internal view virtual returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
/// @author thirdweb | ||
|
||
import "./interface/IPrimarySale_V1.sol"; | ||
|
||
/** | ||
* @title Primary Sale | ||
* @notice Thirdweb's `PrimarySale` is a contract extension to be used with any base contract. It exposes functions for setting and reading | ||
* the recipient of primary sales, and lets the inheriting contract perform conditional logic that uses information about | ||
* primary sales, if desired. | ||
*/ | ||
|
||
abstract contract PrimarySale is IPrimarySale { | ||
/// @dev The address that receives all primary sales value. | ||
address private recipient; | ||
|
||
/// @dev Returns primary sale recipient address. | ||
function primarySaleRecipient() public view override returns (address) { | ||
return recipient; | ||
} | ||
|
||
/** | ||
* @notice Updates primary sale recipient. | ||
* @dev Caller should be authorized to set primary sales info. | ||
* See {_canSetPrimarySaleRecipient}. | ||
* Emits {PrimarySaleRecipientUpdated Event}; See {_setupPrimarySaleRecipient}. | ||
* | ||
* @param _saleRecipient Address to be set as new recipient of primary sales. | ||
*/ | ||
function setPrimarySaleRecipient(address _saleRecipient) external override { | ||
if (!_canSetPrimarySaleRecipient()) { | ||
revert("Not authorized"); | ||
} | ||
_setupPrimarySaleRecipient(_saleRecipient); | ||
} | ||
|
||
/// @dev Lets a contract admin set the recipient for all primary sales. | ||
function _setupPrimarySaleRecipient(address _saleRecipient) internal { | ||
recipient = _saleRecipient; | ||
emit PrimarySaleRecipientUpdated(_saleRecipient); | ||
} | ||
|
||
/// @dev Returns whether primary sale recipient can be set in the given execution context. | ||
function _canSetPrimarySaleRecipient() internal view virtual returns (bool); | ||
} |
33 changes: 33 additions & 0 deletions
33
contracts/legacy-contracts/extension/interface/IPlatformFee_V1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
/// @author thirdweb | ||
|
||
/** | ||
* Thirdweb's `PlatformFee` is a contract extension to be used with any base contract. It exposes functions for setting and reading | ||
* the recipient of platform fee and the platform fee basis points, and lets the inheriting contract perform conditional logic | ||
* that uses information about platform fees, if desired. | ||
*/ | ||
|
||
interface IPlatformFee { | ||
/// @dev Fee type variants: percentage fee and flat fee | ||
enum PlatformFeeType { | ||
Bps, | ||
Flat | ||
} | ||
|
||
/// @dev Returns the platform fee bps and recipient. | ||
function getPlatformFeeInfo() external view returns (address, uint16); | ||
|
||
/// @dev Lets a module admin update the fees on primary sales. | ||
function setPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) external; | ||
|
||
/// @dev Emitted when fee on primary sales is updated. | ||
event PlatformFeeInfoUpdated(address indexed platformFeeRecipient, uint256 platformFeeBps); | ||
|
||
/// @dev Emitted when the flat platform fee is updated. | ||
event FlatPlatformFeeUpdated(address platformFeeRecipient, uint256 flatFee); | ||
|
||
/// @dev Emitted when the platform fee type is updated. | ||
event PlatformFeeTypeUpdated(PlatformFeeType feeType); | ||
} |
21 changes: 21 additions & 0 deletions
21
contracts/legacy-contracts/extension/interface/IPrimarySale_V1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
/// @author thirdweb | ||
|
||
/** | ||
* Thirdweb's `Primary` is a contract extension to be used with any base contract. It exposes functions for setting and reading | ||
* the recipient of primary sales, and lets the inheriting contract perform conditional logic that uses information about | ||
* primary sales, if desired. | ||
*/ | ||
|
||
interface IPrimarySale { | ||
/// @dev The adress that receives all primary sales value. | ||
function primarySaleRecipient() external view returns (address); | ||
|
||
/// @dev Lets a module admin set the default recipient of all primary sales. | ||
function setPrimarySaleRecipient(address _saleRecipient) external; | ||
|
||
/// @dev Emitted when a new sale recipient is set. | ||
event PrimarySaleRecipientUpdated(address indexed recipient); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.