|
| 1 | +// Copyright Immutable Pty Ltd 2018 - 2023 |
| 2 | +// SPDX-License-Identifier: Apache 2.0 |
| 3 | +pragma solidity 0.8.19; |
| 4 | + |
| 5 | +import "@imtbl/contracts/contracts/token/erc1155/preset/ImmutableERC1155.sol"; |
| 6 | +import "@imtbl/contracts/contracts/token/erc721/preset/ImmutableERC721.sol"; |
| 7 | + |
| 8 | + |
| 9 | +/** |
| 10 | + * @title ImmutableERC1155 |
| 11 | + * @author @jasonzwli, Immutable |
| 12 | + */ |
| 13 | +contract RunnerToken1155 is ImmutableERC1155 { |
| 14 | + /// ===== Constructor ===== |
| 15 | + uint256 public constant FOXTOKENID = 1; |
| 16 | + uint256 public constant COINTOKENID = 2; |
| 17 | + |
| 18 | + // A reference to the Immutable Runner Skin contract for the craftSkin function to use. |
| 19 | + // Note: Immutable Runner Skin contract simply extends ImmutableERC721, so we can set |
| 20 | + // the type to ImmutableERC721 |
| 21 | + ImmutableERC721 private _skinContract; |
| 22 | + |
| 23 | + /** |
| 24 | + * @notice Grants `DEFAULT_ADMIN_ROLE` to the supplied `owner` address |
| 25 | + * |
| 26 | + * Sets the name and symbol for the collection |
| 27 | + * Sets the default admin to `owner` |
| 28 | + * Sets the `baseURI` |
| 29 | + * Sets the royalty receiver and amount (this can not be changed once set) |
| 30 | + * @param owner The address that will be granted the `DEFAULT_ADMIN_ROLE` |
| 31 | + * @param name_ The name of the collection |
| 32 | + * @param baseURI_ The base URI for the collection |
| 33 | + * @param contractURI_ The contract URI for the collection |
| 34 | + * @param _operatorAllowlist The address of the OAL |
| 35 | + * @param _receiver The address that will receive the royalty payments |
| 36 | + * @param _feeNumerator The percentage of the sale price that will be paid as a royalty |
| 37 | + */ |
| 38 | + constructor( |
| 39 | + address owner, |
| 40 | + string memory name_, |
| 41 | + string memory baseURI_, |
| 42 | + string memory contractURI_, |
| 43 | + address _operatorAllowlist, |
| 44 | + address _receiver, |
| 45 | + uint96 _feeNumerator, |
| 46 | + address skinContractAddr |
| 47 | + ) ImmutableERC1155(owner, name_, baseURI_, contractURI_, _operatorAllowlist, _receiver, _feeNumerator) { |
| 48 | + // Grant the contract deployer the default admin role: it will be able |
| 49 | + // to grant and revoke any roles |
| 50 | + _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); |
| 51 | + // Save the Immutable Runner Skin contract address |
| 52 | + _skinContract = ImmutableERC721(skinContractAddr); |
| 53 | + |
| 54 | + // Uncomment the line below to grant minter role to contract deployer |
| 55 | + _grantRole(MINTER_ROLE, msg.sender); |
| 56 | + } |
| 57 | + |
| 58 | + function mintNFT(address to) external onlyRole(MINTER_ROLE) { |
| 59 | + super._mint(to, FOXTOKENID, 1, ""); |
| 60 | + } |
| 61 | + |
| 62 | + function mintCoins(address to, uint256 quantity) external onlyRole(MINTER_ROLE) { |
| 63 | + super._mint(to, COINTOKENID, quantity, ""); |
| 64 | + } |
| 65 | + |
| 66 | + // Burns three tokens and crafts a skin to the caller |
| 67 | + function craftSkin() external { |
| 68 | + require( |
| 69 | + balanceOf(msg.sender, COINTOKENID) >= 3, |
| 70 | + "craftSkin: Caller does not have enough tokens" |
| 71 | + ); |
| 72 | + |
| 73 | + // Burn caller's three tokens |
| 74 | + _burn(msg.sender, COINTOKENID, 3); |
| 75 | + |
| 76 | + // Mint one Immutable Runner Skin to the caller |
| 77 | + // Note: To mint a skin, the Immutable Runner Token contract must have the |
| 78 | + // Immutable Runner Skin contract minter role. |
| 79 | + _skinContract.mintByQuantity(msg.sender, 1); |
| 80 | + } |
| 81 | +} |
0 commit comments