-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathErc1155Quest.sol
64 lines (57 loc) · 2.53 KB
/
Erc1155Quest.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.15;
import {IERC1155} from '@openzeppelin/contracts/token/ERC1155/ERC1155.sol';
import {ERC1155Holder} from '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol';
import {Quest} from './Quest.sol';
/// @title Erc1155Quest
/// @author RabbitHole.gg
/// @dev This contract is used to create quests with a reward token that implements the ERC1155 standard
contract Erc1155Quest is Quest, ERC1155Holder {
constructor(
address rewardTokenAddress_,
uint256 endTime_,
uint256 startTime_,
uint256 totalParticipants_,
uint256 rewardAmountInWeiOrTokenId_,
string memory questId_,
address receiptContractAddress_
)
Quest(
rewardTokenAddress_,
endTime_,
startTime_,
totalParticipants_,
rewardAmountInWeiOrTokenId_,
questId_,
receiptContractAddress_
){}
/// @dev Checks the balance to ensure that it has enough for all of the participants. Only able to be called by owner
function start() public override {
if (IERC1155(rewardToken).balanceOf(address(this), rewardAmountInWeiOrTokenId) < totalParticipants)
revert TotalAmountExceedsBalance();
super.start();
}
/// @dev Transfers the reward token `rewardAmountInWeiOrTokenId` to the msg.sender
/// @param amount_ The amount of reward tokens to transfer
function _transferRewards(uint256 amount_) internal override {
IERC1155(rewardToken).safeTransferFrom(address(this), msg.sender, rewardAmountInWeiOrTokenId, amount_, '0x00');
}
/// @dev Returns the amount of rewards. Since an 1155 is just one token, this returns itself
/// @param redeemableTokenCount_ The amount of reward tokens that the user is eligible for
/// @return The amount of reward tokens that the user is eligible for
function _calculateRewards(uint256 redeemableTokenCount_) internal pure override returns (uint256) {
return redeemableTokenCount_;
}
/// @dev Withdraws the remaining tokens from the contract. Only able to be called by owner
/// @param to_ The address to send the remaining tokens to
function withdrawRemainingTokens(address to_) public override onlyOwner {
super.withdrawRemainingTokens(to_);
IERC1155(rewardToken).safeTransferFrom(
address(this),
to_,
rewardAmountInWeiOrTokenId,
IERC1155(rewardToken).balanceOf(address(this), rewardAmountInWeiOrTokenId),
'0x00'
);
}
}