Contract Address Details

0xD7aC544F8A570C4d8764c3AAbCF6870CBD960D0D

UBIScheme Last Balance Update: Block #15172464
Created by 0x5128e3–22e4bb at 0x149298–47c961

Balance

0 Fuse

Fetching tokens...

Contract name:
UBIScheme




Optimization enabled
true
Compiler version
v0.5.16+commit.9c3226ce




Optimization runs
200
EVM Version
default




Verified at
2021-02-07 10:35:43.108905Z

Constructor Arguments

000000000000000000000000f96dadc6d71113f6500e97590760c924da1ef70e000000000000000000000000fa8d865a962ca8456df331d78806152d3ac5b84f00000000000000000000000018bcdf79a724648bf34eb06701be81bd072a238400000000000000000000000000000000000000000000000000000000601915af00000000000000000000000000000000000000000000000000000000601a672f000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000007

Arg [0] (address) : 0xf96dadc6d71113f6500e97590760c924da1ef70e
Arg [1] (address) : 0xfa8d865a962ca8456df331d78806152d3ac5b84f
Arg [2] (address) : 0x18bcdf79a724648bf34eb06701be81bd072a2384
Arg [3] (uint256) : 1612256687
Arg [4] (uint256) : 1612343087
Arg [5] (uint256) : 14
Arg [6] (uint256) : 7

              

Contract source code

// File: openzeppelin-solidity/contracts/ownership/Ownable.sol
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @return the address of the owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner());
_;
}
/**
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0));
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// File: @daostack/infra/contracts/Reputation.sol
/**
* @title Reputation system
* @dev A DAO has Reputation System which allows peers to rate other peers in order to build trust .
* A reputation is use to assign influence measure to a DAO'S peers.
* Reputation is similar to regular tokens but with one crucial difference: It is non-transferable.
* The Reputation contract maintain a map of address to reputation value.
* It provides an onlyOwner functions to mint and burn reputation _to (or _from) a specific address.
*/
contract Reputation is Ownable {
uint8 public decimals = 18; //Number of decimals of the smallest unit
// Event indicating minting of reputation to an address.
event Mint(address indexed _to, uint256 _amount);
// Event indicating burning of reputation for an address.
event Burn(address indexed _from, uint256 _amount);
/// @dev `Checkpoint` is the structure that attaches a block number to a
/// given value, the block number attached is the one that last changed the
/// value
struct Checkpoint {
// `fromBlock` is the block number that the value was generated from
uint128 fromBlock;
// `value` is the amount of reputation at a specific block number
uint128 value;
}
// `balances` is the map that tracks the balance of each address, in this
// contract when the balance changes the block number that the change
// occurred is also included in the map
mapping (address => Checkpoint[]) balances;
// Tracks the history of the `totalSupply` of the reputation
Checkpoint[] totalSupplyHistory;
/// @notice Constructor to create a Reputation
constructor(
) public
{
}
/// @dev This function makes it easy to get the total number of reputation
/// @return The total number of reputation
function totalSupply() public view returns (uint256) {
return totalSupplyAt(block.number);
}
////////////////
// Query balance and totalSupply in History
////////////////
/**
* @dev return the reputation amount of a given owner
* @param _owner an address of the owner which we want to get his reputation
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balanceOfAt(_owner, block.number);
}
/// @dev Queries the balance of `_owner` at a specific `_blockNumber`
/// @param _owner The address from which the balance will be retrieved
/// @param _blockNumber The block number when the balance is queried
/// @return The balance at `_blockNumber`
function balanceOfAt(address _owner, uint256 _blockNumber)
public view returns (uint256)
{
if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
return 0;
// This will return the expected balance during normal situations
} else {
return getValueAt(balances[_owner], _blockNumber);
}
}
/// @notice Total amount of reputation at a specific `_blockNumber`.
/// @param _blockNumber The block number when the totalSupply is queried
/// @return The total amount of reputation at `_blockNumber`
function totalSupplyAt(uint256 _blockNumber) public view returns(uint256) {
if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
return 0;
// This will return the expected totalSupply during normal situations
} else {
return getValueAt(totalSupplyHistory, _blockNumber);
}
}
/// @notice Generates `_amount` reputation that are assigned to `_owner`
/// @param _user The address that will be assigned the new reputation
/// @param _amount The quantity of reputation generated
/// @return True if the reputation are generated correctly
function mint(address _user, uint256 _amount) public onlyOwner returns (bool) {
uint256 curTotalSupply = totalSupply();
require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow
uint256 previousBalanceTo = balanceOf(_user);
require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
updateValueAtNow(balances[_user], previousBalanceTo + _amount);
emit Mint(_user, _amount);
return true;
}
/// @notice Burns `_amount` reputation from `_owner`
/// @param _user The address that will lose the reputation
/// @param _amount The quantity of reputation to burn
/// @return True if the reputation are burned correctly
function burn(address _user, uint256 _amount) public onlyOwner returns (bool) {
uint256 curTotalSupply = totalSupply();
uint256 amountBurned = _amount;
uint256 previousBalanceFrom = balanceOf(_user);
if (previousBalanceFrom < amountBurned) {
amountBurned = previousBalanceFrom;
}
updateValueAtNow(totalSupplyHistory, curTotalSupply - amountBurned);
updateValueAtNow(balances[_user], previousBalanceFrom - amountBurned);
emit Burn(_user, amountBurned);
return true;
}
////////////////
// Internal helper functions to query and set a value in a snapshot array
////////////////
/// @dev `getValueAt` retrieves the number of reputation at a given block number
/// @param checkpoints The history of values being queried
/// @param _block The block number to retrieve the value at
/// @return The number of reputation being queried
function getValueAt(Checkpoint[] storage checkpoints, uint256 _block) internal view returns (uint256) {
if (checkpoints.length == 0) {
return 0;
}
// Shortcut for the actual value
if (_block >= checkpoints[checkpoints.length-1].fromBlock) {
return checkpoints[checkpoints.length-1].value;
}
if (_block < checkpoints[0].fromBlock) {
return 0;
}
// Binary search of the value in the array
uint256 min = 0;
uint256 max = checkpoints.length-1;
while (max > min) {
uint256 mid = (max + min + 1) / 2;
if (checkpoints[mid].fromBlock<=_block) {
min = mid;
} else {
max = mid-1;
}
}
return checkpoints[min].value;
}
/// @dev `updateValueAtNow` used to update the `balances` map and the
/// `totalSupplyHistory`
/// @param checkpoints The history of data being updated
/// @param _value The new number of reputation
function updateValueAtNow(Checkpoint[] storage checkpoints, uint256 _value) internal {
require(uint128(_value) == _value); //check value is in the 128 bits bounderies
if ((checkpoints.length == 0) || (checkpoints[checkpoints.length - 1].fromBlock < block.number)) {
Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++];
newCheckPoint.fromBlock = uint128(block.number);
newCheckPoint.value = uint128(_value);
} else {
Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1];
oldCheckPoint.value = uint128(_value);
}
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/IERC20.sol
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File: openzeppelin-solidity/contracts/math/SafeMath.sol
/**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/
library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/
contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token for a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_allowed[from][msg.sender] = _allowed[from][msg.sender].sub(value);
_transfer(from, to, value);
emit Approval(from, msg.sender, _allowed[from][msg.sender]);
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = _allowed[msg.sender][spender].add(addedValue);
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed_[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
require(spender != address(0));
_allowed[msg.sender][spender] = _allowed[msg.sender][spender].sub(subtractedValue);
emit Approval(msg.sender, spender, _allowed[msg.sender][spender]);
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_allowed[account][msg.sender] = _allowed[account][msg.sender].sub(value);
_burn(account, value);
emit Approval(account, msg.sender, _allowed[account][msg.sender]);
}
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20Burnable.sol
/**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/
contract ERC20Burnable is ERC20 {
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/
function burn(uint256 value) public {
_burn(msg.sender, value);
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint256 value) public {
_burnFrom(from, value);
}
}
// File: @daostack/arc/contracts/controller/DAOToken.sol
/**
* @title DAOToken, base on zeppelin contract.
* @dev ERC20 compatible token. It is a mintable, burnable token.
*/
contract DAOToken is ERC20, ERC20Burnable, Ownable {
string public name;
string public symbol;
// solhint-disable-next-line const-name-snakecase
uint8 public constant decimals = 18;
uint256 public cap;
/**
* @dev Constructor
* @param _name - token name
* @param _symbol - token symbol
* @param _cap - token cap - 0 value means no cap
*/
constructor(string memory _name, string memory _symbol, uint256 _cap)
public {
name = _name;
symbol = _symbol;
cap = _cap;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
*/
function mint(address _to, uint256 _amount) public onlyOwner returns (bool) {
if (cap > 0)
require(totalSupply().add(_amount) <= cap);
_mint(_to, _amount);
return true;
}
}
// File: openzeppelin-solidity/contracts/utils/Address.sol
/**
* Utility library of inline functions on addresses
*/
library Address {
/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param account address of the account to check
* @return whether the target address is a contract
*/
function isContract(address account) internal view returns (bool) {
uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
}
}
// File: @daostack/arc/contracts/libs/SafeERC20.sol
/*
SafeERC20 by daostack.
The code is based on a fix by SECBIT Team.
USE WITH CAUTION & NO WARRANTY
REFERENCE & RELATED READING
- https://github.com/ethereum/solidity/issues/4116
- https://medium.com/@chris_77367/explaining-unexpected-reverts-starting-with-solidity-0-4-22-3ada6e82308c
- https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
- https://gist.github.com/BrendanChou/88a2eeb80947ff00bcf58ffdafeaeb61
*/
library SafeERC20 {
using Address for address;
bytes4 constant private TRANSFER_SELECTOR = bytes4(keccak256(bytes("transfer(address,uint256)")));
bytes4 constant private TRANSFERFROM_SELECTOR = bytes4(keccak256(bytes("transferFrom(address,address,uint256)")));
bytes4 constant private APPROVE_SELECTOR = bytes4(keccak256(bytes("approve(address,uint256)")));
function safeTransfer(address _erc20Addr, address _to, uint256 _value) internal {
// Must be a contract addr first!
require(_erc20Addr.isContract());
(bool success, bytes memory returnValue) =
// solhint-disable-next-line avoid-low-level-calls
_erc20Addr.call(abi.encodeWithSelector(TRANSFER_SELECTOR, _to, _value));
// call return false when something wrong
require(success);
//check return value
require(returnValue.length == 0 || (returnValue.length == 32 && (returnValue[31] != 0)));
}
function safeTransferFrom(address _erc20Addr, address _from, address _to, uint256 _value) internal {
// Must be a contract addr first!
require(_erc20Addr.isContract());
(bool success, bytes memory returnValue) =
// solhint-disable-next-line avoid-low-level-calls
_erc20Addr.call(abi.encodeWithSelector(TRANSFERFROM_SELECTOR, _from, _to, _value));
// call return false when something wrong
require(success);
//check return value
require(returnValue.length == 0 || (returnValue.length == 32 && (returnValue[31] != 0)));
}
function safeApprove(address _erc20Addr, address _spender, uint256 _value) internal {
// Must be a contract addr first!
require(_erc20Addr.isContract());
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero.
require((_value == 0) || (IERC20(_erc20Addr).allowance(address(this), _spender) == 0));
(bool success, bytes memory returnValue) =
// solhint-disable-next-line avoid-low-level-calls
_erc20Addr.call(abi.encodeWithSelector(APPROVE_SELECTOR, _spender, _value));
// call return false when something wrong
require(success);
//check return value
require(returnValue.length == 0 || (returnValue.length == 32 && (returnValue[31] != 0)));
}
}
// File: @daostack/arc/contracts/controller/Avatar.sol
/**
* @title An Avatar holds tokens, reputation and ether for a controller
*/
contract Avatar is Ownable {
using SafeERC20 for address;
string public orgName;
DAOToken public nativeToken;
Reputation public nativeReputation;
event GenericCall(address indexed _contract, bytes _data, uint _value, bool _success);
event SendEther(uint256 _amountInWei, address indexed _to);
event ExternalTokenTransfer(address indexed _externalToken, address indexed _to, uint256 _value);
event ExternalTokenTransferFrom(address indexed _externalToken, address _from, address _to, uint256 _value);
event ExternalTokenApproval(address indexed _externalToken, address _spender, uint256 _value);
event ReceiveEther(address indexed _sender, uint256 _value);
event MetaData(string _metaData);
/**
* @dev the constructor takes organization name, native token and reputation system
and creates an avatar for a controller
*/
constructor(string memory _orgName, DAOToken _nativeToken, Reputation _nativeReputation) public {
orgName = _orgName;
nativeToken = _nativeToken;
nativeReputation = _nativeReputation;
}
/**
* @dev enables an avatar to receive ethers
*/
function() external payable {
emit ReceiveEther(msg.sender, msg.value);
}
/**
* @dev perform a generic call to an arbitrary contract
* @param _contract the contract's address to call
* @param _data ABI-encoded contract call to call `_contract` address.
* @param _value value (ETH) to transfer with the transaction
* @return bool success or fail
* bytes - the return bytes of the called contract's function.
*/
function genericCall(address _contract, bytes memory _data, uint256 _value)
public
onlyOwner
returns(bool success, bytes memory returnValue) {
// solhint-disable-next-line avoid-call-value
(success, returnValue) = _contract.call.value(_value)(_data);
emit GenericCall(_contract, _data, _value, success);
}
/**
* @dev send ethers from the avatar's wallet
* @param _amountInWei amount to send in Wei units
* @param _to send the ethers to this address
* @return bool which represents success
*/
function sendEther(uint256 _amountInWei, address payable _to) public onlyOwner returns(bool) {
_to.transfer(_amountInWei);
emit SendEther(_amountInWei, _to);
return true;
}
/**
* @dev external token transfer
* @param _externalToken the token contract
* @param _to the destination address
* @param _value the amount of tokens to transfer
* @return bool which represents success
*/
function externalTokenTransfer(IERC20 _externalToken, address _to, uint256 _value)
public onlyOwner returns(bool)
{
address(_externalToken).safeTransfer(_to, _value);
emit ExternalTokenTransfer(address(_externalToken), _to, _value);
return true;
}
/**
* @dev external token transfer from a specific account
* @param _externalToken the token contract
* @param _from the account to spend token from
* @param _to the destination address
* @param _value the amount of tokens to transfer
* @return bool which represents success
*/
function externalTokenTransferFrom(
IERC20 _externalToken,
address _from,
address _to,
uint256 _value
)
public onlyOwner returns(bool)
{
address(_externalToken).safeTransferFrom(_from, _to, _value);
emit ExternalTokenTransferFrom(address(_externalToken), _from, _to, _value);
return true;
}
/**
* @dev externalTokenApproval approve the spender address to spend a specified amount of tokens
* on behalf of msg.sender.
* @param _externalToken the address of the Token Contract
* @param _spender address
* @param _value the amount of ether (in Wei) which the approval is referring to.
* @return bool which represents a success
*/
function externalTokenApproval(IERC20 _externalToken, address _spender, uint256 _value)
public onlyOwner returns(bool)
{
address(_externalToken).safeApprove(_spender, _value);
emit ExternalTokenApproval(address(_externalToken), _spender, _value);
return true;
}
/**
* @dev metaData emits an event with a string, should contain the hash of some meta data.
* @param _metaData a string representing a hash of the meta data
* @return bool which represents a success
*/
function metaData(string memory _metaData) public onlyOwner returns(bool) {
emit MetaData(_metaData);
return true;
}
}
// File: @daostack/arc/contracts/globalConstraints/GlobalConstraintInterface.sol
contract GlobalConstraintInterface {
enum CallPhase { Pre, Post, PreAndPost }
function pre( address _scheme, bytes32 _params, bytes32 _method ) public returns(bool);
function post( address _scheme, bytes32 _params, bytes32 _method ) public returns(bool);
/**
* @dev when return if this globalConstraints is pre, post or both.
* @return CallPhase enum indication Pre, Post or PreAndPost.
*/
function when() public returns(CallPhase);
}
// File: @daostack/arc/contracts/controller/ControllerInterface.sol
/**
* @title Controller contract
* @dev A controller controls the organizations tokens ,reputation and avatar.
* It is subject to a set of schemes and constraints that determine its behavior.
* Each scheme has it own parameters and operation permissions.
*/
interface ControllerInterface {
/**
* @dev Mint `_amount` of reputation that are assigned to `_to` .
* @param _amount amount of reputation to mint
* @param _to beneficiary address
* @return bool which represents a success
*/
function mintReputation(uint256 _amount, address _to, address _avatar)
external
returns(bool);
/**
* @dev Burns `_amount` of reputation from `_from`
* @param _amount amount of reputation to burn
* @param _from The address that will lose the reputation
* @return bool which represents a success
*/
function burnReputation(uint256 _amount, address _from, address _avatar)
external
returns(bool);
/**
* @dev mint tokens .
* @param _amount amount of token to mint
* @param _beneficiary beneficiary address
* @param _avatar address
* @return bool which represents a success
*/
function mintTokens(uint256 _amount, address _beneficiary, address _avatar)
external
returns(bool);
/**
* @dev register or update a scheme
* @param _scheme the address of the scheme
* @param _paramsHash a hashed configuration of the usage of the scheme
* @param _permissions the permissions the new scheme will have
* @param _avatar address
* @return bool which represents a success
*/
function registerScheme(address _scheme, bytes32 _paramsHash, bytes4 _permissions, address _avatar)
external
returns(bool);
/**
* @dev unregister a scheme
* @param _avatar address
* @param _scheme the address of the scheme
* @return bool which represents a success
*/
function unregisterScheme(address _scheme, address _avatar)
external
returns(bool);
/**
* @dev unregister the caller's scheme
* @param _avatar address
* @return bool which represents a success
*/
function unregisterSelf(address _avatar) external returns(bool);
/**
* @dev add or update Global Constraint
* @param _globalConstraint the address of the global constraint to be added.
* @param _params the constraint parameters hash.
* @param _avatar the avatar of the organization
* @return bool which represents a success
*/
function addGlobalConstraint(address _globalConstraint, bytes32 _params, address _avatar)
external returns(bool);
/**
* @dev remove Global Constraint
* @param _globalConstraint the address of the global constraint to be remove.
* @param _avatar the organization avatar.
* @return bool which represents a success
*/
function removeGlobalConstraint (address _globalConstraint, address _avatar)
external returns(bool);
/**
* @dev upgrade the Controller
* The function will trigger an event 'UpgradeController'.
* @param _newController the address of the new controller.
* @param _avatar address
* @return bool which represents a success
*/
function upgradeController(address _newController, Avatar _avatar)
external returns(bool);
/**
* @dev perform a generic call to an arbitrary contract
* @param _contract the contract's address to call
* @param _data ABI-encoded contract call to call `_contract` address.
* @param _avatar the controller's avatar address
* @param _value value (ETH) to transfer with the transaction
* @return bool -success
* bytes - the return value of the called _contract's function.
*/
function genericCall(address _contract, bytes calldata _data, Avatar _avatar, uint256 _value)
external
returns(bool, bytes memory);
/**
* @dev send some ether
* @param _amountInWei the amount of ether (in Wei) to send
* @param _to address of the beneficiary
* @param _avatar address
* @return bool which represents a success
*/
function sendEther(uint256 _amountInWei, address payable _to, Avatar _avatar)
external returns(bool);
/**
* @dev send some amount of arbitrary ERC20 Tokens
* @param _externalToken the address of the Token Contract
* @param _to address of the beneficiary
* @param _value the amount of ether (in Wei) to send
* @param _avatar address
* @return bool which represents a success
*/
function externalTokenTransfer(IERC20 _externalToken, address _to, uint256 _value, Avatar _avatar)
external
returns(bool);
/**
* @dev transfer token "from" address "to" address
* One must to approve the amount of tokens which can be spend from the
* "from" account.This can be done using externalTokenApprove.
* @param _externalToken the address of the Token Contract
* @param _from address of the account to send from
* @param _to address of the beneficiary
* @param _value the amount of ether (in Wei) to send
* @param _avatar address
* @return bool which represents a success
*/
function externalTokenTransferFrom(
IERC20 _externalToken,
address _from,
address _to,
uint256 _value,
Avatar _avatar)
external
returns(bool);
/**
* @dev externalTokenApproval approve the spender address to spend a specified amount of tokens
* on behalf of msg.sender.
* @param _externalToken the address of the Token Contract
* @param _spender address
* @param _value the amount of ether (in Wei) which the approval is referring to.
* @return bool which represents a success
*/
function externalTokenApproval(IERC20 _externalToken, address _spender, uint256 _value, Avatar _avatar)
external
returns(bool);
/**
* @dev metaData emits an event with a string, should contain the hash of some meta data.
* @param _metaData a string representing a hash of the meta data
* @param _avatar Avatar
* @return bool which represents a success
*/
function metaData(string calldata _metaData, Avatar _avatar) external returns(bool);
/**
* @dev getNativeReputation
* @param _avatar the organization avatar.
* @return organization native reputation
*/
function getNativeReputation(address _avatar)
external
view
returns(address);
function isSchemeRegistered( address _scheme, address _avatar) external view returns(bool);
function getSchemeParameters(address _scheme, address _avatar) external view returns(bytes32);
function getGlobalConstraintParameters(address _globalConstraint, address _avatar) external view returns(bytes32);
function getSchemePermissions(address _scheme, address _avatar) external view returns(bytes4);
/**
* @dev globalConstraintsCount return the global constraint pre and post count
* @return uint256 globalConstraintsPre count.
* @return uint256 globalConstraintsPost count.
*/
function globalConstraintsCount(address _avatar) external view returns(uint, uint);
function isGlobalConstraintRegistered(address _globalConstraint, address _avatar) external view returns(bool);
}
// File: openzeppelin-solidity/contracts/access/Roles.sol
/**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}
/**
* @dev give an account access to this role
*/
function add(Role storage role, address account) internal {
require(account != address(0));
require(!has(role, account));
role.bearer[account] = true;
}
/**
* @dev remove an account's access to this role
*/
function remove(Role storage role, address account) internal {
require(account != address(0));
require(has(role, account));
role.bearer[account] = false;
}
/**
* @dev check if an account has this role
* @return bool
*/
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0));
return role.bearer[account];
}
}
// File: openzeppelin-solidity/contracts/access/roles/PauserRole.sol
contract PauserRole {
using Roles for Roles.Role;
event PauserAdded(address indexed account);
event PauserRemoved(address indexed account);
Roles.Role private _pausers;
constructor () internal {
_addPauser(msg.sender);
}
modifier onlyPauser() {
require(isPauser(msg.sender));
_;
}
function isPauser(address account) public view returns (bool) {
return _pausers.has(account);
}
function addPauser(address account) public onlyPauser {
_addPauser(account);
}
function renouncePauser() public {
_removePauser(msg.sender);
}
function _addPauser(address account) internal {
_pausers.add(account);
emit PauserAdded(account);
}
function _removePauser(address account) internal {
_pausers.remove(account);
emit PauserRemoved(account);
}
}
// File: openzeppelin-solidity/contracts/lifecycle/Pausable.sol
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is PauserRole {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor () internal {
_paused = false;
}
/**
* @return true if the contract is paused, false otherwise.
*/
function paused() public view returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!_paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(_paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() public onlyPauser whenNotPaused {
_paused = true;
emit Paused(msg.sender);
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() public onlyPauser whenPaused {
_paused = false;
emit Unpaused(msg.sender);
}
}
// File: contracts/dao/schemes/SchemeGuard.sol
/* @dev abstract contract for ensuring that schemes have been registered properly
* Allows setting zero Avatar in situations where the Avatar hasn't been created yet
*/
contract SchemeGuard is Ownable {
Avatar avatar;
ControllerInterface internal controller = ControllerInterface(0);
/** @dev Constructor. only sets controller if given avatar is not null.
* @param _avatar The avatar of the DAO.
*/
constructor(Avatar _avatar) public {
avatar = _avatar;
if (avatar != Avatar(0)) {
controller = ControllerInterface(avatar.owner());
}
}
/** @dev modifier to check if caller is avatar
*/
modifier onlyAvatar() {
require(address(avatar) == msg.sender, "only Avatar can call this method");
_;
}
/** @dev modifier to check if scheme is registered
*/
modifier onlyRegistered() {
require(isRegistered(), "Scheme is not registered");
_;
}
/** @dev modifier to check if scheme is not registered
*/
modifier onlyNotRegistered() {
require(!isRegistered(), "Scheme is registered");
_;
}
/** @dev modifier to check if call is a scheme that is registered
*/
modifier onlyRegisteredCaller() {
require(isRegistered(msg.sender), "Calling scheme is not registered");
_;
}
/** @dev Function to set a new avatar and controller for scheme
* can only be done by owner of scheme
*/
function setAvatar(Avatar _avatar) public onlyOwner {
avatar = _avatar;
controller = ControllerInterface(avatar.owner());
}
/** @dev function to see if an avatar has been set and if this scheme is registered
* @return true if scheme is registered
*/
function isRegistered() public view returns (bool) {
return isRegistered(address(this));
}
/** @dev function to see if an avatar has been set and if this scheme is registered
* @return true if scheme is registered
*/
function isRegistered(address scheme) public view returns (bool) {
require(avatar != Avatar(0), "Avatar is not set");
if (!(controller.isSchemeRegistered(scheme, address(avatar)))) {
return false;
}
return true;
}
}
// File: contracts/identity/IdentityAdminRole.sol
/**
* @title Contract managing the identity admin role
*/
contract IdentityAdminRole is Ownable {
using Roles for Roles.Role;
event IdentityAdminAdded(address indexed account);
event IdentityAdminRemoved(address indexed account);
Roles.Role private IdentityAdmins;
/* @dev constructor. Adds caller as an admin
*/
constructor() internal {
_addIdentityAdmin(msg.sender);
}
/* @dev Modifier to check if caller is an admin
*/
modifier onlyIdentityAdmin() {
require(isIdentityAdmin(msg.sender), "not IdentityAdmin");
_;
}
/**
* @dev Checks if account is identity admin
* @param account Account to check
* @return Boolean indicating if account is identity admin
*/
function isIdentityAdmin(address account) public view returns (bool) {
return IdentityAdmins.has(account);
}
/**
* @dev Adds a identity admin account. Is only callable by owner.
* @param account Address to be added
* @return true if successful
*/
function addIdentityAdmin(address account) public onlyOwner returns (bool) {
_addIdentityAdmin(account);
return true;
}
/**
* @dev Removes a identity admin account. Is only callable by owner.
* @param account Address to be removed
* @return true if successful
*/
function removeIdentityAdmin(address account) public onlyOwner returns (bool) {
_removeIdentityAdmin(account);
return true;
}
/**
* @dev Allows an admin to renounce their role
*/
function renounceIdentityAdmin() public {
_removeIdentityAdmin(msg.sender);
}
/**
* @dev Internal implementation of addIdentityAdmin
*/
function _addIdentityAdmin(address account) internal {
IdentityAdmins.add(account);
emit IdentityAdminAdded(account);
}
/**
* @dev Internal implementation of removeIdentityAdmin
*/
function _removeIdentityAdmin(address account) internal {
IdentityAdmins.remove(account);
emit IdentityAdminRemoved(account);
}
}
// File: contracts/identity/Identity.sol
/* @title Identity contract responsible for whitelisting
* and keeping track of amount of whitelisted users
*/
contract Identity is IdentityAdminRole, SchemeGuard, Pausable {
using Roles for Roles.Role;
using SafeMath for uint256;
Roles.Role private blacklist;
Roles.Role private whitelist;
Roles.Role private contracts;
uint256 public whitelistedCount = 0;
uint256 public whitelistedContracts = 0;
uint256 public authenticationPeriod = 14;
mapping(address => uint256) public dateAuthenticated;
mapping(address => uint256) public dateAdded;
mapping(address => string) public addrToDID;
mapping(bytes32 => address) public didHashToAddress;
event BlacklistAdded(address indexed account);
event BlacklistRemoved(address indexed account);
event WhitelistedAdded(address indexed account);
event WhitelistedRemoved(address indexed account);
event ContractAdded(address indexed account);
event ContractRemoved(address indexed account);
constructor() public SchemeGuard(Avatar(0)) {}
/* @dev Sets a new value for authenticationPeriod.
* Can only be called by Identity Administrators.
* @param period new value for authenticationPeriod
*/
function setAuthenticationPeriod(uint256 period) public onlyOwner whenNotPaused {
authenticationPeriod = period;
}
/* @dev Sets the authentication date of `account`
* to the current time.
* Can only be called by Identity Administrators.
* @param account address to change its auth date
*/
function authenticate(address account)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
dateAuthenticated[account] = now;
}
/* @dev Adds an address as whitelisted.
* Can only be called by Identity Administrators.
* @param account address to add as whitelisted
*/
function addWhitelisted(address account)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
_addWhitelisted(account);
}
/* @dev Adds an address as whitelisted under a specific ID
* @param account The address to add
* @param did the ID to add account under
*/
function addWhitelistedWithDID(address account, string memory did)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
_addWhitelistedWithDID(account, did);
}
/* @dev Removes an address as whitelisted.
* Can only be called by Identity Administrators.
* @param account address to remove as whitelisted
*/
function removeWhitelisted(address account)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
_removeWhitelisted(account);
}
/* @dev Renounces message sender from whitelisted
*/
function renounceWhitelisted() public whenNotPaused {
_removeWhitelisted(msg.sender);
}
/* @dev Returns true if given address has been added to whitelist
* @param account the address to check
* @return a bool indicating weather the address is present in whitelist
*/
function isWhitelisted(address account) public view returns (bool) {
uint256 daysSinceAuthentication = (now.sub(dateAuthenticated[account])) / 1 days;
return
(daysSinceAuthentication <= authenticationPeriod) && whitelist.has(account);
}
/* @dev Function that gives the date the given user was added
* @param account The address to check
* @return The date the address was added
*/
function lastAuthenticated(address account) public view returns (uint256) {
return dateAuthenticated[account];
}
// /**
// *
// * @dev Function to transfer whitelisted privilege to another address
// * relocates did of sender to give address
// * @param account The address to transfer to
// */
// function transferAccount(address account) public whenNotPaused {
// ERC20 token = avatar.nativeToken();
// require(!isBlacklisted(account), "Cannot transfer to blacklisted");
// require(token.balanceOf(account) == 0, "Account is already in use");
// require(isWhitelisted(msg.sender), "Requester need to be whitelisted");
// require(
// keccak256(bytes(addrToDID[account])) == keccak256(bytes("")),
// "address already has DID"
// );
// string memory did = addrToDID[msg.sender];
// bytes32 pHash = keccak256(bytes(did));
// uint256 balance = token.balanceOf(msg.sender);
// token.transferFrom(msg.sender, account, balance);
// _removeWhitelisted(msg.sender);
// _addWhitelisted(account);
// addrToDID[account] = did;
// didHashToAddress[pHash] = account;
// }
/* @dev Adds an address to blacklist.
* Can only be called by Identity Administrators.
* @param account address to add as blacklisted
*/
function addBlacklisted(address account)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
blacklist.add(account);
emit BlacklistAdded(account);
}
/* @dev Removes an address from blacklist
* Can only be called by Identity Administrators.
* @param account address to remove as blacklisted
*/
function removeBlacklisted(address account)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
blacklist.remove(account);
emit BlacklistRemoved(account);
}
/* @dev Function to add a Contract to list of contracts
* @param account The address to add
*/
function addContract(address account)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
require(isContract(account), "Given address is not a contract");
contracts.add(account);
_addWhitelisted(account);
emit ContractAdded(account);
}
/* @dev Function to remove a Contract from list of contracts
* @param account The address to add
*/
function removeContract(address account)
public
onlyRegistered
onlyIdentityAdmin
whenNotPaused
{
contracts.remove(account);
_removeWhitelisted(account);
emit ContractRemoved(account);
}
/* @dev Function to check if given contract is on list of contracts.
* @param address to check
* @return a bool indicating if address is on list of contracts
*/
function isDAOContract(address account) public view returns (bool) {
return contracts.has(account);
}
/* @dev Internal function to add to whitelisted
* @param account the address to add
*/
function _addWhitelisted(address account) internal {
whitelist.add(account);
whitelistedCount += 1;
dateAdded[account] = now;
dateAuthenticated[account] = now;
if (isContract(account)) {
whitelistedContracts += 1;
}
emit WhitelistedAdded(account);
}
/* @dev Internal whitelisting with did function.
* @param account the address to add
* @param did the id to register account under
*/
function _addWhitelistedWithDID(address account, string memory did) internal {
bytes32 pHash = keccak256(bytes(did));
require(didHashToAddress[pHash] == address(0), "DID already registered");
addrToDID[account] = did;
didHashToAddress[pHash] = account;
_addWhitelisted(account);
}
/* @dev Internal function to remove from whitelisted
* @param account the address to add
*/
function _removeWhitelisted(address account) internal {
whitelist.remove(account);
whitelistedCount -= 1;
delete dateAuthenticated[account];
if (isContract(account)) {
whitelistedContracts -= 1;
}
string memory did = addrToDID[account];
bytes32 pHash = keccak256(bytes(did));
delete dateAuthenticated[account];
delete addrToDID[account];
delete didHashToAddress[pHash];
emit WhitelistedRemoved(account);
}
/* @dev Returns true if given address has been added to the blacklist
* @param account the address to check
* @return a bool indicating weather the address is present in the blacklist
*/
function isBlacklisted(address account) public view returns (bool) {
return blacklist.has(account);
}
/* @dev Function to see if given address is a contract
* @return true if address is a contract
*/
function isContract(address _addr) internal view returns (bool) {
uint256 length;
assembly {
length := extcodesize(_addr)
}
return length > 0;
}
}
// File: contracts/identity/IdentityGuard.sol
/* @title The IdentityGuard contract
* @dev Contract containing an identity and
* modifiers to ensure proper access
*/
contract IdentityGuard is Ownable {
Identity public identity;
/* @dev Constructor. Checks if identity is a zero address
* @param _identity The identity contract.
*/
constructor(Identity _identity) public {
require(_identity != Identity(0), "Supplied identity is null");
identity = _identity;
}
/* @dev Modifier that requires the sender to be not blacklisted
*/
modifier onlyNotBlacklisted() {
require(!identity.isBlacklisted(msg.sender), "Caller is blacklisted");
_;
}
/* @dev Modifier that requires the given address to be not blacklisted
* @param _account The address to be checked
*/
modifier requireNotBlacklisted(address _account) {
require(!identity.isBlacklisted(_account), "Receiver is blacklisted");
_;
}
/* @dev Modifier that requires the sender to be whitelisted
*/
modifier onlyWhitelisted() {
require(identity.isWhitelisted(msg.sender), "is not whitelisted");
_;
}
/* @dev Modifier that requires the given address to be whitelisted
* @param _account the given address
*/
modifier requireWhitelisted(address _account) {
require(identity.isWhitelisted(_account), "is not whitelisted");
_;
}
/* @dev Modifier that requires the sender to be an approved DAO contract
*/
modifier onlyDAOContract() {
require(identity.isDAOContract(msg.sender), "is not whitelisted contract");
_;
}
/* @dev Modifier that requires the given address to be whitelisted
* @param _account the given address
*/
modifier requireDAOContract(address _contract) {
require(identity.isDAOContract(_contract), "is not whitelisted contract");
_;
}
/* @dev Modifier that requires the sender to have been whitelisted
* before or on the given date
* @param date The time sender must have been added before
*/
modifier onlyAddedBefore(uint256 date) {
require(
identity.lastAuthenticated(msg.sender) <= date,
"Was not added within period"
);
_;
}
/* @dev Modifier that requires sender to be an identity admin
*/
modifier onlyIdentityAdmin() {
require(identity.isIdentityAdmin(msg.sender), "not IdentityAdmin");
_;
}
/* @dev Allows owner to set a new identity contract if
* the given identity contract has been registered as a scheme
*/
function setIdentity(Identity _identity) public onlyOwner {
require(_identity.isRegistered(), "Identity is not registered");
identity = _identity;
}
}
// File: contracts/dao/schemes/FeeFormula.sol
/**
* @title Fee formula abstract contract
*/
contract AbstractFees is SchemeGuard {
constructor() public SchemeGuard(Avatar(0)) {}
function getTxFees(
uint256 _value,
address _sender,
address _recipient
) public view returns (uint256, bool);
}
/**
* @title Fee formula contract
* contract that provides a function to calculate
* fees as a percentage of any given value
*/
contract FeeFormula is AbstractFees {
using SafeMath for uint256;
uint256 public percentage;
bool public constant senderPays = false;
/**
* @dev Constructor. Requires the given percentage parameter
* to be less than 100.
* @param _percentage the percentage to calculate fees of
*/
constructor(uint256 _percentage) public {
require(_percentage < 100, "Percentage should be <100");
percentage = _percentage;
}
/** @dev calculates the fee of given value.
* @param _value the value of the transaction to calculate fees from
* @param _sender address sending.
* @param _recipient address receiving.
* @return the transactional fee for given value
*/
function getTxFees(
uint256 _value,
address _sender,
address _recipient
) public view returns (uint256, bool) {
return (_value.mul(percentage).div(100), senderPays);
}
}
// File: contracts/dao/schemes/FormulaHolder.sol
/* @title Contract in charge of setting registered fee formula schemes to contract
*/
contract FormulaHolder is Ownable {
AbstractFees public formula;
/* @dev Constructor. Requires that given formula is a valid contract.
* @param _formula The fee formula contract.
*/
constructor(AbstractFees _formula) public {
require(_formula != AbstractFees(0), "Supplied formula is null");
formula = _formula;
}
/* @dev Sets the given fee formula contract. Is only callable by owner.
* Reverts if formula has not been registered by DAO.
* @param _formula the new fee formula scheme
*/
function setFormula(AbstractFees _formula) public onlyOwner {
_formula.isRegistered();
formula = _formula;
}
}
// File: contracts/token/ERC677/ERC677.sol
/* @title ERC677 interface
*/
interface ERC677 {
event Transfer(address indexed from, address indexed to, uint256 value, bytes data);
function transferAndCall(
address,
uint256,
bytes calldata
) external returns (bool);
}
// File: contracts/token/ERC677/ERC677Receiver.sol
/* @title ERC677Receiver interface
*/
interface ERC677Receiver {
function onTokenTransfer(
address _from,
uint256 _value,
bytes calldata _data
) external returns (bool);
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20Pausable.sol
/**
* @title Pausable token
* @dev ERC20 modified with pausable transfers.
**/
contract ERC20Pausable is ERC20, Pausable {
function transfer(address to, uint256 value) public whenNotPaused returns (bool) {
return super.transfer(to, value);
}
function transferFrom(address from, address to, uint256 value) public whenNotPaused returns (bool) {
return super.transferFrom(from, to, value);
}
function approve(address spender, uint256 value) public whenNotPaused returns (bool) {
return super.approve(spender, value);
}
function increaseAllowance(address spender, uint addedValue) public whenNotPaused returns (bool success) {
return super.increaseAllowance(spender, addedValue);
}
function decreaseAllowance(address spender, uint subtractedValue) public whenNotPaused returns (bool success) {
return super.decreaseAllowance(spender, subtractedValue);
}
}
// File: contracts/token/ERC677Token.sol
/* @title ERC677Token contract.
*/
contract ERC677Token is ERC677, DAOToken, ERC20Pausable {
constructor(
string memory _name,
string memory _symbol,
uint256 _cap
) public DAOToken(_name, _symbol, _cap) {}
/**
* @dev transfer token to a contract address with additional data if the recipient is a contact.
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
* @param _data The extra data to be passed to the receiving contract.
* @return true if transfer is successful
*/
function _transferAndCall(
address _to,
uint256 _value,
bytes memory _data
) internal whenNotPaused returns (bool) {
bool res = super.transfer(_to, _value);
emit Transfer(msg.sender, _to, _value, _data);
if (isContract(_to)) {
require(contractFallback(_to, _value, _data), "Contract fallback failed");
}
return res;
}
/* @dev Contract fallback function. Is called if transferAndCall is called
* to a contract
*/
function contractFallback(
address _to,
uint256 _value,
bytes memory _data
) private returns (bool) {
ERC677Receiver receiver = ERC677Receiver(_to);
require(
receiver.onTokenTransfer(msg.sender, _value, _data),
"Contract Fallback failed"
);
return true;
}
/* @dev Function to check if given address is a contract
* @param _addr Address to check
* @return true if given address is a contract
*/
function isContract(address _addr) internal view returns (bool) {
uint256 length;
assembly {
length := extcodesize(_addr)
}
return length > 0;
}
}
// File: openzeppelin-solidity/contracts/access/roles/MinterRole.sol
contract MinterRole {
using Roles for Roles.Role;
event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);
Roles.Role private _minters;
constructor () internal {
_addMinter(msg.sender);
}
modifier onlyMinter() {
require(isMinter(msg.sender));
_;
}
function isMinter(address account) public view returns (bool) {
return _minters.has(account);
}
function addMinter(address account) public onlyMinter {
_addMinter(account);
}
function renounceMinter() public {
_removeMinter(msg.sender);
}
function _addMinter(address account) internal {
_minters.add(account);
emit MinterAdded(account);
}
function _removeMinter(address account) internal {
_minters.remove(account);
emit MinterRemoved(account);
}
}
// File: contracts/token/ERC677BridgeToken.sol
contract ERC677BridgeToken is ERC677Token, MinterRole {
address public bridgeContract;
constructor(
string memory _name,
string memory _symbol,
uint256 _cap
) public ERC677Token(_name, _symbol, _cap) {}
function setBridgeContract(address _bridgeContract) public onlyMinter {
require(
_bridgeContract != address(0) && isContract(_bridgeContract),
"Invalid bridge contract"
);
bridgeContract = _bridgeContract;
}
}
// File: contracts/token/GoodDollar.sol
/**
* @title The GoodDollar ERC677 token contract
*/
contract GoodDollar is ERC677BridgeToken, IdentityGuard, FormulaHolder {
address feeRecipient;
// Overrides hard-coded decimal in DAOToken
uint256 public constant decimals = 2;
/**
* @dev constructor
* @param _name The name of the token
* @param _symbol The symbol of the token
* @param _cap the cap of the token. no cap if 0
* @param _formula the fee formula contract
* @param _identity the identity contract
* @param _feeRecipient the address that receives transaction fees
*/
constructor(
string memory _name,
string memory _symbol,
uint256 _cap,
AbstractFees _formula,
Identity _identity,
address _feeRecipient
)
public
ERC677BridgeToken(_name, _symbol, _cap)
IdentityGuard(_identity)
FormulaHolder(_formula)
{
feeRecipient = _feeRecipient;
}
/**
* @dev Processes fees from given value and sends
* remainder to given address
* @param to the address to be sent to
* @param value the value to be processed and then
* transferred
* @return a boolean that indicates if the operation was successful
*/
function transfer(address to, uint256 value) public returns (bool) {
uint256 bruttoValue = processFees(msg.sender, to, value);
return super.transfer(to, bruttoValue);
}
/**
* @dev Approve the passed address to spend the specified
* amount of tokens on behalf of msg.sender
* @param spender The address which will spend the funds
* @param value The amount of tokens to be spent
* @return a boolean that indicates if the operation was successful
*/
function approve(address spender, uint256 value) public returns (bool) {
return super.approve(spender, value);
}
/**
* @dev Transfer tokens from one address to another
* @param from The address which you want to send tokens from
* @param to The address which you want to transfer to
* @param value the amount of tokens to be transferred
* @return a boolean that indicates if the operation was successful
*/
function transferFrom(
address from,
address to,
uint256 value
) public returns (bool) {
uint256 bruttoValue = processFees(from, to, value);
return super.transferFrom(from, to, bruttoValue);
}
/**
* @dev Processes transfer fees and calls ERC677Token transferAndCall function
* @param to address to transfer to
* @param value the amount to transfer
* @param data The data to pass to transferAndCall
* @return a bool indicating if transfer function succeeded
*/
function transferAndCall(
address to,
uint256 value,
bytes calldata data
) external returns (bool) {
uint256 bruttoValue = processFees(msg.sender, to, value);
return super._transferAndCall(to, bruttoValue, data);
}
/**
* @dev Minting function
* @param to the address that will receive the minted tokens
* @param value the amount of tokens to mint
* @return a boolean that indicated if the operation was successful
*/
function mint(address to, uint256 value)
public
onlyMinter
requireNotBlacklisted(to)
returns (bool)
{
if (cap > 0) {
require(totalSupply().add(value) <= cap, "Cannot increase supply beyond cap");
}
super._mint(to, value);
return true;
}
/**
* @dev Burns a specific amount of tokens.
* @param value The amount of token to be burned.
*/
function burn(uint256 value) public onlyNotBlacklisted {
super.burn(value);
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint256 value)
public
onlyNotBlacklisted
requireNotBlacklisted(from)
{
super.burnFrom(from, value);
}
/**
* @dev Increase the amount of tokens that an owner allows a spender
* @param spender The address which will spend the funds
* @param addedValue The amount of tokens to increase the allowance by
* @return a boolean that indicated if the operation was successful
*/
function increaseAllowance(address spender, uint256 addedValue)
public
returns (bool)
{
return super.increaseAllowance(spender, addedValue);
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender
* @param spender The address which will spend the funds
* @param subtractedValue The amount of tokens to decrease the allowance by
* @return a boolean that indicated if the operation was successful
*/
function decreaseAllowance(address spender, uint256 subtractedValue)
public
returns (bool)
{
return super.decreaseAllowance(spender, subtractedValue);
}
/**
* @dev Gets the current transaction fees
* @return an uint256 that represents
* the current transaction fees
*/
function getFees(uint256 value) public view returns (uint256, bool) {
return formula.getTxFees(value, address(0), address(0));
}
/**
* @dev Gets the current transaction fees
* @return an uint256 that represents
* the current transaction fees
*/
function getFees(
uint256 value,
address sender,
address recipient
) public view returns (uint256, bool) {
return formula.getTxFees(value, sender, recipient);
}
/**
* @dev Sets the address that receives the transactional fees.
* can only be called by owner
* @param _feeRecipient The new address to receive transactional fees
*/
function setFeeRecipient(address _feeRecipient) public onlyOwner {
feeRecipient = _feeRecipient;
}
/**
* @dev Sends transactional fees to feeRecipient address from given address
* @param account The account that sends the fees
* @param value The amount to subtract fees from
* @return an uint256 that represents the given value minus the transactional fees
*/
function processFees(
address account,
address recipient,
uint256 value
) internal returns (uint256) {
(uint256 txFees, bool senderPays) = getFees(value, account, recipient);
if (txFees > 0 && !identity.isDAOContract(msg.sender)) {
require(
senderPays == false || value.add(txFees) <= balanceOf(account),
"Not enough balance to pay TX fee"
);
if (account == msg.sender) {
super.transfer(feeRecipient, txFees);
} else {
super.transferFrom(account, feeRecipient, txFees);
}
return senderPays ? value : value.sub(txFees);
}
return value;
}
}
// File: contracts/dao/schemes/ActivePeriod.sol
/* @title Abstract contract responsible for ensuring a scheme is only usable within a set period
*/
contract ActivePeriod {
uint256 public periodStart;
uint256 public periodEnd;
bool public isActive;
Avatar avatar;
event SchemeStarted(address indexed by, uint256 time);
event SchemeEnded(address indexed by, uint256 time);
/* @dev modifier that requires scheme to be active
*/
modifier requireActive() {
require(isActive, "is not active");
_;
}
/* @dev modifier that requires scheme to not be active
*/
modifier requireNotActive() {
require(!isActive, "cannot start twice");
_;
}
/* @dev modifier that requires current time to be after period start and before period end
*/
modifier requireInPeriod() {
require(now >= periodStart && now < periodEnd, "not in period");
_;
}
/* @dev modifier that requires current time to be after period end
*/
modifier requirePeriodEnd() {
require(now >= periodEnd, "period has not ended");
_;
}
/* @dev Constructor. requires end period to be larger than start period
* Sets local period parameters and sets isActive to false
* @param _periodStart The time from when the contract can be started
* @param _periodEnd The time from when the contract can be ended
* @param _avatar DAO avatar
*/
constructor(
uint256 _periodStart,
uint256 _periodEnd,
Avatar _avatar
) public {
require(_periodStart < _periodEnd, "start cannot be after nor equal to end");
periodStart = _periodStart;
periodEnd = _periodEnd;
avatar = _avatar;
isActive = false;
}
/* @dev Function to start scheme. Must be inactive and within period.
* Sets isActive to true and emits event with address that started and
* current time.
*/
function start() public requireInPeriod requireNotActive {
isActive = true;
emit SchemeStarted(msg.sender, now);
}
/* @dev Function to end scheme. Must be after assigned period end.
* Calls internal function internalEnd, passing along the avatar
* @param _avatar the avatar of the dao
*/
function end() public requirePeriodEnd {
return internalEnd(avatar);
}
/* @dev internal end function. Must be active to run.
* Sets contract to inactive, emits an event with caller and
* current time, and self-destructs the contract, transferring any
* eth in the contract to the avatar address
* @param _avatar the avatar of the dao
*/
function internalEnd(Avatar _avatar) internal requireActive {
isActive = false;
emit SchemeEnded(msg.sender, now);
selfdestruct(address(_avatar));
}
}
// File: contracts/dao/schemes/FeelessScheme.sol
/**
* @dev Contract for letting scheme add itself to identity
* to allow transferring GoodDollar without paying fees
* and transfer ownership to Avatar
*/
contract FeelessScheme is SchemeGuard, IdentityGuard {
/* @dev Constructor
* @param _identity The identity contract
* @param _avatar The avatar of the DAO
*/
constructor(Identity _identity, Avatar _avatar)
public
SchemeGuard(_avatar)
IdentityGuard(_identity)
{}
/* @dev Internal function to add contract to identity.
* Can only be called if scheme is registered.
*/
function addRights() internal onlyRegistered {
controller.genericCall(
address(identity),
abi.encodeWithSignature("addContract(address)", address(this)),
avatar,
0
);
transferOwnership(address(avatar));
}
/* @dev Internal function to remove contract from identity.
* Can only be called if scheme is registered.
*/
function removeRights() internal onlyRegistered {
controller.genericCall(
address(identity),
abi.encodeWithSignature("removeContract(address)", address(this)),
avatar,
0
);
}
}
// File: contracts/dao/schemes/UBI.sol
/* @title Base contract template for UBI scheme
*/
contract AbstractUBI is ActivePeriod, FeelessScheme {
using SafeMath for uint256;
uint256 initialReserve;
uint256 public claimDistribution;
struct Day {
mapping(address => bool) hasClaimed;
uint256 amountOfClaimers;
uint256 claimAmount;
}
mapping(uint256 => Day) claimDay;
mapping(address => uint256) public lastClaimed;
uint256 public currentDay;
event UBIStarted(uint256 balance, uint256 time);
event UBIClaimed(address indexed claimer, uint256 amount);
event UBIEnded(uint256 claimers, uint256 claimamount);
/**
* @dev Constructor. Checks if avatar is a zero address
* and if periodEnd variable is after periodStart.
* @param _avatar the avatar contract
* @param _periodStart period from when the contract is able to start
* @param _periodEnd period from when the contract is able to end
*/
constructor(
Avatar _avatar,
Identity _identity,
uint256 _initialReserve,
uint256 _periodStart,
uint256 _periodEnd
)
public
ActivePeriod(_periodStart, _periodEnd, _avatar)
FeelessScheme(_identity, _avatar)
{
initialReserve = _initialReserve;
}
/**
* @dev function that returns an uint256 that
* represents the amount each claimer can claim.
* @param reserve the account balance to calculate from
* @return The distribution for each claimer
*/
function distributionFormula(uint256 reserve, address user)
internal
returns (uint256);
/* @dev function that gets the amount of people who claimed on the given day
* @param day the day to get claimer count from, with 0 being the starting day
* @return an integer indicating the amount of people who claimed that day
*/
function getClaimerCount(uint256 day) public view returns (uint256) {
return claimDay[day].amountOfClaimers;
}
/* @dev function that gets the amount that was claimed on the given day
* @param day the day to get claimer count from, with 0 being the starting day
* @return an integer indicating the amount that has been claimed on the given day
*/
function getClaimAmount(uint256 day) public view returns (uint256) {
return claimDay[day].claimAmount;
}
/* @dev function that gets count of claimers and amount claimed for the current day
* @return the amount of claimers and the amount claimed.
*/
function getDailyStats() public view returns (uint256 count, uint256 amount) {
uint256 today = (now.sub(periodStart)) / 1 days;
return (getClaimerCount(today), getClaimAmount(today));
}
/* @dev Function that commences distribution period on contract.
* Can only be called after periodStart and before periodEnd and
* can only be done once. The reserve is sent
* to this contract to allow claimers to claim from said reserve.
* The claim distribution is then calculated and true is returned
* to indicate that claiming can be done.
*/
function start() public onlyRegistered {
super.start();
addRights();
currentDay = now.sub(periodStart) / 1 days;
// Transfer the fee reserve to this contract
DAOToken token = avatar.nativeToken();
if (initialReserve > 0) {
require(
initialReserve <= token.balanceOf(address(avatar)),
"Not enough funds to start"
);
controller.genericCall(
address(token),
abi.encodeWithSignature(
"transfer(address,uint256)",
address(this),
initialReserve
),
avatar,
0
);
}
emit UBIStarted(token.balanceOf(address(this)), now);
}
/**
* @dev Function that ends the claiming period. Can only be done if
* Contract has been started and periodEnd is passed.
* Sends the remaining funds on contract back to the avatar contract
* address
*/
function end() public requirePeriodEnd {
DAOToken token = avatar.nativeToken();
uint256 remainingReserve = token.balanceOf(address(this));
if (remainingReserve > 0) {
require(
token.transfer(address(avatar), remainingReserve),
"end transfer failed"
);
}
removeRights();
super.end();
}
/* @dev UBI claiming function. Can only be called by users that were
* whitelisted before start of contract
* Each claimer can only claim once per UBI contract
* @return true if the user claimed successfully
*/
function claim()
public
requireActive
onlyWhitelisted
onlyAddedBefore(periodStart)
returns (bool)
{
require(!claimDay[currentDay].hasClaimed[msg.sender], "has already claimed");
claimDay[currentDay].hasClaimed[msg.sender] = true;
GoodDollar token = GoodDollar(address(avatar.nativeToken()));
claimDay[currentDay].amountOfClaimers = claimDay[currentDay].amountOfClaimers.add(
1
);
claimDay[currentDay].claimAmount = claimDay[currentDay].claimAmount.add(
claimDistribution
);
lastClaimed[msg.sender] = now;
require(token.transfer(msg.sender, claimDistribution), "claim transfer failed");
emit UBIClaimed(msg.sender, claimDistribution);
return true;
}
}
/* @title UBI scheme contract responsible for calculating a distribution
* based on amount of whitelisted users
*/
contract UBI is AbstractUBI {
uint256 claimers;
/* @dev Constructor. Checks if avatar is a zero address
* and if periodEnd variable is after periodStart.
* @param _avatar the avatar contract
* @param _identity the identity contract
* @param _periodStart period from when the contract is able to start
* @param _periodEnd period from when the contract is able to end
*/
constructor(
Avatar _avatar,
Identity _identity,
uint256 _initialReserve,
uint256 _periodStart,
uint256 _periodEnd
) public AbstractUBI(_avatar, _identity, _initialReserve, _periodStart, _periodEnd) {
claimers = (identity.whitelistedCount()).sub(identity.whitelistedContracts());
}
/* @dev function that calculated the amount each claimer can claim.
* amount to claim is the amount of GoodDollar contract holds
* divided by amount of eligible claimers
* @param reserve the account balance to calculate from
* @return The reserve divided by the amount of registered claimers
*/
function distributionFormula(
uint256 reserve,
address /*user*/
) internal returns (uint256) {
return reserve.div(claimers);
}
/* @dev starts scheme and calculates distribution of UBI
*/
function start() public {
super.start();
DAOToken token = avatar.nativeToken();
claimDistribution = distributionFormula(
token.balanceOf(address(this)),
address(0)
);
}
}
// File: stakingModel/contracts/FirstClaimPool.sol
/**
* @title FirstClaimPool contract that transfer bonus tokens when claiming for
* the first time
*/
contract FirstClaimPool is FeelessScheme, ActivePeriod {
using SafeMath for uint256;
// The whitelisted ex scheme contract
address public ubi;
// The transfer amount to a
// given user address
uint256 public claimAmount;
modifier onlyUBIScheme {
require(msg.sender == ubi, "Only UBIScheme can call this method");
_;
}
modifier ubiHasInitialized {
require(ubi != address(0), "ubi has not initialized");
_;
}
/**
* @dev Constructor
* @param _avatar The avatar of the DAO
* @param _identity The identity contract
* @param _claimAmount The transfer amount to a given user
*/
constructor(
Avatar _avatar,
Identity _identity,
uint256 _claimAmount
) public FeelessScheme(_identity, _avatar) ActivePeriod(now, now * 2, _avatar) {
claimAmount = _claimAmount;
}
/* @dev Start function. Adds this contract to identity as a feeless scheme.
* Can only be called if scheme is registered.
*/
function start() public onlyRegistered {
addRights();
super.start();
}
/**
* @dev Sets the whitelisted ubi scheme. Only Avatar
* can call this method.
* @param _ubi The new ubi scheme to be whitelisted
*/
function setUBIScheme(address _ubi) public onlyAvatar {
ubi = _ubi;
}
/**
* @dev Sets the claim amount. Only Avatar
* can call this method.
* @param _claimAmount The new claim amount
*/
function setClaimAmount(uint256 _claimAmount) public onlyAvatar {
claimAmount = _claimAmount;
}
/**
* @dev Transfers claimAmount to the given account address.
* Only the whitelisted ubi scheme can call this method.
* @param _account Recieves the claimAmount
* @return (claimAmount) The amount that was transferred to the given _account
*/
function awardUser(address _account)
public
requireActive
ubiHasInitialized
onlyUBIScheme
returns (uint256)
{
DAOToken token = avatar.nativeToken();
uint256 balance = token.balanceOf(address(this));
if (balance >= claimAmount) {
require(token.transfer(_account, claimAmount), "award transfer failed");
return claimAmount;
}
return 0;
}
/**
* @dev making the contract inactive after it has transferred funds to `_avatar`
* Only the avatar can destroy the contract.
*/
function end() public onlyAvatar {
DAOToken token = avatar.nativeToken();
uint256 remainingGDReserve = token.balanceOf(address(this));
if (remainingGDReserve > 0) {
require(
token.transfer(address(avatar), remainingGDReserve),
"end transfer failed"
);
}
removeRights();
super.internalEnd(avatar);
}
}
// File: stakingModel/contracts/UBIScheme.sol
/* @title Dynamic amount-per-day UBI scheme allowing claim once a day
*/
contract UBIScheme is AbstractUBI {
using SafeMath for uint256;
// Result of distribution formula
// calculated each day
uint256 public dailyUbi;
// Limits the gas for each iteration at `fishMulti`
uint256 public iterationGasLimit = 150000;
// Tracks the active users number. It changes when
// a new user claim for the first time or when a user
// has been fished
uint256 public activeUsersCount;
// Tracks the last withdrawal day of funds from avatar.
// Withdraw occures on the first daily claim or the
// first daily fish only
uint256 public lastWithdrawDay;
// How long can a user be inactive.
// After those days the user can be fished
// (see `fish` notes)
uint256 public maxInactiveDays;
// Whether to withdraw GD from avatar
// before daily ubi calculation
bool public shouldWithdrawFromDAO;
//number of days of each UBI pool cycle
//dailyPool = Pool/cycleLength
uint256 public cycleLength;
//the amount of G$ UBI pool for each day in the cycle to be divided by active users
uint256 public dailyCyclePool;
//timestamp of current cycle start
uint256 public startOfCycle;
//should be 0 for starters so distributionFormula detects new cycle on first day claim
uint256 public currentCycleLength;
// A pool of GD to give to activated users,
// since they will enter the UBI pool
// calculations only in the next day,
// meaning they can only claim in the next
// day
FirstClaimPool public firstClaimPool;
struct Funds {
// marks if the funds for a specific day has
// withdrawn from avatar
bool hasWithdrawn;
// total GD held after withdrawing
uint256 openAmount;
}
// Tracks the daily withdraws and the actual amount
// at the begining of a trading day
mapping(uint256 => Funds) public dailyUBIHistory;
// Marks users that have been fished to avoid
// double fishing
mapping(address => bool) public fishedUsersAddresses;
// Total claims per user stat
mapping(address => uint256) public totalClaimsPerUser;
// Emits when a withdraw has been succeded
event WithdrawFromDao(uint256 prevBalance, uint256 newBalance);
// Emits when a user is activated
event ActivatedUser(address indexed account);
// Emits when a fish has been succeded
event InactiveUserFished(
address indexed caller,
address indexed fished_account,
uint256 claimAmount
);
// Emits when finishing a `multi fish` execution.
// Indicates the number of users from the given
// array who actually been fished. it might not
// be finished going over all the array if there
// no gas left.
event TotalFished(uint256 total);
// Emits when daily ubi is calculated
event UBICalculated(uint256 day, uint256 dailyUbi, uint256 blockNumber);
event UBICycleCalculated(
uint256 day,
uint256 pool,
uint256 cycleLength,
uint256 dailyUBIPool
);
modifier requireStarted() {
require(now >= periodStart, "not in periodStarted");
_;
}
/**
* @dev Constructor
* @param _avatar The avatar of the DAO
* @param _identity The identity contract
* @param _firstClaimPool A pool for GD to give out to activated users
* @param _periodStart The time from when the contract can start
* @param _periodEnd The time from when the contract can end
* @param _maxInactiveDays Days of grace without claiming request
*/
constructor(
Avatar _avatar,
Identity _identity,
FirstClaimPool _firstClaimPool,
uint256 _periodStart,
uint256 _periodEnd,
uint256 _maxInactiveDays,
uint256 _cycleLength
) public AbstractUBI(_avatar, _identity, 0, _periodStart, _periodEnd) {
require(_maxInactiveDays > 0, "Max inactive days cannot be zero");
maxInactiveDays = _maxInactiveDays;
firstClaimPool = _firstClaimPool;
shouldWithdrawFromDAO = false;
cycleLength = _cycleLength;
}
/**
* @dev On a daily basis UBIScheme withdraws tokens from GoodDao.
* Emits event with caller address and last day balance and the
* updated balance.
*/
function _withdrawFromDao() internal {
DAOToken token = avatar.nativeToken();
uint256 prevBalance = token.balanceOf(address(this));
uint256 toWithdraw = token.balanceOf(address(avatar));
controller.genericCall(
address(token),
abi.encodeWithSignature(
"transfer(address,uint256)",
address(this),
toWithdraw
),
avatar,
0
);
uint256 newBalance = prevBalance.add(toWithdraw);
require(
newBalance == token.balanceOf(address(this)),
"DAO transfer has failed"
);
emit WithdrawFromDao(prevBalance, newBalance);
}
/**
* @dev sets the ubi calculation cycle length
* @param _newLength the new length in days
*/
function setCycleLength(uint256 _newLength) public onlyAvatar {
require(_newLength > 0, "cycle must be at least 1 day long");
cycleLength = _newLength;
}
/**
* @dev returns the day count since start of current cycle
*/
function currentDayInCycle() public view returns (uint256) {
return now.sub(startOfCycle).div(1 days);
}
/**
* @dev The claim calculation formula. Divided the daily balance with
* the sum of the active users.
* @return The amount of GoodDollar the user can claim
*/
function distributionFormula(uint256 reserve, address user)
internal
returns (uint256)
{
setDay();
// on first day or once in 24 hrs calculate distribution
if (currentDay != lastWithdrawDay) {
DAOToken token = avatar.nativeToken();
uint256 currentBalance = token.balanceOf(address(this));
if (
currentDayInCycle() >= currentCycleLength
) //start of cycle or first time
{
if (shouldWithdrawFromDAO) _withdrawFromDao();
currentBalance = token.balanceOf(address(this));
dailyCyclePool = currentBalance.div(cycleLength);
currentCycleLength = cycleLength;
startOfCycle = now.div(1 hours) * 1 hours; //start at a round hour
emit UBICycleCalculated(
currentDay,
currentBalance,
cycleLength,
dailyCyclePool
);
}
lastWithdrawDay = currentDay;
Funds storage funds = dailyUBIHistory[currentDay];
funds.hasWithdrawn = shouldWithdrawFromDAO;
funds.openAmount = currentBalance;
if (activeUsersCount > 0) {
dailyUbi = dailyCyclePool.div(activeUsersCount);
}
emit UBICalculated(currentDay, dailyUbi, block.number);
}
return dailyUbi;
}
/**
*@dev Sets the currentDay variable to amount of days
* since start of contract.
*/
function setDay() public {
currentDay = (now.sub(periodStart)).div(1 days);
}
/**
* @dev Checks if the given account has claimed today
* @param account to check
* @return True if the given user has already claimed today
*/
function hasClaimed(address account) public view returns (bool) {
return claimDay[currentDay].hasClaimed[account];
}
/**
* @dev Checks if the given account has been owned by a registered user.
* @param _account to check
* @return True for an existing user. False for a new user
*/
function isNotNewUser(address _account) public view returns (bool) {
uint256 lastClaimed = lastClaimed[_account];
if (lastClaimed > 0) {
// the sender is not registered
return true;
}
return false;
}
/**
* @dev Checks weather the given address is owned by an active user.
* A registered user is a user that claimed at least one time. An
* active user is a user that claimed at least one time but claimed
* at least one time in the last `maxInactiveDays` days. A user that
* has not claimed for `maxInactiveDays` is an inactive user.
* @param _account to check
* @return True for active user
*/
function isActiveUser(address _account) public view returns (bool) {
uint256 lastClaimed = lastClaimed[_account];
if (isNotNewUser(_account)) {
uint256 daysSinceLastClaim = now.sub(lastClaimed).div(1 days);
if (daysSinceLastClaim < maxInactiveDays) {
// active user
return true;
}
}
return false;
}
/**
* @dev Transfers `amount` DAO tokens to `account`. Updates stats
* and emits an event in case of claimed.
* In case that `isFirstTime` is true, it awards the user.
* @param _account the account which recieves the funds
* @param _amount the amount to transfer
* @param _isClaimed true for claimed
* @param _isFirstTime true for new user or fished user
*/
function _transferTokens(
address _account,
uint256 _amount,
bool _isClaimed,
bool _isFirstTime
) internal {
// updates the stats
Day storage day = claimDay[currentDay];
day.amountOfClaimers = day.amountOfClaimers.add(1);
day.hasClaimed[_account] = true;
lastClaimed[_account] = now;
totalClaimsPerUser[_account].add(1);
// awards a new user or a fished user
if (_isFirstTime) {
uint256 awardAmount = firstClaimPool.awardUser(_account);
day.claimAmount = day.claimAmount.add(awardAmount);
emit UBIClaimed(_account, awardAmount);
} else {
day.claimAmount = day.claimAmount.add(_amount);
GoodDollar token = GoodDollar(address(avatar.nativeToken()));
require(token.transfer(_account, _amount), "claim transfer failed");
if (_isClaimed) {
emit UBIClaimed(_account, _amount);
}
}
}
/**
* @dev Checks the amount which the sender address is eligible to claim for,
* regardless if they have been whitelisted or not. In case the user is
* active, then the current day must be equal to the actual day, i.e. claim
* or fish has already been executed today.
* @return The amount of GD tokens the address can claim.
*/
function checkEntitlement() public view requireActive returns (uint256) {
// new user or inactive should recieve the first claim reward
if (!isNotNewUser(msg.sender) || fishedUsersAddresses[msg.sender]) {
return firstClaimPool.claimAmount();
}
// current day has already been updated which means
// that the dailyUbi has been updated
if (currentDay == (now.sub(periodStart)).div(1 days)) {
return hasClaimed(msg.sender) ? 0 : dailyUbi;
}
// the current day has not updated yet
DAOToken token = avatar.nativeToken();
uint256 currentBalance = token.balanceOf(address(this));
return currentBalance.div(activeUsersCount);
}
/**
* @dev Function for claiming UBI. Requires contract to be active. Calls distributionFormula,
* calculats the amount the account can claims, and transfers the amount to the account.
* Emits the address of account and amount claimed.
* @param _account The claimer account
* @return A bool indicating if UBI was claimed
*/
function _claim(address _account) internal returns (bool) {
// calculats the formula up today ie on day 0 there are no active users, on day 1 any user
// (new or active) will trigger the calculation with the active users count of the day before
// and so on. the new or inactive users that will become active today, will not take into account
// within the calculation.
uint256 newDistribution = distributionFormula(0, _account);
// active user which has not claimed today yet, ie user last claimed < today
if (
isNotNewUser(_account) &&
!fishedUsersAddresses[_account] &&
!hasClaimed(_account)
) {
_transferTokens(_account, newDistribution, true, false);
return true;
} else if (!isNotNewUser(_account) || fishedUsersAddresses[_account]) {
// a unregistered or fished user
activeUsersCount = activeUsersCount.add(1);
fishedUsersAddresses[_account] = false;
_transferTokens(_account, 0, false, true);
emit ActivatedUser(_account);
return true;
}
return false;
}
/**
* @dev Function for claiming UBI. Requires contract to be active and claimer to be whitelisted.
* Calls distributionFormula, calculats the amount the caller can claim, and transfers the amount
* to the caller. Emits the address of caller and amount claimed.
* @return A bool indicating if UBI was claimed
*/
function claim()
public
requireStarted
requireActive
onlyWhitelisted
returns (bool)
{
return _claim(msg.sender);
}
/**
* @dev In order to update users from active to inactive, we give out incentive to people
* to update the status of inactive users, this action is called "Fishing". Anyone can
* send a tx to the contract to mark inactive users. The "fisherman" receives a reward
* equal to the daily UBI (ie instead of the “fished” user). User that “last claimed” > 14
* can be "fished" and made inactive (reduces active users count by one). Requires
* contract to be active.
* @param _account to fish
* @return A bool indicating if UBI was fished
*/
function fish(address _account) public requireActive returns (bool) {
// checking if the account exists. that's been done because that
// will prevent trying to fish non-existence accounts in the system
require(
isNotNewUser(_account) && !isActiveUser(_account),
"is not an inactive user"
);
require(!fishedUsersAddresses[_account], "already fished");
fishedUsersAddresses[_account] = true; // marking the account as fished so it won't refish
// making sure that the calculation will be with the correct number of active users in case
// that the fisher is the first to make the calculation today
uint256 newDistribution = distributionFormula(0, _account);
activeUsersCount = activeUsersCount.sub(1);
_transferTokens(msg.sender, newDistribution, false, false);
emit InactiveUserFished(msg.sender, _account, newDistribution);
return true;
}
/**
* @dev executes `fish` with multiple addresses. emits the number of users from the given
* array who actually been tried being fished.
* @param _accounts to fish
* @return A bool indicating if all the UBIs were fished
*/
function fishMulti(address[] memory _accounts)
public
requireActive
returns (uint256)
{
for (uint256 i = 0; i < _accounts.length; ++i) {
if (gasleft() < iterationGasLimit) {
emit TotalFished(i);
return i;
}
if (
isNotNewUser(_accounts[i]) &&
!isActiveUser(_accounts[i]) &&
!fishedUsersAddresses[_accounts[i]]
) {
require(fish(_accounts[i]), "fish has failed");
}
}
emit TotalFished(_accounts.length);
return _accounts.length;
}
/**
* @dev Start function. Adds this contract to identity as a feeless scheme and
* adds permissions to FirstClaimPool
* Can only be called if scheme is registered
*/
function start() public onlyRegistered {
super.start();
periodStart = now.div(1 days) * 1 days + 12 hours; //set start time to GMT noon
startOfCycle = periodStart;
controller.genericCall(
address(firstClaimPool),
abi.encodeWithSignature("setUBIScheme(address)", address(this)),
avatar,
0
);
}
/**
* @dev Sets whether to also withdraw GD from avatar for UBI
* @param _shouldWithdraw boolean if to withdraw
*/
function setShouldWithdrawFromDAO(bool _shouldWithdraw) public onlyAvatar {
shouldWithdrawFromDAO = _shouldWithdraw;
}
function end() public onlyAvatar {
super.end();
}
function upgrade(address prevUBIScheme) public onlyRegistered {
start();
if (prevUBIScheme != address(0)) {
GoodDollar gd = GoodDollar(address(avatar.nativeToken()));
uint256 ubiBalance = gd.balanceOf(prevUBIScheme);
// transfer funds from old scheme here
controller.genericCall(
prevUBIScheme,
abi.encodeWithSignature("end()"),
avatar,
0
);
controller.genericCall(
address(firstClaimPool),
abi.encodeWithSignature("setClaimAmount(uint256)", 1000),
avatar,
0
);
if (ubiBalance > 0) {
controller.externalTokenTransfer(
gd,
address(this),
ubiBalance,
avatar
);
}
}
}
}

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","payable":false,"inputs":[{"type":"address","name":"_avatar","internalType":"contract Avatar"},{"type":"address","name":"_identity","internalType":"contract Identity"},{"type":"address","name":"_firstClaimPool","internalType":"contract FirstClaimPool"},{"type":"uint256","name":"_periodStart","internalType":"uint256"},{"type":"uint256","name":"_periodEnd","internalType":"uint256"},{"type":"uint256","name":"_maxInactiveDays","internalType":"uint256"},{"type":"uint256","name":"_cycleLength","internalType":"uint256"}]},{"type":"event","name":"ActivatedUser","inputs":[{"type":"address","name":"account","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"InactiveUserFished","inputs":[{"type":"address","name":"caller","internalType":"address","indexed":true},{"type":"address","name":"fished_account","internalType":"address","indexed":true},{"type":"uint256","name":"claimAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"SchemeEnded","inputs":[{"type":"address","name":"by","internalType":"address","indexed":true},{"type":"uint256","name":"time","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"SchemeStarted","inputs":[{"type":"address","name":"by","internalType":"address","indexed":true},{"type":"uint256","name":"time","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TotalFished","inputs":[{"type":"uint256","name":"total","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UBICalculated","inputs":[{"type":"uint256","name":"day","internalType":"uint256","indexed":false},{"type":"uint256","name":"dailyUbi","internalType":"uint256","indexed":false},{"type":"uint256","name":"blockNumber","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UBIClaimed","inputs":[{"type":"address","name":"claimer","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UBICycleCalculated","inputs":[{"type":"uint256","name":"day","internalType":"uint256","indexed":false},{"type":"uint256","name":"pool","internalType":"uint256","indexed":false},{"type":"uint256","name":"cycleLength","internalType":"uint256","indexed":false},{"type":"uint256","name":"dailyUBIPool","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UBIEnded","inputs":[{"type":"uint256","name":"claimers","internalType":"uint256","indexed":false},{"type":"uint256","name":"claimamount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UBIStarted","inputs":[{"type":"uint256","name":"balance","internalType":"uint256","indexed":false},{"type":"uint256","name":"time","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"WithdrawFromDao","inputs":[{"type":"uint256","name":"prevBalance","internalType":"uint256","indexed":false},{"type":"uint256","name":"newBalance","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"activeUsersCount","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"checkEntitlement","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"claim","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"claimDistribution","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"currentCycleLength","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"currentDay","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"currentDayInCycle","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"cycleLength","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"dailyCyclePool","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"hasWithdrawn","internalType":"bool"},{"type":"uint256","name":"openAmount","internalType":"uint256"}],"name":"dailyUBIHistory","inputs":[{"type":"uint256","name":"","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"dailyUbi","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"end","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract FirstClaimPool"}],"name":"firstClaimPool","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"fish","inputs":[{"type":"address","name":"_account","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"fishMulti","inputs":[{"type":"address[]","name":"_accounts","internalType":"address[]"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"fishedUsersAddresses","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getClaimAmount","inputs":[{"type":"uint256","name":"day","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getClaimerCount","inputs":[{"type":"uint256","name":"day","internalType":"uint256"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"count","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}],"name":"getDailyStats","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasClaimed","inputs":[{"type":"address","name":"account","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract Identity"}],"name":"identity","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isActive","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isActiveUser","inputs":[{"type":"address","name":"_account","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isNotNewUser","inputs":[{"type":"address","name":"_account","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isOwner","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isRegistered","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isRegistered","inputs":[{"type":"address","name":"scheme","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"iterationGasLimit","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastClaimed","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastWithdrawDay","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxInactiveDays","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"periodEnd","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"periodStart","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"renounceOwnership","inputs":[],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setAvatar","inputs":[{"type":"address","name":"_avatar","internalType":"contract Avatar"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setCycleLength","inputs":[{"type":"uint256","name":"_newLength","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setDay","inputs":[],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setIdentity","inputs":[{"type":"address","name":"_identity","internalType":"contract Identity"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"setShouldWithdrawFromDAO","inputs":[{"type":"bool","name":"_shouldWithdraw","internalType":"bool"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"shouldWithdrawFromDAO","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"start","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"startOfCycle","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalClaimsPerUser","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"upgrade","inputs":[{"type":"address","name":"prevUBIScheme","internalType":"address"}],"constant":false}]
            

Deployed ByteCode

0x608060405234801561001057600080fd5b506004361061028a5760003560e01c80638081cbbd1161015c578063c1337508116100ce578063dddc361611610087578063dddc36161461067e578063de1de3a014610686578063eac471a0146106a5578063eda4e6d6146106ad578063efbe1c1c146106b5578063f2fde38b146106bd5761028a565b8063c13375081461054f578063c3c5a547146105f0578063c7a76adf14610616578063cc054dfc14610633578063cef6360014610659578063d7c4cbb8146106765761028a565b80639dc2c033116101205780639dc2c03314610501578063a21f698a14610509578063b656223d1461052f578063ba07541014610537578063be9a65551461053f578063c033abf2146105475761028a565b80638081cbbd146104d9578063884a41be146104e15780638da5cb5b146104e95780638f32d59b146104f157806398d6621b146104f95761028a565b80633d84ceca11610200578063560796d1116101b9578063560796d11461043d5780635c9302c9146104755780635d5bf1781461047d578063715018a6146104a357806373b2e80e146104ab578063741470ac146104d15761028a565b80633d84ceca146103bc5780634202d214146103d9578063456ac1c2146103ff5780634e71d92d14610407578063506ec0951461040f5780635231e2f0146104175761028a565b80631bbc644c116102525780631bbc644c1461033e5780631d8f5ea914610378578063223668441461038057806322b457271461038857806322f3e2d4146103905780632c159a1a146103985761028a565b8063013eba921461028f578063069786ea146102c7578063086cfca8146102e85780630900f010146103105780630ce82d6714610336575b600080fd5b6102b5600480360360208110156102a557600080fd5b50356001600160a01b03166106e3565b60408051918252519081900360200190f35b6102cf6106f5565b6040805192835260208301919091528051918290030190f35b61030e600480360360208110156102fe57600080fd5b50356001600160a01b0316610738565b005b61030e6004803603602081101561032657600080fd5b50356001600160a01b03166107ef565b6102b5610dd1565b6103646004803603602081101561035457600080fd5b50356001600160a01b0316610e01565b604080519115158252519081900360200190f35b6102b5610fb5565b610364610fbb565b6102b5610fc6565b610364610fcc565b6103a0610fd5565b604080516001600160a01b039092168252519081900360200190f35b61030e600480360360208110156103d257600080fd5b5035610fe4565b610364600480360360208110156103ef57600080fd5b50356001600160a01b0316611087565b6103646110e9565b6103646110f2565b6102b561124e565b6103646004803603602081101561042d57600080fd5b50356001600160a01b0316611254565b61045a6004803603602081101561045357600080fd5b5035611269565b60408051921515835260208301919091528051918290030190f35b6102b5611288565b61030e6004803603602081101561049357600080fd5b50356001600160a01b031661128e565b61030e611377565b610364600480360360208110156104c157600080fd5b50356001600160a01b03166113d2565b6102b56113ff565b6103a0611405565b6102b5611414565b6103a061141a565b610364611429565b6102b561143a565b6102b5611684565b6103646004803603602081101561051f57600080fd5b50356001600160a01b031661168a565b6102b56116b3565b6102b56116b9565b61030e6116bf565b6102b5611935565b6102b56004803603602081101561056557600080fd5b810190602081018135600160201b81111561057f57600080fd5b82018360208201111561059157600080fd5b803590602001918460208302840111600160201b831117156105b257600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955061193b945050505050565b6103646004803603602081101561060657600080fd5b50356001600160a01b0316611afc565b6102b56004803603602081101561062c57600080fd5b5035611bea565b6102b56004803603602081101561064957600080fd5b50356001600160a01b0316611bff565b6102b56004803603602081101561066f57600080fd5b5035611c11565b6102b5611c26565b61030e611c2c565b61030e6004803603602081101561069c57600080fd5b50351515611c4d565b6102b5611cbf565b6102b5611cc5565b61030e611ccb565b61030e600480360360208110156106d357600080fd5b50356001600160a01b0316611d34565b600a6020526000908152604090205481565b60008060006201518061071360005442611d4e90919063ffffffff16565b8161071a57fe5b04905061072681611bea565b61072f82611c11565b92509250509091565b610740611429565b61074957600080fd5b600480546001600160a01b0319166001600160a01b038381169190911780835560408051638da5cb5b60e01b815290519190921692638da5cb5b92808201926020929091829003018186803b1580156107a157600080fd5b505afa1580156107b5573d6000803e3d6000fd5b505050506040513d60208110156107cb57600080fd5b5051600580546001600160a01b0319166001600160a01b0390921691909117905550565b6107f7610fbb565b610836576040805162461bcd60e51b8152602060048201526018602482015260008051602061356d833981519152604482015290519081900360640190fd5b61083e6116bf565b6001600160a01b03811615610dce576000600460009054906101000a90046001600160a01b03166001600160a01b031663e1758bd86040518163ffffffff1660e01b815260040160206040518083038186803b15801561089d57600080fd5b505afa1580156108b1573d6000803e3d6000fd5b505050506040513d60208110156108c757600080fd5b5051604080516370a0823160e01b81526001600160a01b0385811660048301529151929350600092918416916370a0823191602480820192602092909190829003018186803b15801561091957600080fd5b505afa15801561092d573d6000803e3d6000fd5b505050506040513d602081101561094357600080fd5b5051600554604080516004808252602480830184526020830180516001600160e01b0316633bef870760e21b178152825494516368db844d60e11b81526001600160a01b038b8116948201948552958616604482018190526000606483018190526080948301948552865160848401528651999a50969097169763d1b7089a978c97909590949093909260a40191808383885b838110156109ee5781810151838201526020016109d6565b50505050905090810190601f168015610a1b5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015610a3d57600080fd5b505af1158015610a51573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040908152811015610a7a57600080fd5b815160208301805160405192949293830192919084600160201b821115610aa057600080fd5b908301906020820185811115610ab557600080fd5b8251600160201b811182820188101715610ace57600080fd5b82525081516020918201929091019080838360005b83811015610afb578181015183820152602001610ae3565b50505050905090810190601f168015610b285780820380516001836020036101000a031916815260200191505b5060408181526005546016546103e8602480860191909152835180860382018152604495860185526020810180516001600160e01b0316632c71fbc360e21b1781526004805496516368db844d60e11b81526001600160a01b039586169181018281529786169881018990526000606482018190526080958201958652845160848301528451969097169d5063d1b7089a9c50909a509198509596509294909260a40191808383885b83811015610be9578181015183820152602001610bd1565b50505050905090810190601f168015610c165780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015610c3857600080fd5b505af1158015610c4c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040908152811015610c7557600080fd5b815160208301805160405192949293830192919084600160201b821115610c9b57600080fd5b908301906020820185811115610cb057600080fd5b8251600160201b811182820188101715610cc957600080fd5b82525081516020918201929091019080838360005b83811015610cf6578181015183820152602001610cde565b50505050905090810190601f168015610d235780820380516001836020036101000a031916815260200191505b5060405250505050506000811115610dcb57600554600480546040805163b9a04cdd60e01b81526001600160a01b038781169482019490945230602482015260448101869052918316606483015251919092169163b9a04cdd9160848083019260209291908290030181600087803b158015610d9e57600080fd5b505af1158015610db2573d6000803e3d6000fd5b505050506040513d6020811015610dc857600080fd5b50505b50505b50565b6000610dfb62015180610def60145442611d4e90919063ffffffff16565b9063ffffffff611d6316565b90505b90565b60025460009060ff16610e4b576040805162461bcd60e51b815260206004820152600d60248201526c6973206e6f742061637469766560981b604482015290519081900360640190fd5b610e548261168a565b8015610e665750610e6482611087565b155b610eb7576040805162461bcd60e51b815260206004820152601760248201527f6973206e6f7420616e20696e6163746976652075736572000000000000000000604482015290519081900360640190fd5b6001600160a01b03821660009081526018602052604090205460ff1615610f16576040805162461bcd60e51b815260206004820152600e60248201526d185b1c9958591e48199a5cda195960921b604482015290519081900360640190fd5b6001600160a01b0382166000908152601860205260408120805460ff19166001179055610f438184611d85565b600e54909150610f5a90600163ffffffff611d4e16565b600e55610f6a3382600080612052565b6040805182815290516001600160a01b0385169133917f3c91d315d82534112f8ce552cb79133a14191077a2d715fd65cabd026fc27c749181900360200190a360019150505b919050565b600c5481565b6000610dfb30611afc565b600e5481565b60025460ff1681565b6006546001600160a01b031681565b6004546001600160a01b03163314611043576040805162461bcd60e51b815260206004820181905260248201527f6f6e6c79204176617461722063616e2063616c6c2074686973206d6574686f64604482015290519081900360640190fd5b600081116110825760405162461bcd60e51b815260040180806020018281038252602181526020018061358d6021913960400191505060405180910390fd5b601255565b6001600160a01b0381166000908152600a60205260408120546110a98361168a565b156110e05760006110c762015180610def428563ffffffff611d4e16565b90506010548110156110de57600192505050610fb0565b505b50600092915050565b60115460ff1681565b60008054421015611141576040805162461bcd60e51b81526020600482015260146024820152731b9bdd081a5b881c195c9a5bd914dd185c9d195960621b604482015290519081900360640190fd5b60025460ff16611188576040805162461bcd60e51b815260206004820152600d60248201526c6973206e6f742061637469766560981b604482015290519081900360640190fd5b60065460408051633af32abf60e01b815233600482015290516001600160a01b0390921691633af32abf91602480820192602092909190829003018186803b1580156111d357600080fd5b505afa1580156111e7573d6000803e3d6000fd5b505050506040513d60208110156111fd57600080fd5b5051611245576040805162461bcd60e51b81526020600482015260126024820152711a5cc81b9bdd081dda1a5d195b1a5cdd195960721b604482015290519081900360640190fd5b610dfb33612351565b60015481565b60186020526000908152604090205460ff1681565b6017602052600090815260409020805460019091015460ff9091169082565b600b5481565b611296611429565b61129f57600080fd5b806001600160a01b031663223668446040518163ffffffff1660e01b815260040160206040518083038186803b1580156112d857600080fd5b505afa1580156112ec573d6000803e3d6000fd5b505050506040513d602081101561130257600080fd5b5051611355576040805162461bcd60e51b815260206004820152601a60248201527f4964656e74697479206973206e6f742072656769737465726564000000000000604482015290519081900360640190fd5b600680546001600160a01b0319166001600160a01b0392909216919091179055565b61137f611429565b61138857600080fd5b6003546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600380546001600160a01b0319169055565b600b5460009081526009602090815260408083206001600160a01b03949094168352929052205460ff1690565b60155481565b6016546001600160a01b031681565b60085481565b6003546001600160a01b031690565b6003546001600160a01b0316331490565b60025460009060ff16611484576040805162461bcd60e51b815260206004820152600d60248201526c6973206e6f742061637469766560981b604482015290519081900360640190fd5b61148d3361168a565b15806114a857503360009081526018602052604090205460ff165b1561152e57601660009054906101000a90046001600160a01b03166001600160a01b031663830953ab6040518163ffffffff1660e01b815260040160206040518083038186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b50519050610dfe565b61154a62015180610def60005442611d4e90919063ffffffff16565b600b5414156115725761155c336113d2565b61156857600c5461156b565b60005b9050610dfe565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663e1758bd86040518163ffffffff1660e01b815260040160206040518083038186803b1580156115c257600080fd5b505afa1580156115d6573d6000803e3d6000fd5b505050506040513d60208110156115ec57600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561163a57600080fd5b505afa15801561164e573d6000803e3d6000fd5b505050506040513d602081101561166457600080fd5b5051600e5490915061167d90829063ffffffff611d6316565b9250505090565b60135481565b6001600160a01b0381166000908152600a602052604081205480156110e0576001915050610fb0565b60105481565b60145481565b6116c7610fbb565b611706576040805162461bcd60e51b8152602060048201526018602482015260008051602061356d833981519152604482015290519081900360640190fd5b61170e612473565b611721426201518063ffffffff611d6316565b620151800261a8c0016000818155601491909155600554601654604080513060248083019190915282518083038201815260449283018452602081018051631619b41160e11b6001600160e01b039091161781526004805495516368db844d60e11b81526001600160a01b03978816918101828152968816958101869052606481018a90526080948101948552835160848201528351979098169863d1b7089a989197939690949093909260a49092019190808383885b838110156117f05781810151838201526020016117d8565b50505050905090810190601f16801561181d5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561183f57600080fd5b505af1158015611853573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604090815281101561187c57600080fd5b815160208301805160405192949293830192919084600160201b8211156118a257600080fd5b9083019060208201858111156118b757600080fd5b8251600160201b8111828201881017156118d057600080fd5b82525081516020918201929091019080838360005b838110156118fd5781810151838201526020016118e5565b50505050905090810190601f16801561192a5780820380516001836020036101000a031916815260200191505b506040525050505050565b600d5481565b60025460009060ff16611985576040805162461bcd60e51b815260206004820152600d60248201526c6973206e6f742061637469766560981b604482015290519081900360640190fd5b60005b8251811015611ac257600d545a10156119d5576040805182815290517f72b174db45b7e58932cb0c6bf37a7158f40424a078b07677d823cafdb3db540f9181900360200190a19050610fb0565b6119f18382815181106119e457fe5b602002602001015161168a565b8015611a165750611a14838281518110611a0757fe5b6020026020010151611087565b155b8015611a56575060186000848381518110611a2d57fe5b6020908102919091018101516001600160a01b031682528101919091526040016000205460ff16155b15611aba57611a77838281518110611a6a57fe5b6020026020010151610e01565b611aba576040805162461bcd60e51b815260206004820152600f60248201526e199a5cda081a185cc819985a5b1959608a1b604482015290519081900360640190fd5b600101611988565b50815160408051918252517f72b174db45b7e58932cb0c6bf37a7158f40424a078b07677d823cafdb3db540f9181900360200190a1505190565b6004546000906001600160a01b0316611b50576040805162461bcd60e51b8152602060048201526011602482015270105d985d185c881a5cc81b9bdd081cd95d607a1b604482015290519081900360640190fd5b6005546004805460408051639be2faed60e01b81526001600160a01b03878116948201949094529183166024830152519190921691639be2faed916044808301926020929190829003018186803b158015611baa57600080fd5b505afa158015611bbe573d6000803e3d6000fd5b505050506040513d6020811015611bd457600080fd5b5051611be257506000610fb0565b506001919050565b60009081526009602052604090206001015490565b60196020526000908152604090205481565b60009081526009602052604090206002015490565b600f5481565b611c4862015180610def60005442611d4e90919063ffffffff16565b600b55565b6004546001600160a01b03163314611cac576040805162461bcd60e51b815260206004820181905260248201527f6f6e6c79204176617461722063616e2063616c6c2074686973206d6574686f64604482015290519081900360640190fd5b6011805460ff1916911515919091179055565b60125481565b60005481565b6004546001600160a01b03163314611d2a576040805162461bcd60e51b815260206004820181905260248201527f6f6e6c79204176617461722063616e2063616c6c2074686973206d6574686f64604482015290519081900360640190fd5b611d326128f1565b565b611d3c611429565b611d4557600080fd5b610dce81612b19565b600082821115611d5d57600080fd5b50900390565b6000808211611d7157600080fd5b6000828481611d7c57fe5b04949350505050565b6000611d8f611c2c565b600f54600b5414612048576000600460009054906101000a90046001600160a01b03166001600160a01b031663e1758bd86040518163ffffffff1660e01b815260040160206040518083038186803b158015611dea57600080fd5b505afa158015611dfe573d6000803e3d6000fd5b505050506040513d6020811015611e1457600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038416916370a08231916024808301926020929190829003018186803b158015611e6257600080fd5b505afa158015611e76573d6000803e3d6000fd5b505050506040513d6020811015611e8c57600080fd5b5051601554909150611e9c610dd1565b10611fae5760115460ff1615611eb457611eb4612b88565b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b158015611efa57600080fd5b505afa158015611f0e573d6000803e3d6000fd5b505050506040513d6020811015611f2457600080fd5b5051601254909150611f3d90829063ffffffff611d6316565b601355601254601555611f5842610e1063ffffffff611d6316565b610e1002601455600b546012546013546040805193845260208401859052838101929092526060830152517f83e0d535b9e84324e0a25922406398d6ff5f96d0c686204ee490e16d7670566f9181900360800190a15b600b54600f8190556000908152601760205260409020601154815460ff191660ff909116151517815560018101829055600e5415611fff57600e54601354611ffb9163ffffffff611d6316565b600c555b600b54600c546040805192835260208301919091524382820152517f836fa39995340265746dfe9587d9fe5c5de35b7bce778afd9b124ce1cfeafdc49181900360600190a15050505b50600c5492915050565b600b5460009081526009602052604090206001808201546120789163ffffffff61301f16565b6001808301919091556001600160a01b038616600090815260208381526040808320805460ff191685179055600a825280832042905560199091529020546120c59163ffffffff61301f16565b5081156121ac5760165460408051636bf2228d60e11b81526001600160a01b0388811660048301529151600093929092169163d7e4451a9160248082019260209290919082900301818787803b15801561211e57600080fd5b505af1158015612132573d6000803e3d6000fd5b505050506040513d602081101561214857600080fd5b50516002830154909150612162908263ffffffff61301f16565b60028301556040805182815290516001600160a01b038816917f89ed24731df6b066e4c5186901fffdba18cd9a10f07494aff900bdee260d1304919081900360200190a250610dc8565b60028101546121c1908563ffffffff61301f16565b60028201556004805460408051631c2eb17b60e31b815290516000936001600160a01b039093169263e1758bd892808201926020929091829003018186803b15801561220c57600080fd5b505afa158015612220573d6000803e3d6000fd5b505050506040513d602081101561223657600080fd5b50516040805163a9059cbb60e01b81526001600160a01b0389811660048301526024820189905291519293509083169163a9059cbb916044808201926020929091908290030181600087803b15801561228e57600080fd5b505af11580156122a2573d6000803e3d6000fd5b505050506040513d60208110156122b857600080fd5b5051612303576040805162461bcd60e51b815260206004820152601560248201527418db185a5b481d1c985b9cd9995c8819985a5b1959605a1b604482015290519081900360640190fd5b8315612349576040805186815290516001600160a01b038816917f89ed24731df6b066e4c5186901fffdba18cd9a10f07494aff900bdee260d1304919081900360200190a25b505050505050565b60008061235f600084611d85565b905061236a8361168a565b801561238f57506001600160a01b03831660009081526018602052604090205460ff16155b80156123a1575061239f836113d2565b155b156123be576123b4838260016000612052565b6001915050610fb0565b6123c78361168a565b15806123eb57506001600160a01b03831660009081526018602052604090205460ff165b156110e057600e5461240490600163ffffffff61301f16565b600e556001600160a01b0383166000908152601860205260408120805460ff19169055612435908490806001612052565b6040516001600160a01b038416907f2f9cfaa2a5c422dfab45f7d0da071f030fc2d3a7a1f0a255c028eff9b6d3d93690600090a26001915050610fb0565b61247b610fbb565b6124ba576040805162461bcd60e51b8152602060048201526018602482015260008051602061356d833981519152604482015290519081900360640190fd5b6124c2613038565b6124ca61311e565b620151806124e360005442611d4e90919063ffffffff16565b816124ea57fe5b04600b556004805460408051631c2eb17b60e31b815290516000936001600160a01b039093169263e1758bd892808201926020929091829003018186803b15801561253457600080fd5b505afa158015612548573d6000803e3d6000fd5b505050506040513d602081101561255e57600080fd5b5051600754909150156128435760048054604080516370a0823160e01b81526001600160a01b039283169381019390935251908316916370a08231916024808301926020929190829003018186803b1580156125b957600080fd5b505afa1580156125cd573d6000803e3d6000fd5b505050506040513d60208110156125e357600080fd5b5051600754111561263b576040805162461bcd60e51b815260206004820152601960248201527f4e6f7420656e6f7567682066756e647320746f20737461727400000000000000604482015290519081900360640190fd5b6005546007546040805130602480830191909152604480830194909452825180830385018152606492830184526020810180516001600160e01b031663a9059cbb60e01b1781526004805495516368db844d60e11b81526001600160a01b038a811692820192835296871697810188905260009581018690526080948101948552835160848201528351969098169763d1b7089a978a979496909590949293909260a490920191808383885b838110156126ff5781810151838201526020016126e7565b50505050905090810190601f16801561272c5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561274e57600080fd5b505af1158015612762573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604090815281101561278b57600080fd5b815160208301805160405192949293830192919084600160201b8211156127b157600080fd5b9083019060208201858111156127c657600080fd5b8251600160201b8111828201881017156127df57600080fd5b82525081516020918201929091019080838360005b8381101561280c5781810151838201526020016127f4565b50505050905090810190601f1680156128395780820380516001836020036101000a031916815260200191505b5060405250505050505b604080516370a0823160e01b815230600482015290517faaf5e5cfa7e44b7c9cfc845d0cc96adc1c5a4c802d3572523f740424a3ce4fb2916001600160a01b038416916370a0823191602480820192602092909190829003018186803b1580156128ac57600080fd5b505afa1580156128c0573d6000803e3d6000fd5b505050506040513d60208110156128d657600080fd5b5051604080519182524260208301528051918290030190a150565b60015442101561293f576040805162461bcd60e51b81526020600482015260146024820152731c195c9a5bd9081a185cc81b9bdd08195b99195960621b604482015290519081900360640190fd5b6000600460009054906101000a90046001600160a01b03166001600160a01b031663e1758bd86040518163ffffffff1660e01b815260040160206040518083038186803b15801561298f57600080fd5b505afa1580156129a3573d6000803e3d6000fd5b505050506040513d60208110156129b957600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038416916370a08231916024808301926020929190829003018186803b158015612a0757600080fd5b505afa158015612a1b573d6000803e3d6000fd5b505050506040513d6020811015612a3157600080fd5b505190508015612b0557600480546040805163a9059cbb60e01b81526001600160a01b039283169381019390935260248301849052519084169163a9059cbb9160448083019260209291908290030181600087803b158015612a9257600080fd5b505af1158015612aa6573d6000803e3d6000fd5b505050506040513d6020811015612abc57600080fd5b5051612b05576040805162461bcd60e51b8152602060048201526013602482015272195b99081d1c985b9cd9995c8819985a5b1959606a1b604482015290519081900360640190fd5b612b0d613379565b612b15613479565b5050565b6001600160a01b038116612b2c57600080fd5b6003546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663e1758bd86040518163ffffffff1660e01b815260040160206040518083038186803b158015612bd857600080fd5b505afa158015612bec573d6000803e3d6000fd5b505050506040513d6020811015612c0257600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038416916370a08231916024808301926020929190829003018186803b158015612c5057600080fd5b505afa158015612c64573d6000803e3d6000fd5b505050506040513d6020811015612c7a57600080fd5b505160048054604080516370a0823160e01b81526001600160a01b039283169381019390935251929350600092908516916370a08231916024808301926020929190829003018186803b158015612cd057600080fd5b505afa158015612ce4573d6000803e3d6000fd5b505050506040513d6020811015612cfa57600080fd5b505160055460408051306024808301919091526044808301869052835180840382018152606493840185526020810180516001600160e01b031663a9059cbb60e01b1781526004805496516368db844d60e11b81526001600160a01b038d811692820192835297881694810185905260009681018790526080958101958652835160848201528351999a50969097169763d1b7089a978c97939694959093909260a490910191808383885b83811015612dbd578181015183820152602001612da5565b50505050905090810190601f168015612dea5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b158015612e0c57600080fd5b505af1158015612e20573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040908152811015612e4957600080fd5b815160208301805160405192949293830192919084600160201b821115612e6f57600080fd5b908301906020820185811115612e8457600080fd5b8251600160201b811182820188101715612e9d57600080fd5b82525081516020918201929091019080838360005b83811015612eca578181015183820152602001612eb2565b50505050905090810190601f168015612ef75780820380516001836020036101000a031916815260200191505b5060405250505050506000612f15828461301f90919063ffffffff16565b604080516370a0823160e01b815230600482015290519192506001600160a01b038616916370a0823191602480820192602092909190829003018186803b158015612f5f57600080fd5b505afa158015612f73573d6000803e3d6000fd5b505050506040513d6020811015612f8957600080fd5b50518114612fde576040805162461bcd60e51b815260206004820152601760248201527f44414f207472616e7366657220686173206661696c6564000000000000000000604482015290519081900360640190fd5b604080518481526020810183905281517f3107ec7eaa50b775d2486c7a394472235804b6fe1c0d4b7bd1d79b09df60f2ba929181900390910190a150505050565b60008282018381101561303157600080fd5b9392505050565b600054421015801561304b575060015442105b61308c576040805162461bcd60e51b815260206004820152600d60248201526c1b9bdd081a5b881c195c9a5bd9609a1b604482015290519081900360640190fd5b60025460ff16156130d9576040805162461bcd60e51b815260206004820152601260248201527163616e6e6f7420737461727420747769636560701b604482015290519081900360640190fd5b6002805460ff1916600117905560408051428152905133917f727dd98701807c5fdf715b9f1fd7d87461a558e2ab3e05935add76e42e330fa3919081900360200190a2565b613126610fbb565b613165576040805162461bcd60e51b8152602060048201526018602482015260008051602061356d833981519152604482015290519081900360640190fd5b6005546006546040805130602480830191909152825180830382018152604492830184526020810180516001600160e01b0316635f539d6960e01b1781526004805495516368db844d60e11b81526001600160a01b039788169181018281529688169581018690526000606482018190526080958201958652845160848301528451989099169863d1b7089a989297949695909493909260a490920191808383885b8381101561321f578181015183820152602001613207565b50505050905090810190601f16801561324c5780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801561326e57600080fd5b505af1158015613282573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160409081528110156132ab57600080fd5b815160208301805160405192949293830192919084600160201b8211156132d157600080fd5b9083019060208201858111156132e657600080fd5b8251600160201b8111828201881017156132ff57600080fd5b82525081516020918201929091019080838360005b8381101561332c578181015183820152602001613314565b50505050905090810190601f1680156133595780820380516001836020036101000a031916815260200191505b506040525050600454611d3293506001600160a01b03169150611d349050565b613381610fbb565b6133c0576040805162461bcd60e51b8152602060048201526018602482015260008051602061356d833981519152604482015290519081900360640190fd5b6005546006546040805130602480830191909152825180830382018152604492830184526020810180516001600160e01b031663c375c2ef60e01b1781526004805495516368db844d60e11b81526001600160a01b039788169181018281529688169581018690526000606482018190526080958201958652845160848301528451989099169863d1b7089a989297949695909493909260a49092019180838388838110156117f05781810151838201526020016117d8565b6001544210156134c7576040805162461bcd60e51b81526020600482015260146024820152731c195c9a5bd9081a185cc81b9bdd08195b99195960621b604482015290519081900360640190fd5b600254611d32906001600160a01b036101008204169060ff16613521576040805162461bcd60e51b815260206004820152600d60248201526c6973206e6f742061637469766560981b604482015290519081900360640190fd5b6002805460ff1916905560408051428152905133917ef689ee9beb942c1c9c0d6642687ace05a9000d5f2979d344163c57829fa779919081900360200190a2806001600160a01b0316fffe536368656d65206973206e6f74207265676973746572656400000000000000006379636c65206d757374206265206174206c65617374203120646179206c6f6e67a265627a7a72315820d0b246690184b3a6a5f4cc518cfdbd344c09fecbde906cc790e1023363222fda64736f6c63430005100032