2020-02-18 20:23:31 +01:00
|
|
|
pragma solidity ^0.6.1;
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
2020-04-24 18:59:08 +02:00
|
|
|
import "./Bucket.sol";
|
2020-04-03 14:19:40 +02:00
|
|
|
import "./erc20/IERC20.sol";
|
2020-02-18 20:23:31 +01:00
|
|
|
|
2020-04-24 18:59:08 +02:00
|
|
|
contract GiftBucket is Bucket {
|
2020-02-21 16:09:42 +01:00
|
|
|
uint256 public redeemableSupply;
|
|
|
|
|
2020-04-24 18:59:08 +02:00
|
|
|
constructor(
|
|
|
|
address _tokenAddress,
|
|
|
|
uint256 _startTime,
|
|
|
|
uint256 _expirationTime) Bucket("KeycardGift", _tokenAddress, _startTime, _expirationTime) public {}
|
2020-02-18 20:23:31 +01:00
|
|
|
|
2020-02-21 19:55:53 +01:00
|
|
|
function totalSupply() public view returns(uint256) {
|
2020-04-24 18:59:08 +02:00
|
|
|
return IERC20(tokenAddress).balanceOf(address(this));
|
2020-02-21 16:09:42 +01:00
|
|
|
}
|
|
|
|
|
2020-02-21 19:55:53 +01:00
|
|
|
function availableSupply() public view returns(uint256) {
|
2020-02-21 16:09:42 +01:00
|
|
|
uint256 _totalSupply = this.totalSupply();
|
2020-02-21 16:57:23 +01:00
|
|
|
require(_totalSupply >= redeemableSupply, "redeemableSupply is greater than redeemableSupply");
|
|
|
|
|
2020-02-21 16:09:42 +01:00
|
|
|
return _totalSupply - redeemableSupply;
|
2020-02-18 20:23:31 +01:00
|
|
|
}
|
|
|
|
|
2020-02-21 19:55:53 +01:00
|
|
|
function createGift(address recipient, uint256 amount, bytes32 code) external onlyOwner {
|
2020-02-18 20:23:31 +01:00
|
|
|
require(amount > 0, "invalid amount");
|
2020-02-21 16:09:42 +01:00
|
|
|
|
|
|
|
uint256 _availableSupply = this.availableSupply();
|
|
|
|
require(_availableSupply >= amount, "low supply");
|
2020-02-18 20:23:31 +01:00
|
|
|
|
2020-02-21 19:55:53 +01:00
|
|
|
Gift storage gift = gifts[recipient];
|
2020-04-08 14:00:16 +03:00
|
|
|
require(gift.recipient == address(0), "recipient already used");
|
2020-02-18 20:23:31 +01:00
|
|
|
|
2020-02-21 19:55:53 +01:00
|
|
|
gift.recipient = recipient;
|
2020-02-18 20:23:31 +01:00
|
|
|
gift.code = code;
|
2020-04-24 18:59:08 +02:00
|
|
|
gift.data = amount;
|
2020-02-18 20:23:31 +01:00
|
|
|
|
2020-02-21 16:57:23 +01:00
|
|
|
require(redeemableSupply + amount > redeemableSupply, "addition overflow");
|
2020-02-21 16:09:42 +01:00
|
|
|
redeemableSupply += amount;
|
2020-02-18 20:23:31 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 18:59:08 +02:00
|
|
|
function transferRedeemable(uint256 data, Redeem memory redeem) override internal {
|
|
|
|
require(redeemableSupply >= data, "not enough redeemable supply");
|
|
|
|
redeemableSupply -= data;
|
|
|
|
IERC20(tokenAddress).transfer(redeem.receiver, data);
|
2020-02-18 20:23:31 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 18:59:08 +02:00
|
|
|
function transferRedeemablesToOwner() override internal {
|
|
|
|
bool success = IERC20(tokenAddress).transfer(owner, this.totalSupply());
|
2020-02-18 20:23:31 +01:00
|
|
|
assert(success);
|
|
|
|
}
|
|
|
|
}
|