Created
August 2, 2019 15:21
-
-
Save nateawelch/031dd94f9d35dfdfd2e8d1748573244b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.7; | |
pragma experimental ABIEncoderV2; | |
import { IERC20 } from "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; | |
import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; | |
import { IHumanityRegistry } from "./interface/IHumanityRegistry.sol"; | |
import { CompoundPoolingBank } from "./CompoundPoolingBank.sol"; | |
/** | |
* @title UniversalBasicIncome | |
* @dev Dai that can be claimed by humans on the Human Registry. | |
*/ | |
contract UniversalBasicIncome { | |
using SafeMath for uint; | |
IHumanityRegistry public registry; | |
IERC20 public dai; | |
CompoundPoolingBank public bank; | |
uint public constant MONTHLY_INCOME = 1e18; // 1 Dai | |
uint public constant INCOME_PER_SECOND = MONTHLY_INCOME / 30 days; | |
mapping (address => uint) public claimTimes; | |
constructor(IHumanityRegistry _registry, IERC20 _dai, CompoundPoolingBank _bank) public { | |
registry = _registry; | |
dai = _dai; | |
bank = _bank; | |
} | |
function claim() public { | |
require(registry.isHuman(msg.sender), "UniversalBasicIncome::claim: You must be on the Humanity registry to claim income"); | |
uint income; | |
uint time = block.timestamp; | |
// If claiming for the first time, send 1 month of UBI | |
if (claimTimes[msg.sender] == 0) { | |
income = MONTHLY_INCOME; | |
} else { | |
income = time.sub(claimTimes[msg.sender]).mul(INCOME_PER_SECOND); | |
} | |
uint balance = bank.excessDepositTokens(); | |
// If not enough Dai reserves, send the remaining balance | |
uint actualIncome = balance < income ? balance : income; | |
bank.withdrawInterest(msg.sender, actualIncome); | |
claimTimes[msg.sender] = time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment