Skip to content

Commit

Permalink
ERC1155Sale set paymenttoken separately
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed May 29, 2024
1 parent f4e4ccc commit 70b27a2
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/tokens/ERC1155/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The `ERC1155Items` contract is a preset that configures the `ERC1155BaseToken` c

The `ERC1155Sale` contract is a preset that configures the `ERC1155BaseToken` contract to allow for the sale of tokens. It adds a `mint(address to, , uint256[] memory tokenIds, uint256[] memory amounts, bytes memory data, bytes32[] calldata proof)` function allows for the minting of tokens under various conditions.

Conditions may be set by the contract owner using either the `setTokenSaleDetails(uint256 tokenId, uint256 cost, uint256 supplyCap, uint64 startTime, uint64 endTime, bytes32 merkleRoot)` function for single token settings or the `setGlobalSaleDetails(uint256 cost, uint256 supplyCap, address paymentTokenAddr, uint64 startTime, uint64 endTime, bytes32 merkleRoot)` function for global settings. These functions can only be called by accounts with the `MINT_ADMIN_ROLE`.
Conditions may be set by the contract owner. Set the payment token with `setPaymentToken(address paymentTokenAddr)`, then use either the `setTokenSaleDetails(uint256 tokenId, uint256 cost, uint256 supplyCap, uint64 startTime, uint64 endTime, bytes32 merkleRoot)` function for single token settings or the `setGlobalSaleDetails(uint256 cost, uint256 supplyCap, uint64 startTime, uint64 endTime, bytes32 merkleRoot)` function for global settings. These functions can only be called by accounts with the `MINT_ADMIN_ROLE`.

When using a merkle proof, each caller may only use each root once. To prevent collisions ensure the same root is not used for multiple sale details.
Leaves are defined as `keccak256(abi.encodePacked(caller, tokenId))`. The `caller` is the message sender, who will also receive the tokens. The `tokenId` is the id of the token that will be minted, (for global sales `type(uint256).max` is used).
Expand Down
17 changes: 14 additions & 3 deletions src/tokens/ERC1155/utility/sale/ERC1155Sale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,32 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
IERC1155ItemsFunctions(_items).batchMint(to, tokenIds, amounts, data);
}

//
// Admin
//

/**
* Set the payment token.
* @param paymentTokenAddr The ERC20 token address to accept payment in. address(0) indicates ETH.
* @dev This should be set before the sale starts.
*/
function setPaymentToken(address paymentTokenAddr) public onlyRole(MINT_ADMIN_ROLE) {
_paymentToken = paymentTokenAddr;
}

/**
* Set the global sale details.
* @param cost The amount of payment tokens to accept for each token minted.
* @param supplyCap The maximum number of tokens that can be minted.
* @param paymentTokenAddr The ERC20 token address to accept payment in. address(0) indicates ETH.
* @param startTime The start time of the sale. Tokens cannot be minted before this time.
* @param endTime The end time of the sale. Tokens cannot be minted after this time.
* @param merkleRoot The merkle root for allowlist minting.
* @dev A zero end time indicates an inactive sale.
* @notice The payment token is set globally.
*/
function setGlobalSaleDetails(
uint256 cost,
uint256 supplyCap,
address paymentTokenAddr,
uint64 startTime,
uint64 endTime,
bytes32 merkleRoot
Expand All @@ -223,7 +235,6 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
if (endTime < startTime || endTime <= block.timestamp) {
revert InvalidSaleDetails();
}
_paymentToken = paymentTokenAddr;
_globalSaleDetails = SaleDetails(cost, startTime, endTime, merkleRoot);
totalSupplyCap = supplyCap;
emit GlobalSaleDetailsUpdated(cost, supplyCap, startTime, endTime, merkleRoot);
Expand Down
3 changes: 2 additions & 1 deletion test/tokens/ERC1155/utility/sale/ERC1155SaleBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ contract ERC1155SaleTest is TestHelper, IERC1155SaleSignals, IERC1155SupplySigna
checkSelectorCollision(0x3013ce29); // paymentToken()
checkSelectorCollision(0x36568abe); // renounceRole(bytes32,address)
checkSelectorCollision(0xd547741f); // revokeRole(bytes32,address)
checkSelectorCollision(0x43d3f88b); // setGlobalSaleDetails(uint256,uint256,address,uint64,uint64,bytes32)
checkSelectorCollision(0x97559600); // setGlobalSaleDetails(uint256,uint256,uint64,uint64,bytes32)
checkSelectorCollision(0x6a326ab1); // setPaymentToken(address)
checkSelectorCollision(0x4f651ccd); // setTokenSaleDetails(uint256,uint256,uint256,uint64,uint64,bytes32)
checkSelectorCollision(0x01ffc9a7); // supportsInterface(bytes4)
checkSelectorCollision(0x0869678c); // tokenSaleDetails(uint256)
Expand Down
Loading

0 comments on commit 70b27a2

Please sign in to comment.