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