GithubHelp home page GithubHelp logo

Christian juru's Projects

auto-gpt icon auto-gpt

An experimental open-source attempt to make GPT-4 fully autonomous.

awesome-makerdao icon awesome-makerdao

A collection of tools, documents, articles, blog posts, interviews, and videos related to MakerDAO and the Dai stablecoin.

blockchain-devkit icon blockchain-devkit

Samples of how to integrate, connect and use devops to interact with Azure blockchain

create-hq20-dapp icon create-hq20-dapp

:herb: This is the TechHQ dapp starter kit :octocat: All you need in a nut:shell:

dappsys icon dappsys

Composable building blocks for Ethereum contracts

developerguides icon developerguides

Developer guides to integrate with MakerDAO's smart contracts, SDKs, APIs, products, and partners

dipfab icon dipfab

Contrat intelligent "auteur.sol" d'entraînement. Ce contrat est un contrat d'entrainement qui permet aux juristes de comprendre la structure d'un contrat intelligent et la notion de fonction. Il n'est strictement pas développé pour une utilisation en production. Amusez-vous bien !

dss icon dss

Dai Stablecoin System

erc1400 icon erc1400

Implementation of ERC1400 Smart Contract standard for Security Tokens (STO)

erc20 icon erc20

/** *Submitted for verification at Etherscan.io on 2019-08-18 */ // File: openzeppelin-solidity/contracts/math/SafeMath.sol pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot 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, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } } // File: openzeppelin-solidity/contracts/token/ERC20/IERC20.sol pragma solidity ^0.5.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > 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 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol pragma solidity ^0.5.0; /** * @dev Optional functions from the ERC20 standard. */ contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of * these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. * * > Note that this information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * `IERC20.balanceOf` and `IERC20.transfer`. */ function decimals() public view returns (uint8) { return _decimals; } } // File: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol pragma solidity ^0.5.0; /** * @dev Implementation of the `IERC20` interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using `_mint`. * For a generic mechanism see `ERC20Mintable`. * * *For a detailed writeup see our guide [How to implement supply * mechanisms](https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226).* * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an `Approval` event is emitted on calls to `transferFrom`. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard `decreaseAllowance` and `increaseAllowance` * functions have been added to mitigate the well-known issues around setting * allowances. See `IERC20.approve`. */ contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; /** * @dev See `IERC20.totalSupply`. */ function totalSupply() public view returns (uint256) { return _totalSupply; } /** * @dev See `IERC20.balanceOf`. */ function balanceOf(address account) public view returns (uint256) { return _balances[account]; } /** * @dev See `IERC20.transfer`. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(msg.sender, recipient, amount); return true; } /** * @dev See `IERC20.allowance`. */ function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } /** * @dev See `IERC20.approve`. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 value) public returns (bool) { _approve(msg.sender, spender, value); return true; } /** * @dev See `IERC20.transferFrom`. * * Emits an `Approval` event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of `ERC20`; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `value`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { _transfer(sender, recipient, amount); _approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount)); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to `approve` that can be used as a mitigation for * problems described in `IERC20.approve`. * * Emits an `Approval` event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { _approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to `approve` that can be used as a mitigation for * problems described in `IERC20.approve`. * * Emits an `Approval` event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { _approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue)); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to `transfer`, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a `Transfer` event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _balances[sender] = _balances[sender].sub(amount); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a `Transfer` event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destoys `amount` tokens from `account`, reducing the * total supply. * * Emits a `Transfer` event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 value) internal { require(account != address(0), "ERC20: burn from the zero address"); _totalSupply = _totalSupply.sub(value); _balances[account] = _balances[account].sub(value); emit Transfer(account, address(0), value); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an `Approval` event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 value) internal { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = value; emit Approval(owner, spender, value); } /** * @dev Destoys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See `_burn` and `_approve`. */ function _burnFrom(address account, uint256 amount) internal { _burn(account, amount); _approve(account, msg.sender, _allowances[account][msg.sender].sub(amount)); } } // File: openzeppelin-solidity/contracts/access/Roles.sol pragma solidity ^0.5.0; /** * @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(!has(role, account), "Roles: account already has role"); role.bearer[account] = true; } /** * @dev Remove an account's access to this role. */ function remove(Role storage role, address account) internal { require(has(role, account), "Roles: account does not have role"); 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), "Roles: account is the zero address"); return role.bearer[account]; } } // File: openzeppelin-solidity/contracts/access/roles/PauserRole.sol pragma solidity ^0.5.0; 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), "PauserRole: caller does not have the Pauser role"); _; } 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 pragma solidity ^0.5.0; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ contract Pausable is PauserRole { /** * @dev Emitted when the pause is triggered by a pauser (`account`). */ event Paused(address account); /** * @dev Emitted when the pause is lifted by a pauser (`account`). */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. Assigns the Pauser role * to the deployer. */ constructor () internal { _paused = false; } /** * @dev Returns true if the contract is paused, and 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, "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. */ modifier whenPaused() { require(_paused, "Pausable: not paused"); _; } /** * @dev Called by a pauser to pause, triggers stopped state. */ function pause() public onlyPauser whenNotPaused { _paused = true; emit Paused(msg.sender); } /** * @dev Called by a pauser to unpause, returns to normal state. */ function unpause() public onlyPauser whenPaused { _paused = false; emit Unpaused(msg.sender); } } // File: openzeppelin-solidity/contracts/token/ERC20/ERC20Pausable.sol pragma solidity ^0.5.0; /** * @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) { return super.increaseAllowance(spender, addedValue); } function decreaseAllowance(address spender, uint subtractedValue) public whenNotPaused returns (bool) { return super.decreaseAllowance(spender, subtractedValue); } } // File: openzeppelin-solidity/contracts/access/roles/MinterRole.sol pragma solidity ^0.5.0; 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), "MinterRole: caller does not have the Minter role"); _; } 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: openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol pragma solidity ^0.5.0; /** * @dev Extension of `ERC20` that adds a set of accounts with the `MinterRole`, * which have permission to mint (create) new tokens as they see fit. * * At construction, the deployer of the contract is the only minter. */ contract ERC20Mintable is ERC20, MinterRole { /** * @dev See `ERC20._mint`. * * Requirements: * * - the caller must have the `MinterRole`. */ function mint(address account, uint256 amount) public onlyMinter returns (bool) { _mint(account, amount); return true; } } // File: openzeppelin-solidity/contracts/ownership/Ownable.sol pragma solidity ^0.5.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */ contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: contracts/whitelist/IWhitelist.sol pragma solidity ^0.5.0; // Interface to be implemented by the Whitelist contract. contract IWhitelist { function isWhitelisted(address account) public view returns (bool); } // File: contracts/token/BurnerRole.sol pragma solidity ^0.5.0; contract BurnerRole { using Roles for Roles.Role; event BurnerAdded(address indexed account); event BurnerRemoved(address indexed account); Roles.Role private _burners; constructor () internal { _addBurner(msg.sender); } modifier onlyBurner() { require(isBurner(msg.sender)); _; } function isBurner(address account) public view returns (bool) { return _burners.has(account); } function addBurner(address account) public onlyBurner { _addBurner(account); } function renounceBurner() public { _removeBurner(msg.sender); } function _addBurner(address account) internal { _burners.add(account); emit BurnerAdded(account); } function _removeBurner(address account) internal { _burners.remove(account); emit BurnerRemoved(account); } } // File: contracts/token/ERC20Burnable.sol pragma solidity ^0.5.0; // Only allow accounts with the burner role to burn tokens. contract ERC20Burnable is ERC20, BurnerRole { function burn(uint256 value) public onlyBurner() { _burn(msg.sender, value); } function burnFrom(address from, uint256 value) public onlyBurner() { _burnFrom(from, value); } } // File: contracts/token/ERC20Whitelistable.sol pragma solidity ^0.5.0; // Disallow transfers of the token to or from blacklisted accounts. contract ERC20Whitelistable is ERC20Mintable, ERC20Burnable, Ownable { event WhitelistChanged(IWhitelist indexed account); IWhitelist public whitelist; function setWhitelist(IWhitelist _whitelist) public onlyOwner { whitelist = _whitelist; emit WhitelistChanged(_whitelist); } modifier onlyWhitelisted(address account) { require(isWhitelisted(account)); _; } modifier notWhitelisted(address account) { require(!isWhitelisted(account)); _; } // Returns true if the account is allowed to send and receive tokens. function isWhitelisted(address account) public view returns (bool) { return whitelist.isWhitelisted(account); } function transfer(address to, uint256 value) public onlyWhitelisted(msg.sender) onlyWhitelisted(to) returns (bool) { return super.transfer(to, value); } function transferFrom(address from, address to, uint256 value) public onlyWhitelisted(from) onlyWhitelisted(to) returns (bool) { return super.transferFrom(from, to, value); } function mint(address to, uint256 value) public onlyWhitelisted(to) returns (bool) { return super.mint(to, value); } // Destroy the tokens held by a blacklisted account. function burnBlacklisted(address from, uint256 value) public onlyBurner() notWhitelisted(from) { _burn(from, value); } } // File: contracts/utils/CanReclaimEther.sol pragma solidity ^0.5.0; // Ether should not be sent to this contract. If any ether is accidentally sent to this // contract, allow the contract owner to recover it. // Copied from https://github.com/OpenZeppelin/openzeppelin-solidity/blob/2441fd7d17bffa1944f6f539b2cddd6d19997a31/contracts/ownership/HasNoEther.sol contract CanReclaimEther is Ownable { function reclaimEther() external onlyOwner { msg.sender.transfer(address(this).balance); } } // File: openzeppelin-solidity/contracts/utils/Address.sol pragma solidity ^0.5.0; /** * @dev Collection of functions related to the address type, */ library Address { /** * @dev Returns true if `account` is a contract. * * This test is non-exhaustive, and there may be false-negatives: during the * execution of a contract's constructor, its address will be reported as * not containing a contract. * * > It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } } // File: openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol pragma solidity ^0.5.0; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: contracts/utils/CanReclaimToken.sol pragma solidity ^0.5.0; // Tokens should not be sent to this contract. If any tokens are accidentally sent to // this contract, allow the contract owner to recover them. // Copied from https://github.com/OpenZeppelin/openzeppelin-solidity/blob/6c4c8989b399510a66d8b98ad75a0979482436d2/contracts/ownership/CanReclaimToken.sol contract CanReclaimToken is Ownable { using SafeERC20 for IERC20; function reclaimToken(IERC20 token) external onlyOwner { uint256 balance = token.balanceOf(address(this)); token.safeTransfer(owner(), balance); } } // File: contracts/token/LeveragedToken.sol pragma solidity ^0.5.0; contract LeveragedToken is ERC20Detailed, ERC20Pausable, ERC20Mintable, ERC20Burnable, ERC20Whitelistable, CanReclaimEther, CanReclaimToken { string public underlying; int8 public leverage; constructor(string memory name, string memory symbol, string memory _underlying, int8 _leverage) ERC20Detailed(name, symbol, 18) public { underlying = _underlying; leverage = _leverage; } }

eth-client icon eth-client

support library for Z.com Clound BlockChain and ConoHa BlockChain

ganache icon ganache

Personal blockchain for Ethereum development

gpt4all icon gpt4all

gpt4all: an ecosystem of open-source chatbots trained on a massive collections of clean assistant data including code, stories and dialogue

kyc-ethereum-dapp icon kyc-ethereum-dapp

Proof of Concept (PoC) Dapp on Ethereum Blockchain for solving the KYC requirements of financial and other organisations

lexcorpus icon lexcorpus

Body of building block contracts for legal engineers and their clients

mak icon mak

pragma solidity ^ 0.4.17; library SafeMath { function mul(uint a, uint b) internal pure returns(uint) { uint c = a * b; assert(a == 0 || c / a == b); return c; } function sub(uint a, uint b) internal pure returns(uint) { assert(b <= a); return a - b; } function add(uint a, uint b) internal pure returns(uint) { uint c = a + b; assert(c >= a && c >= b); return c; } } contract ERC20 { uint public totalSupply; function balanceOf(address who) public view returns(uint); function allowance(address owner, address spender) public view returns(uint); function transfer(address to, uint value) public returns(bool ok); function transferFrom(address from, address to, uint value) public returns(bool ok); function approve(address spender, uint value) public returns(bool ok); event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value); } /** * @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 public owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ function Ownable() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @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) onlyOwner public { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } } /** * @title Pausable * @dev Base contract which allows children to implement an emergency stop mechanism. */ contract Pausable is Ownable { event Pause(); event Unpause(); bool public paused = false; /** * @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 onlyOwner whenNotPaused { paused = true; Pause(); } /** * @dev called by the owner to unpause, returns to normal state */ function unpause() public onlyOwner whenPaused { paused = false; Unpause(); } } // Whitelist smart contract // This smart contract keeps list of addresses to whitelist contract WhiteList is Ownable { mapping(address => bool) public whiteList; uint public totalWhiteListed; //white listed users number event LogWhiteListed(address indexed user, uint whiteListedNum); event LogWhiteListedMultiple(uint whiteListedNum); event LogRemoveWhiteListed(address indexed user); // @notice it will return status of white listing // @return true if user is white listed and false if is not function isWhiteListed(address _user) external view returns (bool) { return whiteList[_user]; } // @notice it will remove whitelisted user // @param _contributor {address} of user to unwhitelist function removeFromWhiteList(address _user) external onlyOwner() returns (bool) { require(whiteList[_user] == true); whiteList[_user] = false; totalWhiteListed--; LogRemoveWhiteListed(_user); return true; } // @notice it will white list one member // @param _user {address} of user to whitelist // @return true if successful function addToWhiteList(address _user) external onlyOwner() returns (bool) { if (whiteList[_user] != true) { whiteList[_user] = true; totalWhiteListed++; LogWhiteListed(_user, totalWhiteListed); } return true; } // @notice it will white list multiple members // @param _user {address[]} of users to whitelist // @return true if successful function addToWhiteListMultiple(address[] _users) external onlyOwner() returns (bool) { for (uint i = 0; i < _users.length; ++i) { if (whiteList[_users[i]] != true) { whiteList[_users[i]] = true; totalWhiteListed++; } } LogWhiteListedMultiple(totalWhiteListed); return true; } } // @note this contract can be inherited by Crowdsale and TeamAllocation contracts and // control release of tokens through even time release based on the inputted duration time interval contract TokenVesting is Ownable { using SafeMath for uint; struct TokenHolder { uint weiReceived; // amount of ETH contributed uint tokensToSend; // amount of tokens sent bool refunded; // true if user has been refunded uint releasedAmount; // amount released through vesting schedule bool revoked; // true if right to continue vesting is revoked } event Released(uint256 amount, uint256 tokenDecimals); event ContractUpdated(bool done); uint256 public cliff; // time in when vesting should begin uint256 public startCountDown; // time when countdown starts uint256 public duration; // duration of period in which vesting takes place Token public token; // token contract containing tokens mapping(address => TokenHolder) public tokenHolders; //tokenHolder list WhiteList public whiteList; // whitelist contract uint256 public presaleBonus; // @note constructor /** function TokenVesting(uint256 _start, uint256 _cliff, uint256 _duration) public { require(_cliff <= _duration); duration = _duration; cliff = _start.add(_cliff); startCountDown = _start; ContractUpdated(true); } */ // @notice Specify address of token contract // @param _tokenAddress {address} address of token contract // @return res {bool} function initilizeVestingAndTokenAndWhiteList(Token _tokenAddress, uint256 _start, uint256 _cliff, uint256 _duration, uint256 _presaleBonus, WhiteList _whiteList) external onlyOwner() returns(bool res) { require(_cliff <= _duration); require(_tokenAddress != address(0)); duration = _duration; cliff = _start.add(_cliff); startCountDown = _start; token = _tokenAddress; whiteList = _whiteList; presaleBonus = _presaleBonus; ContractUpdated(true); return true; } // @notice Specify address of token contract // @param _tokenAddress {address} address of token contract // @return res {bool} function initilizeVestingAndToken(Token _tokenAddress, uint256 _start, uint256 _cliff, uint256 _duration, uint256 _presaleBonus ) external onlyOwner() returns(bool res) { require(_cliff <= _duration); require(_tokenAddress != address(0)); duration = _duration; cliff = _start.add(_cliff); startCountDown = _start; token = _tokenAddress; presaleBonus = _presaleBonus; ContractUpdated(true); return true; } function returnVestingSchedule() external view returns (uint, uint, uint) { return (duration, cliff, startCountDown); } // @note owner can revoke access to continue vesting of tokens // @param _user {address} of user to revoke their right to vesting function revoke(address _user) public onlyOwner() { TokenHolder storage tokenHolder = tokenHolders[_user]; tokenHolder.revoked = true; } function vestedAmountAvailable() public view returns (uint amount, uint decimals) { TokenHolder storage tokenHolder = tokenHolders[msg.sender]; uint tokensToRelease = vestedAmount(tokenHolder.tokensToSend); // if (tokenHolder.releasedAmount + tokensToRelease > tokenHolder.tokensToSend) // return (tokenHolder.tokensToSend - tokenHolder.releasedAmount, token.decimals()); // else return (tokensToRelease - tokenHolder.releasedAmount, token.decimals()); } // @notice Transfers vested available tokens to beneficiary function release() public { TokenHolder storage tokenHolder = tokenHolders[msg.sender]; // check if right to vesting is not revoked require(!tokenHolder.revoked); uint tokensToRelease = vestedAmount(tokenHolder.tokensToSend); uint currentTokenToRelease = tokensToRelease - tokenHolder.releasedAmount; tokenHolder.releasedAmount += currentTokenToRelease; token.transfer(msg.sender, currentTokenToRelease); Released(currentTokenToRelease, token.decimals()); } // @notice this function will determine vested amount // @param _totalBalance {uint} total balance of tokens assigned to this user // @return {uint} amount of tokens available to transfer function vestedAmount(uint _totalBalance) public view returns (uint) { if (now < cliff) { return 0; } else if (now >= startCountDown.add(duration)) { return _totalBalance; } else { return _totalBalance.mul(now.sub(startCountDown)) / duration; } } } // Crowdsale Smart Contract // This smart contract collects ETH and in return sends tokens to the Backers contract Crowdsale is Pausable, TokenVesting { using SafeMath for uint; address public multisigETH; // Multisig contract that will receive the ETH address public commissionAddress; // address to deposit commissions uint public tokensForTeam; // tokens for the team uint public ethReceivedPresale; // Number of ETH received in presale uint public ethReceivedMain; // Number of ETH received in main sale uint public totalTokensSent; // Number of tokens sent to ETH contributors uint public tokensSentMain; uint public tokensSentPresale; uint public tokensSentDev; uint public startBlock; // Crowdsale start block uint public endBlock; // Crowdsale end block uint public maxCap; // Maximum number of token to sell uint public minCap; // Minimum number of ETH to raise uint public minContributionMainSale; // Minimum amount to contribute in main sale uint public minContributionPresale; // Minimum amount to contribut in presale uint public maxContribution; bool public crowdsaleClosed; // Is crowdsale still on going uint public tokenPriceWei; uint public refundCount; uint public totalRefunded; uint public campaignDurationDays; // campaign duration in days uint public firstPeriod; uint public secondPeriod; uint public thirdPeriod; uint public firstBonus; uint public secondBonus; uint public thirdBonus; uint public multiplier; uint public status; Step public currentStep; // To allow for controlled steps of the campaign // Looping through Backer //mapping(address => Backer) public backers; //backer list address[] public holdersIndex; // to be able to itarate through backers when distributing the tokens address[] public devIndex; // to be able to itarate through backers when distributing the tokens // @notice to set and determine steps of crowdsale enum Step { FundingPreSale, // presale mode FundingMainSale, // public mode Refunding // in case campaign failed during this step contributors will be able to receive refunds } // @notice to verify if action is not performed out of the campaing range modifier respectTimeFrame() { if ((block.number < startBlock) || (block.number > endBlock)) revert(); _; } modifier minCapNotReached() { if (totalTokensSent >= minCap) revert(); _; } // Events event LogReceivedETH(address indexed backer, uint amount, uint tokenAmount); event LogStarted(uint startBlockLog, uint endBlockLog); event LogFinalized(bool success); event LogRefundETH(address indexed backer, uint amount); event LogStepAdvanced(); event LogDevTokensAllocated(address indexed dev, uint amount); event LogNonVestedTokensSent(address indexed user, uint amount); // Crowdsale {constructor} // @notice fired when contract is crated. Initilizes all constnat variables. function Crowdsale(uint _decimalPoints, address _multisigETH, uint _toekensForTeam, uint _minContributionPresale, uint _minContributionMainSale, uint _maxContribution, uint _maxCap, uint _minCap, uint _tokenPriceWei, uint _campaignDurationDays, uint _firstPeriod, uint _secondPeriod, uint _thirdPeriod, uint _firstBonus, uint _secondBonus, uint _thirdBonus) public { multiplier = 10**_decimalPoints; multisigETH = _multisigETH; tokensForTeam = _toekensForTeam * multiplier; minContributionPresale = _minContributionPresale; minContributionMainSale = _minContributionMainSale; maxContribution = _maxContribution; maxCap = _maxCap * multiplier; minCap = _minCap * multiplier; tokenPriceWei = _tokenPriceWei; campaignDurationDays = _campaignDurationDays; firstPeriod = _firstPeriod; secondPeriod = _secondPeriod; thirdPeriod = _thirdPeriod; firstBonus = _firstBonus; secondBonus = _secondBonus; thirdBonus = _thirdBonus; //TODO replace this address below with correct address. commissionAddress = 0x326B5E9b8B2ebf415F9e91b42c7911279d296ea1; //commissionAddress = 0x853A3F142430658A32f75A0dc891b98BF4bDF5c1; currentStep = Step.FundingPreSale; } // @notice to populate website with status of the sale function returnWebsiteData() external view returns(uint, uint, uint, uint, uint, uint, uint, uint, uint, uint, bool, bool, uint, Step) { return (startBlock, endBlock, numberOfBackers(), ethReceivedPresale + ethReceivedMain, maxCap, minCap, totalTokensSent, tokenPriceWei, minContributionPresale, minContributionMainSale, paused, crowdsaleClosed, token.decimals(), currentStep); } // @notice this function will determine status of crowdsale function determineStatus() external view returns (uint) { if (crowdsaleClosed) // ICO finihsed return 1; if (block.number < endBlock && totalTokensSent < maxCap - 100) // ICO in progress return 2; if (totalTokensSent < minCap && block.number > endBlock) // ICO failed return 3; if (endBlock == 0) // ICO hasn't been started yet return 4; return 0; } // {fallback function} // @notice It will call internal function which handels allocation of Ether and calculates tokens. function () public payable { contribute(msg.sender); } // @notice to allow for contribution from interface function contributePublic() external payable { contribute(msg.sender); } // @notice set the step of the campaign from presale to public sale // contract is deployed in presale mode // WARNING: there is no way to go back function advanceStep() external onlyOwner() { currentStep = Step.FundingMainSale; LogStepAdvanced(); } // @notice It will be called by owner to start the sale function start() external onlyOwner() { startBlock = block.number; endBlock = startBlock + (4*60*24*campaignDurationDays); // assumption is that one block takes 15 sec. crowdsaleClosed = false; LogStarted(startBlock, endBlock); } // @notice This function will finalize the sale. // It will only execute if predetermined sale time passed or all tokens are sold. function finalize() external onlyOwner() { require(!crowdsaleClosed); require(block.number >= endBlock || totalTokensSent > maxCap - 1000); // - 1000 is used to allow closing of the campaing when contribution is near // finished as exact amount of maxCap might be not feasible e.g. you can't easily buy few tokens. // when min contribution is 0.1 Eth. require(totalTokensSent >= minCap); crowdsaleClosed = true; // transfer commission portion to the platform commissionAddress.transfer(determineCommissions()); // transfer remaning funds to the campaign wallet multisigETH.transfer(this.balance); /*if (!token.transfer(owner, token.balanceOf(this))) revert(); // transfer tokens to admin account if (!token.burn(this, token.balanceOf(this))) revert(); // burn all the tokens remaining in the contract */ token.unlock(); // release lock from transfering tokens. LogFinalized(true); } // @notice it will allow contributors to get refund in case campaign failed // @return {bool} true if successful function refund() external whenNotPaused returns (bool) { uint totalEtherReceived = ethReceivedPresale + ethReceivedMain; require(totalEtherReceived < minCap); // ensure that campaign failed require(this.balance > 0); // contract will hold 0 ether at the end of campaign. // contract needs to be funded through fundContract() TokenHolder storage backer = tokenHolders[msg.sender]; require(backer.weiReceived > 0); // ensure that user has sent contribution require(!backer.refunded); // ensure that user hasn't been refunded yet backer.refunded = true; // save refund status to true refundCount++; totalRefunded += backer.weiReceived; if (!token.burn(msg.sender, backer.tokensToSend)) // burn tokens revert(); msg.sender.transfer(backer.weiReceived); // send back the contribution LogRefundETH(msg.sender, backer.weiReceived); return true; } // @notice allocate tokens to dev/team/advisors // @param _dev {address} // @param _amount {uint} amount of tokens function devAllocation(address _dev, uint _amount) external onlyOwner() returns (bool) { require(_dev != address(0)); require(crowdsaleClosed); require(totalTokensSent.add(_amount) <= token.totalSupply()); devIndex.push(_dev); TokenHolder storage tokenHolder = tokenHolders[_dev]; tokenHolder.tokensToSend = _amount; tokensSentDev += _amount; totalTokensSent += _amount; LogDevTokensAllocated(_dev, _amount); // Register event return true; } // @notice Failsafe drain function drain(uint _amount) external onlyOwner() { owner.transfer(_amount); } // @notice transfer tokens which are not subject to vesting // @param _recipient {addres} // @param _amont {uint} amount to transfer function transferTokens(address _recipient, uint _amount) external onlyOwner() returns (bool) { require(_recipient != address(0)); if (!token.transfer(_recipient, _amount)) revert(); LogNonVestedTokensSent(_recipient, _amount); } // @notice determine amount of commissions for the platform function determineCommissions() public view returns (uint) { if (this.balance <= 500 ether) { return (this.balance * 10)/100; }else if (this.balance <= 1000 ether) { return (this.balance * 8)/100; }else if (this.balance < 10000 ether) { return (this.balance * 6)/100; }else { return (this.balance * 6)/100; } } // @notice return number of contributors // @return {uint} number of contributors function numberOfBackers() public view returns (uint) { return holdersIndex.length; } // @notice It will be called by fallback function whenever ether is sent to it // @param _backer {address} address of beneficiary // @return res {bool} true if transaction was successful function contribute(address _backer) internal whenNotPaused respectTimeFrame returns(bool res) { //require(msg.value <= maxContribution); if (whiteList != address(0)) // if whitelist initialized verify member whitelist status require(whiteList.isWhiteListed(_backer)); // ensure that user is whitelisted uint tokensToSend = calculateNoOfTokensToSend(); // calculate number of tokens // Ensure that max cap hasn't been reached require(totalTokensSent + tokensToSend <= maxCap); TokenHolder storage backer = tokenHolders[_backer]; if (backer.weiReceived == 0) holdersIndex.push(_backer); if (Step.FundingMainSale == currentStep) { // Update the total Ether received and tokens sent during public sale require(msg.value >= minContributionMainSale); // stop when required minimum is not met ethReceivedMain = ethReceivedMain.add(msg.value); tokensSentMain += tokensToSend; }else { require(msg.value >= minContributionPresale); // stop when required minimum is not met ethReceivedPresale = ethReceivedPresale.add(msg.value); tokensSentPresale += tokensToSend; } backer.tokensToSend += tokensToSend; backer.weiReceived = backer.weiReceived.add(msg.value); totalTokensSent += tokensToSend; // tokens are not transferrd to contributors during this phase // tokens will be transferred based on the vesting schedule, when contributor // calls release() function of this contract LogReceivedETH(_backer, msg.value, tokensToSend); // Register event return true; } // @notice This function will return number of tokens based on time intervals in the campaign function calculateNoOfTokensToSend() internal view returns (uint) { uint tokenAmount = msg.value.mul(multiplier) / tokenPriceWei; if (Step.FundingMainSale == currentStep) { if (block.number <= startBlock + firstPeriod) { return tokenAmount + tokenAmount.mul(firstBonus) / 100; }else if (block.number <= startBlock + secondPeriod) { return tokenAmount + tokenAmount.mul(secondBonus) / 100; }else if (block.number <= startBlock + thirdPeriod) { return tokenAmount + tokenAmount.mul(thirdBonus) / 100; }else { return tokenAmount; } }else return tokenAmount + tokenAmount.mul(presaleBonus) / 100; } } // The token contract Token is ERC20, Ownable { using SafeMath for uint; // Public variables of the token string public name; string public symbol; uint public decimals; // How many decimals to show. string public version = "v0.1"; uint public totalSupply; bool public locked; address public crowdSaleAddress; mapping(address => uint) public balances; mapping(address => mapping(address => uint)) public allowed; // Lock transfer during the ICO modifier onlyUnlocked() { if (msg.sender != crowdSaleAddress && locked && msg.sender != owner) revert(); _; } modifier onlyAuthorized() { if (msg.sender != crowdSaleAddress && msg.sender != owner) revert(); _; } // The Token constructor function Token(uint _initialSupply, string _tokenName, uint _decimalUnits, string _tokenSymbol, string _version, address _crowdSaleAddress) public { locked = true; // Lock the transfer of tokens during the crowdsale totalSupply = _initialSupply * (10**_decimalUnits); name = _tokenName; // Set the name for display purposes symbol = _tokenSymbol; // Set the symbol for display purposes decimals = _decimalUnits; // Amount of decimals for display purposes version = _version; crowdSaleAddress = _crowdSaleAddress; balances[crowdSaleAddress] = totalSupply; } function unlock() public onlyAuthorized { locked = false; } function lock() public onlyAuthorized { locked = true; } function burn(address _member, uint256 _value) public onlyAuthorized returns(bool) { require(balances[_member] >= _value); balances[_member] -= _value; totalSupply -= _value; Transfer(_member, 0x0, _value); return true; } // @notice transfer tokens to given address // @param _to {address} address or recipient // @param _value {uint} amount to transfer // @return {bool} true if successful function transfer(address _to, uint _value) public onlyUnlocked returns(bool) { require(_to != address(0)); require(balances[msg.sender] >= _value); balances[msg.sender] -= _value; balances[_to] += _value; Transfer(msg.sender, _to, _value); return true; } // @notice transfer tokens from given address to another address // @param _from {address} from whom tokens are transferred // @param _to {address} to whom tokens are transferred // @param _value {uint} amount of tokens to transfer // @return {bool} true if successful function transferFrom(address _from, address _to, uint256 _value) public onlyUnlocked returns(bool success) { require(_to != address(0)); require(balances[_from] >= _value); // Check if the sender has enough require(_value <= allowed[_from][msg.sender]); // Check if allowed is greater or equal balances[_from] -= _value; // Subtract from the sender balances[_to] += _value; // Add the same to the recipient allowed[_from][msg.sender] -= _value; // adjust allowed Transfer(_from, _to, _value); return true; } // @notice to query balance of account // @return _owner {address} address of user to query balance function balanceOf(address _owner) public view returns(uint balance) { return balances[_owner]; } /** * @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, uint _value) public returns(bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } // @notice to query of allowance of one user to the other // @param _owner {address} of the owner of the account // @param _spender {address} of the spender of the account // @return remaining {uint} amount of remaining allowance function allowance(address _owner, address _spender) public view returns(uint remaining) { return allowed[_owner][_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 */ function increaseApproval (address _spender, uint _addedValue) public returns (bool success) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.