Skip to content

Instantly share code, notes, and snippets.

@abramsymons
Created August 13, 2020 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abramsymons/0d764c062ff4306e5668abbc5e51440a to your computer and use it in GitHub Desktop.
Save abramsymons/0d764c062ff4306e5668abbc5e51440a to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.3;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";
import "https://github.com/BrightID/BrightID-SmartContract/blob/master/v4/IBrightID.sol";
contract Sahm is ERC20, Ownable {
IBrightID public brightid;
mapping(address => bool) public claimed;
uint256 public reward = 5 * 10 ** 17;
uint256 public counter = 0;
uint256 public stepSize = 1000000;
constructor() ERC20("Sahm", "Sahm") public {
}
function setBrightID(address addr) public onlyOwner {
brightid = IBrightID(addr);
}
function claim(
address addr,
address parent,
uint8 v,
bytes32 r,
bytes32 s
) public {
bytes32 message = keccak256(abi.encodePacked(addr, parent));
address signer = ecrecover(message, v, r, s);
require(signer == addr, "not authorized");
require (brightid.verifications(addr) > 0, "address is not verified");
if (parent == address(0) || brightid.verifications(parent) == 0) {
parent = owner();
}
address tmp = addr;
while (tmp != address(0)) {
require (!claimed[tmp]);
tmp = brightid.history(tmp);
}
claimed[addr] = true;
counter = counter + 1;
if (counter == stepSize) {
counter = 0;
reward = reward / 2;
stepSize = stepSize * 2;
}
_mint(addr, reward);
_mint(parent, reward);
_mint(owner(), reward);
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
require(to == owner() || brightid.verifications(to) > 0, "to address is not verified");
require(from == address(0) || from == owner() || brightid.verifications(from) > 0, "from address is not verified");
require(to == owner() || balanceOf(to).add(amount) <= 20 * 10**18, "Account balance exceeds 20");
}
function reclaim(address addr) public {
address tmp = brightid.history(addr);
while (tmp != address(0)) {
if (balanceOf(tmp) > 0) {
_transfer(tmp, addr, balanceOf(tmp));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment