Last active
February 12, 2022 17:15
-
-
Save llSourcell/daac5930ecfc81b063e364dc012d1077 to your computer and use it in GitHub Desktop.
This file contains 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
// What is Basic Income? | |
// Why? | |
// How? Dividend issuing token every x interval, like a week. Polygon, fast, cheap | |
// Problem - Proof of Unique Identity | |
// | |
pragma solidity ^0.4.21; | |
contract BasicIncomeToken { | |
//DEFINE TOKEN NAMING | |
string public name = "Basic Income Token"; | |
string public symbol = "BIT"; | |
//DEFINE SUPPLY | |
// This code assumes decimals is zero---do not change. | |
uint8 public decimals = 0; // DO NOT CHANGE! | |
uint256 public totalSupply = 1000000 * (uint256(10) ** decimals); | |
mapping(address => uint256) public balanceOf; | |
constructor() public { | |
// Initially assign all tokens to the contract's creator. | |
balanceOf[msg.sender] = totalSupply; | |
emit Transfer(address(0), msg.sender, totalSupply); | |
} | |
mapping(address => uint256) dividendBalanceOf; | |
uint256 public dividendPerToken; | |
mapping(address => uint256) dividendCreditedTo; | |
function update(address account) internal { | |
uint256 owed = | |
dividendPerToken - dividendCreditedTo[account]; | |
dividendBalanceOf[account] += balanceOf[account] * owed; | |
dividendCreditedTo[account] = dividendPerToken; | |
} | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
mapping(address => mapping(address => uint256)) public allowance; | |
function transfer(address to, uint256 value) public returns (bool success) { | |
require(balanceOf[msg.sender] >= value); | |
update(msg.sender); // <-- added to simple ERC20 contract | |
update(to); // <-- added to simple ERC20 contract | |
balanceOf[msg.sender] -= value; | |
balanceOf[to] += value; | |
emit Transfer(msg.sender, to, value); | |
return true; | |
} | |
function transferFrom(address from, address to, uint256 value) | |
public | |
returns (bool success) | |
{ | |
require(value <= balanceOf[from]); | |
require(value <= allowance[from][msg.sender]); | |
update(from); // <-- added to simple ERC20 contract | |
update(to); // <-- added to simple ERC20 contract | |
balanceOf[from] -= value; | |
balanceOf[to] += value; | |
allowance[from][msg.sender] -= value; | |
emit Transfer(from, to, value); | |
return true; | |
} | |
function deposit() public payable { | |
dividendPerToken += msg.value / totalSupply; // ignoring remainder | |
} | |
function withdraw() public { | |
update(msg.sender); | |
uint256 amount = dividendBalanceOf[msg.sender]; | |
dividendBalanceOf[msg.sender] = 0; | |
msg.sender.transfer(amount); | |
} | |
function approve(address spender, uint256 value) | |
public | |
returns (bool success) | |
{ | |
allowance[msg.sender][spender] = value; | |
emit Approval(msg.sender, spender, value); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment