// SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.16; import "./interface/IPrimarySale.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 recipients; mapping(address => uint16) private recipientBps; uint16 private constant MAX_BPS = 10_000; error RecipientCantBeZeroAddressError(); error RecipientAlreadySetError(); error InsufficientBPSError(); constructor(PrimarySaleRecipient[] memory _recipients) { uint256 totalBps = 0; for (uint256 i = 0; i < _recipients.length; i++) { if (_recipients[i].recipient == address(0)) { revert RecipientCantBeZeroAddressError(); } if (recipientBps[_recipients[i].recipient] > 0) { revert RecipientAlreadySetError(); } totalBps += _recipients[i].bps; recipients.push(_recipients[i].recipient); recipientBps[_recipients[i].recipient] = _recipients[i].bps; } if (totalBps != MAX_BPS) { revert InsufficientBPSError(); } } /// @dev Returns primary sale recipient address. function primarySaleRecipients() public view override returns (address[] memory) { return recipients; } function primarySaleRecipientBps(address _recipient) public view returns (uint16 bps) { return recipientBps[_recipient]; } }