|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +pragma solidity ^0.8.11; |
| 3 | + |
| 4 | +import "../extension/interface/ITokenBundle.sol"; |
| 5 | + |
| 6 | +/** |
| 7 | + * The thirdweb `Pack` contract is a lootbox mechanism. An account can bundle up arbitrary ERC20, ERC721 and ERC1155 tokens into |
| 8 | + * a set of packs. A pack can then be opened in return for a selection of the tokens in the pack. The selection of tokens distributed |
| 9 | + * on opening a pack depends on the relative supply of all tokens in the packs. |
| 10 | + */ |
| 11 | + |
| 12 | +interface IPackVRFDirect is ITokenBundle { |
| 13 | + /** |
| 14 | + * @notice All info relevant to packs. |
| 15 | + * |
| 16 | + * @param perUnitAmounts Mapping from a UID -> to the per-unit amount of that asset i.e. `Token` at that index. |
| 17 | + * @param openStartTimestamp The timestamp after which packs can be opened. |
| 18 | + * @param amountDistributedPerOpen The number of reward units distributed per open. |
| 19 | + */ |
| 20 | + struct PackInfo { |
| 21 | + uint256[] perUnitAmounts; |
| 22 | + uint128 openStartTimestamp; |
| 23 | + uint128 amountDistributedPerOpen; |
| 24 | + } |
| 25 | + |
| 26 | + /// @notice Emitted when a set of packs is created. |
| 27 | + event PackCreated(uint256 indexed packId, address recipient, uint256 totalPacksCreated); |
| 28 | + |
| 29 | + /// @notice Emitted when the opening of a pack is requested. |
| 30 | + event PackOpenRequested(address indexed opener, uint256 indexed packId, uint256 amountToOpen, uint256 requestId); |
| 31 | + |
| 32 | + /// @notice Emitted when Chainlink VRF fulfills a random number request. |
| 33 | + event PackRandomnessFulfilled(uint256 indexed packId, uint256 indexed requestId); |
| 34 | + |
| 35 | + /// @notice Emitted when a pack is opened. |
| 36 | + event PackOpened( |
| 37 | + uint256 indexed packId, |
| 38 | + address indexed opener, |
| 39 | + uint256 numOfPacksOpened, |
| 40 | + Token[] rewardUnitsDistributed |
| 41 | + ); |
| 42 | + |
| 43 | + /** |
| 44 | + * @notice Creates a pack with the stated contents. |
| 45 | + * |
| 46 | + * @param contents The reward units to pack in the packs. |
| 47 | + * @param numOfRewardUnits The number of reward units to create, for each asset specified in `contents`. |
| 48 | + * @param packUri The (metadata) URI assigned to the packs created. |
| 49 | + * @param openStartTimestamp The timestamp after which packs can be opened. |
| 50 | + * @param amountDistributedPerOpen The number of reward units distributed per open. |
| 51 | + * @param recipient The recipient of the packs created. |
| 52 | + * |
| 53 | + * @return packId The unique identifer of the created set of packs. |
| 54 | + * @return packTotalSupply The total number of packs created. |
| 55 | + */ |
| 56 | + function createPack( |
| 57 | + Token[] calldata contents, |
| 58 | + uint256[] calldata numOfRewardUnits, |
| 59 | + string calldata packUri, |
| 60 | + uint128 openStartTimestamp, |
| 61 | + uint128 amountDistributedPerOpen, |
| 62 | + address recipient |
| 63 | + ) external payable returns (uint256 packId, uint256 packTotalSupply); |
| 64 | + |
| 65 | + /** |
| 66 | + * @notice Lets a pack owner request to open a pack. |
| 67 | + * |
| 68 | + * @param packId The identifier of the pack to open. |
| 69 | + * @param amountToOpen The number of packs to open at once. |
| 70 | + */ |
| 71 | + function openPack(uint256 packId, uint256 amountToOpen) external returns (uint256 requestId); |
| 72 | + |
| 73 | + /// @notice Called by a pack opener to claim rewards from the opened pack. |
| 74 | + function claimRewards() external returns (Token[] memory rewardUnits); |
| 75 | + |
| 76 | + /// @notice Called by a pack opener to open a pack in a single transaction, instead of calling openPack and claimRewards separately. |
| 77 | + function openPackAndClaimRewards( |
| 78 | + uint256 _packId, |
| 79 | + uint256 _amountToOpen, |
| 80 | + uint32 _callBackGasLimit |
| 81 | + ) external returns (uint256); |
| 82 | + |
| 83 | + /// @notice Returns whether a pack opener is ready to call `claimRewards`. |
| 84 | + function canClaimRewards(address _opener) external view returns (bool); |
| 85 | +} |
0 commit comments