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
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_safeMint
function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); }
/** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 11053, 11168 ] }
3,200
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_safeMint
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); }
/** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 11390, 11645 ] }
3,201
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_mint
function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); }
/** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 11976, 12385 ] }
3,202
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_burn
function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); }
/** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 12609, 13159 ] }
3,203
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_transfer
function _transfer(address from, address to, uint256 tokenId) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); }
/** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * Requirements: * * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 13491, 14095 ] }
3,204
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_setTokenURI
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; }
/** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 14246, 14466 ] }
3,205
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_setBaseURI
function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; }
/** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 14691, 14796 ] }
3,206
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_checkOnERC721Received
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) private returns (bool) { if (!to.isContract()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); }
/** * @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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 15356, 15965 ] }
3,207
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_approve
function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner }
/** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 16079, 16276 ] }
3,208
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
ERC721
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable { using SafeMath for uint256; using Address for address; using EnumerableSet for EnumerableSet.UintSet; using EnumerableMap for EnumerableMap.UintToAddressMap; using Strings for uint256; // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector` bytes4 private constant _ERC721_RECEIVED = 0x150b7a02; // Mapping from holder address to their (enumerable) set of owned tokens mapping (address => EnumerableSet.UintSet) private _holderTokens; // Enumerable mapping from token ids to their owners EnumerableMap.UintToAddressMap private _tokenOwners; // 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; // Token name string private _name; // Token symbol string private _symbol; // Optional mapping for token URIs mapping (uint256 => string) private _tokenURIs; // Base URI string private _baseURI; /* * bytes4(keccak256('balanceOf(address)')) == 0x70a08231 * bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e * bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3 * bytes4(keccak256('getApproved(uint256)')) == 0x081812fc * bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465 * bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5 * bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde * * => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^ * 0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd */ bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd; /* * bytes4(keccak256('name()')) == 0x06fdde03 * bytes4(keccak256('symbol()')) == 0x95d89b41 * bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd * * => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f */ bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f; /* * bytes4(keccak256('totalSupply()')) == 0x18160ddd * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59 * bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7 * * => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63 */ bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; // register the supported interfaces to conform to ERC721 via ERC165 _registerInterface(_INTERFACE_ID_ERC721); _registerInterface(_INTERFACE_ID_ERC721_METADATA); _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE); } /** * @dev See {IERC721-balanceOf}. */ function balanceOf(address owner) public view virtual override returns (uint256) { require(owner != address(0), "ERC721: balance query for the zero address"); return _holderTokens[owner].length(); } /** * @dev See {IERC721-ownerOf}. */ function ownerOf(uint256 tokenId) public view virtual override returns (address) { return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token"); } /** * @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) { require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token"); string memory _tokenURI = _tokenURIs[tokenId]; string memory base = baseURI(); // If there is no base URI, return the token URI. if (bytes(base).length == 0) { return _tokenURI; } // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). if (bytes(_tokenURI).length > 0) { return string(abi.encodePacked(base, _tokenURI)); } // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI. return string(abi.encodePacked(base, tokenId.toString())); } /** * @dev Returns the base URI set via {_setBaseURI}. This will be * automatically added as a prefix in {tokenURI} to each token's URI, or * to the token ID if no specific URI is set for that token ID. */ function baseURI() public view virtual returns (string memory) { return _baseURI; } /** * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { return _holderTokens[owner].at(index); } /** * @dev See {IERC721Enumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds return _tokenOwners.length(); } /** * @dev See {IERC721Enumerable-tokenByIndex}. */ function tokenByIndex(uint256 index) public view virtual override returns (uint256) { (uint256 tokenId, ) = _tokenOwners.at(index); return tokenId; } /** * @dev See {IERC721-approve}. */ function approve(address to, uint256 tokenId) public virtual override { address owner = ERC721.ownerOf(tokenId); require(to != owner, "ERC721: approval to current owner"); require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()), "ERC721: approve caller is not owner nor approved for all" ); _approve(to, tokenId); } /** * @dev See {IERC721-getApproved}. */ function getApproved(uint256 tokenId) public view virtual override returns (address) { require(_exists(tokenId), "ERC721: approved query for nonexistent token"); return _tokenApprovals[tokenId]; } /** * @dev See {IERC721-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { require(operator != _msgSender(), "ERC721: approve to caller"); _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 { //solhint-disable-next-line max-line-length require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _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 { require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved"); _safeTransfer(from, to, tokenId, _data); } /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * `_data` is additional data, it has no specified format and it is sent in call to `to`. * * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g. * implement alternative mechanisms to perform token transfer, such as signature-based. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual { _transfer(from, to, tokenId); require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @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`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _tokenOwners.contains(tokenId); } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) { require(_exists(tokenId), "ERC721: operator query for nonexistent token"); address owner = ERC721.ownerOf(tokenId); return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender)); } /** * @dev Safely mints `tokenId` and transfers it to `to`. * * Requirements: d* * - `tokenId` must not exist. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function _safeMint(address to, uint256 tokenId) internal virtual { _safeMint(to, tokenId, ""); } /** * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is * forwarded in {IERC721Receiver-onERC721Received} to contract recipients. */ function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual { _mint(to, tokenId); require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer"); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Transfer} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "ERC721: mint to the zero address"); require(!_exists(tokenId), "ERC721: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(address(0), to, tokenId); } /** * @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 { address owner = ERC721.ownerOf(tokenId); // internal owner _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); // Clear metadata (if any) if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } _holderTokens[owner].remove(tokenId); _tokenOwners.remove(tokenId); emit Transfer(owner, address(0), tokenId); } /** * @dev Transfers `tokenId` from `from` to `to`. * As opposed to {transferFrom}, this imposes no restrictions on msg.sender. * * 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) internal virtual { require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner require(to != address(0), "ERC721: transfer to the zero address"); _beforeTokenTransfer(from, to, tokenId); // Clear approvals from the previous owner _approve(address(0), tokenId); _holderTokens[from].remove(tokenId); _holderTokens[to].add(tokenId); _tokenOwners.set(tokenId, to); emit Transfer(from, to, tokenId); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev Internal function to set the base URI for all token IDs. It is * automatically added as a prefix to the value returned in {tokenURI}, * or to the token ID if {tokenURI} is empty. */ function _setBaseURI(string memory baseURI_) internal virtual { _baseURI = baseURI_; } /** * @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()) { return true; } bytes memory returndata = to.functionCall(abi.encodeWithSelector( IERC721Receiver(to).onERC721Received.selector, _msgSender(), from, tokenId, _data ), "ERC721: transfer to non ERC721Receiver implementer"); bytes4 retval = abi.decode(returndata, (bytes4)); return (retval == _ERC721_RECEIVED); } /** * @dev Approve `to` to operate on `tokenId` * * Emits an {Approval} event. */ function _approve(address to, uint256 tokenId) internal virtual { _tokenApprovals[tokenId] = to; emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { } }
/** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://eips.ethereum.org/EIPS/eip-721 */
NatSpecMultiLine
_beforeTokenTransfer
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
/** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * 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, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 16884, 16982 ] }
3,209
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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
tryAdd
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); }
/** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 161, 344 ] }
3,210
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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
trySub
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); }
/** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 492, 651 ] }
3,211
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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
tryMul
function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); }
/** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 801, 1249 ] }
3,212
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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
tryDiv
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); }
/** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 1400, 1560 ] }
3,213
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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
tryMod
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); }
/** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 1721, 1881 ] }
3,214
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 2123, 2307 ] }
3,215
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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"); return a - b; }
/** * @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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 2585, 2748 ] }
3,216
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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) { 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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 3002, 3227 ] }
3,217
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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) { require(b > 0, "SafeMath: division by zero"); return a / b; }
/** * @dev Returns the integer division of two unsigned integers, reverting 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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 3700, 3858 ] }
3,218
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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), * reverting 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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 4320, 4476 ] }
3,219
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; }
/** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 4950, 5121 ] }
3,220
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; }
/** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 5790, 5960 ] }
3,221
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, 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 (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @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"); return a - b; } /** * @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) { 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, reverting 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) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting 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 Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); 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, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * 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.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 6618, 6788 ] }
3,222
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
owner
function owner() public view virtual returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 497, 589 ] }
3,223
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 1148, 1301 ] }
3,224
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
Ownable
abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 1451, 1700 ] }
3,225
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
CuriousAxolotlNFT
contract CuriousAxolotlNFT is ERC721, Ownable { using SafeMath for uint256; using Counters for Counters.Counter; Counters.Counter private _tokenIds; event licenseisLocked(string _licenseText); string public AXOLOTL_PROVENANCE = "QmcXvN9tph2HKhMCr3jrcXr1BUdiWjhdR4M2AVnxGHAvvh"; // IPFS URL WILL BE ADDED WHEN AXOLOTLs ARE ALL SOLD OUT bool public saleIsActive = false; mapping(uint => string) public axolotlNames; using Strings for uint256; string public LICENSE_TEXT = "MIT"; // IT IS WHAT IT SAYS bool licenseLocked = false; // TEAM CAN'T EDIT THE LICENSE AFTER THIS GETS TRUE uint256 public constant axolotlPrice = 20000000000000000; // 0.020 ETH uint public constant maxAxolotlPurchase = 20; // Reserve 20 Axolotls for team - Giveaways/Prizes etc uint public axolotlReserve = 20; uint256 public constant MAX_AXOLOTL = 1000; event axolotlNameChange(address _by, uint _tokenId, string _name); // the name and symbol for the NFT constructor() public ERC721("CuriousAxolotl", "AXOLOTL") {} function withdraw() public onlyOwner { uint balance = address(this).balance; msg.sender.transfer(balance); } function reserveAxolotls(address _to, uint256 _reserveAmount) public onlyOwner { uint supply = totalSupply(); require(_reserveAmount > 0 && _reserveAmount <= axolotlReserve, "Not enough reserve left for team"); for (uint i = 0; i < _reserveAmount; i++) { _safeMint(_to, supply + i); } axolotlReserve = axolotlReserve.sub(_reserveAmount); } function setBaseURI(string memory baseURI) public onlyOwner { _setBaseURI(baseURI); } // Returns the license for tokens function tokenLicense(uint _id) public view returns(string memory) { require(_id < totalSupply(), "CHOOSE A AXOLOTL WITHIN RANGE"); return LICENSE_TEXT; } // Locks the license to prevent further changes function lockLicense() public onlyOwner { licenseLocked = true; emit licenseisLocked(LICENSE_TEXT); } // Change the license function changeLicense(string memory _license) public onlyOwner { require(licenseLocked == false, "License already locked"); LICENSE_TEXT = _license; } function flipSaleState() public onlyOwner { saleIsActive = !saleIsActive; } // Create a function to mint/create the NFT function mintCuriousAxolotl(uint numberOfTokens) public payable { require(saleIsActive, "Sale must be active to mint Axolotl"); require(numberOfTokens > 0 && numberOfTokens <= maxAxolotlPurchase, "Can only mint 20 tokens at a time"); require(totalSupply().add(numberOfTokens) <= MAX_AXOLOTL, "Purchase would exceed max supply of Axolotls"); require(msg.value >= axolotlPrice.mul(numberOfTokens), "Ether value sent is not correct"); for(uint i = 0; i < numberOfTokens; i++) { uint mintIndex = totalSupply(); if (totalSupply() < MAX_AXOLOTL) { _safeMint(msg.sender, mintIndex); } } } // GET ALL AXOLOTL OF A WALLET AS AN ARRAY OF STRINGS. function axolotlNamesOfOwner(address _owner) external view returns(string[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new string[](0); } else { string[] memory result = new string[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = axolotlNames[ tokenOfOwnerByIndex(_owner, index) ] ; } return result; } } }
// Accessing the Ownable method ensures that only the creator of the smart contract can interact with it
LineComment
tokenLicense
function tokenLicense(uint _id) public view returns(string memory) { require(_id < totalSupply(), "CHOOSE A AXOLOTL WITHIN RANGE"); return LICENSE_TEXT; }
// Returns the license for tokens
LineComment
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 1846, 2028 ] }
3,226
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
CuriousAxolotlNFT
contract CuriousAxolotlNFT is ERC721, Ownable { using SafeMath for uint256; using Counters for Counters.Counter; Counters.Counter private _tokenIds; event licenseisLocked(string _licenseText); string public AXOLOTL_PROVENANCE = "QmcXvN9tph2HKhMCr3jrcXr1BUdiWjhdR4M2AVnxGHAvvh"; // IPFS URL WILL BE ADDED WHEN AXOLOTLs ARE ALL SOLD OUT bool public saleIsActive = false; mapping(uint => string) public axolotlNames; using Strings for uint256; string public LICENSE_TEXT = "MIT"; // IT IS WHAT IT SAYS bool licenseLocked = false; // TEAM CAN'T EDIT THE LICENSE AFTER THIS GETS TRUE uint256 public constant axolotlPrice = 20000000000000000; // 0.020 ETH uint public constant maxAxolotlPurchase = 20; // Reserve 20 Axolotls for team - Giveaways/Prizes etc uint public axolotlReserve = 20; uint256 public constant MAX_AXOLOTL = 1000; event axolotlNameChange(address _by, uint _tokenId, string _name); // the name and symbol for the NFT constructor() public ERC721("CuriousAxolotl", "AXOLOTL") {} function withdraw() public onlyOwner { uint balance = address(this).balance; msg.sender.transfer(balance); } function reserveAxolotls(address _to, uint256 _reserveAmount) public onlyOwner { uint supply = totalSupply(); require(_reserveAmount > 0 && _reserveAmount <= axolotlReserve, "Not enough reserve left for team"); for (uint i = 0; i < _reserveAmount; i++) { _safeMint(_to, supply + i); } axolotlReserve = axolotlReserve.sub(_reserveAmount); } function setBaseURI(string memory baseURI) public onlyOwner { _setBaseURI(baseURI); } // Returns the license for tokens function tokenLicense(uint _id) public view returns(string memory) { require(_id < totalSupply(), "CHOOSE A AXOLOTL WITHIN RANGE"); return LICENSE_TEXT; } // Locks the license to prevent further changes function lockLicense() public onlyOwner { licenseLocked = true; emit licenseisLocked(LICENSE_TEXT); } // Change the license function changeLicense(string memory _license) public onlyOwner { require(licenseLocked == false, "License already locked"); LICENSE_TEXT = _license; } function flipSaleState() public onlyOwner { saleIsActive = !saleIsActive; } // Create a function to mint/create the NFT function mintCuriousAxolotl(uint numberOfTokens) public payable { require(saleIsActive, "Sale must be active to mint Axolotl"); require(numberOfTokens > 0 && numberOfTokens <= maxAxolotlPurchase, "Can only mint 20 tokens at a time"); require(totalSupply().add(numberOfTokens) <= MAX_AXOLOTL, "Purchase would exceed max supply of Axolotls"); require(msg.value >= axolotlPrice.mul(numberOfTokens), "Ether value sent is not correct"); for(uint i = 0; i < numberOfTokens; i++) { uint mintIndex = totalSupply(); if (totalSupply() < MAX_AXOLOTL) { _safeMint(msg.sender, mintIndex); } } } // GET ALL AXOLOTL OF A WALLET AS AN ARRAY OF STRINGS. function axolotlNamesOfOwner(address _owner) external view returns(string[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new string[](0); } else { string[] memory result = new string[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = axolotlNames[ tokenOfOwnerByIndex(_owner, index) ] ; } return result; } } }
// Accessing the Ownable method ensures that only the creator of the smart contract can interact with it
LineComment
lockLicense
function lockLicense() public onlyOwner { licenseLocked = true; emit licenseisLocked(LICENSE_TEXT); }
// Locks the license to prevent further changes
LineComment
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 2089, 2219 ] }
3,227
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
CuriousAxolotlNFT
contract CuriousAxolotlNFT is ERC721, Ownable { using SafeMath for uint256; using Counters for Counters.Counter; Counters.Counter private _tokenIds; event licenseisLocked(string _licenseText); string public AXOLOTL_PROVENANCE = "QmcXvN9tph2HKhMCr3jrcXr1BUdiWjhdR4M2AVnxGHAvvh"; // IPFS URL WILL BE ADDED WHEN AXOLOTLs ARE ALL SOLD OUT bool public saleIsActive = false; mapping(uint => string) public axolotlNames; using Strings for uint256; string public LICENSE_TEXT = "MIT"; // IT IS WHAT IT SAYS bool licenseLocked = false; // TEAM CAN'T EDIT THE LICENSE AFTER THIS GETS TRUE uint256 public constant axolotlPrice = 20000000000000000; // 0.020 ETH uint public constant maxAxolotlPurchase = 20; // Reserve 20 Axolotls for team - Giveaways/Prizes etc uint public axolotlReserve = 20; uint256 public constant MAX_AXOLOTL = 1000; event axolotlNameChange(address _by, uint _tokenId, string _name); // the name and symbol for the NFT constructor() public ERC721("CuriousAxolotl", "AXOLOTL") {} function withdraw() public onlyOwner { uint balance = address(this).balance; msg.sender.transfer(balance); } function reserveAxolotls(address _to, uint256 _reserveAmount) public onlyOwner { uint supply = totalSupply(); require(_reserveAmount > 0 && _reserveAmount <= axolotlReserve, "Not enough reserve left for team"); for (uint i = 0; i < _reserveAmount; i++) { _safeMint(_to, supply + i); } axolotlReserve = axolotlReserve.sub(_reserveAmount); } function setBaseURI(string memory baseURI) public onlyOwner { _setBaseURI(baseURI); } // Returns the license for tokens function tokenLicense(uint _id) public view returns(string memory) { require(_id < totalSupply(), "CHOOSE A AXOLOTL WITHIN RANGE"); return LICENSE_TEXT; } // Locks the license to prevent further changes function lockLicense() public onlyOwner { licenseLocked = true; emit licenseisLocked(LICENSE_TEXT); } // Change the license function changeLicense(string memory _license) public onlyOwner { require(licenseLocked == false, "License already locked"); LICENSE_TEXT = _license; } function flipSaleState() public onlyOwner { saleIsActive = !saleIsActive; } // Create a function to mint/create the NFT function mintCuriousAxolotl(uint numberOfTokens) public payable { require(saleIsActive, "Sale must be active to mint Axolotl"); require(numberOfTokens > 0 && numberOfTokens <= maxAxolotlPurchase, "Can only mint 20 tokens at a time"); require(totalSupply().add(numberOfTokens) <= MAX_AXOLOTL, "Purchase would exceed max supply of Axolotls"); require(msg.value >= axolotlPrice.mul(numberOfTokens), "Ether value sent is not correct"); for(uint i = 0; i < numberOfTokens; i++) { uint mintIndex = totalSupply(); if (totalSupply() < MAX_AXOLOTL) { _safeMint(msg.sender, mintIndex); } } } // GET ALL AXOLOTL OF A WALLET AS AN ARRAY OF STRINGS. function axolotlNamesOfOwner(address _owner) external view returns(string[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new string[](0); } else { string[] memory result = new string[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = axolotlNames[ tokenOfOwnerByIndex(_owner, index) ] ; } return result; } } }
// Accessing the Ownable method ensures that only the creator of the smart contract can interact with it
LineComment
changeLicense
function changeLicense(string memory _license) public onlyOwner { require(licenseLocked == false, "License already locked"); LICENSE_TEXT = _license; }
// Change the license
LineComment
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 2249, 2428 ] }
3,228
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
CuriousAxolotlNFT
contract CuriousAxolotlNFT is ERC721, Ownable { using SafeMath for uint256; using Counters for Counters.Counter; Counters.Counter private _tokenIds; event licenseisLocked(string _licenseText); string public AXOLOTL_PROVENANCE = "QmcXvN9tph2HKhMCr3jrcXr1BUdiWjhdR4M2AVnxGHAvvh"; // IPFS URL WILL BE ADDED WHEN AXOLOTLs ARE ALL SOLD OUT bool public saleIsActive = false; mapping(uint => string) public axolotlNames; using Strings for uint256; string public LICENSE_TEXT = "MIT"; // IT IS WHAT IT SAYS bool licenseLocked = false; // TEAM CAN'T EDIT THE LICENSE AFTER THIS GETS TRUE uint256 public constant axolotlPrice = 20000000000000000; // 0.020 ETH uint public constant maxAxolotlPurchase = 20; // Reserve 20 Axolotls for team - Giveaways/Prizes etc uint public axolotlReserve = 20; uint256 public constant MAX_AXOLOTL = 1000; event axolotlNameChange(address _by, uint _tokenId, string _name); // the name and symbol for the NFT constructor() public ERC721("CuriousAxolotl", "AXOLOTL") {} function withdraw() public onlyOwner { uint balance = address(this).balance; msg.sender.transfer(balance); } function reserveAxolotls(address _to, uint256 _reserveAmount) public onlyOwner { uint supply = totalSupply(); require(_reserveAmount > 0 && _reserveAmount <= axolotlReserve, "Not enough reserve left for team"); for (uint i = 0; i < _reserveAmount; i++) { _safeMint(_to, supply + i); } axolotlReserve = axolotlReserve.sub(_reserveAmount); } function setBaseURI(string memory baseURI) public onlyOwner { _setBaseURI(baseURI); } // Returns the license for tokens function tokenLicense(uint _id) public view returns(string memory) { require(_id < totalSupply(), "CHOOSE A AXOLOTL WITHIN RANGE"); return LICENSE_TEXT; } // Locks the license to prevent further changes function lockLicense() public onlyOwner { licenseLocked = true; emit licenseisLocked(LICENSE_TEXT); } // Change the license function changeLicense(string memory _license) public onlyOwner { require(licenseLocked == false, "License already locked"); LICENSE_TEXT = _license; } function flipSaleState() public onlyOwner { saleIsActive = !saleIsActive; } // Create a function to mint/create the NFT function mintCuriousAxolotl(uint numberOfTokens) public payable { require(saleIsActive, "Sale must be active to mint Axolotl"); require(numberOfTokens > 0 && numberOfTokens <= maxAxolotlPurchase, "Can only mint 20 tokens at a time"); require(totalSupply().add(numberOfTokens) <= MAX_AXOLOTL, "Purchase would exceed max supply of Axolotls"); require(msg.value >= axolotlPrice.mul(numberOfTokens), "Ether value sent is not correct"); for(uint i = 0; i < numberOfTokens; i++) { uint mintIndex = totalSupply(); if (totalSupply() < MAX_AXOLOTL) { _safeMint(msg.sender, mintIndex); } } } // GET ALL AXOLOTL OF A WALLET AS AN ARRAY OF STRINGS. function axolotlNamesOfOwner(address _owner) external view returns(string[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new string[](0); } else { string[] memory result = new string[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = axolotlNames[ tokenOfOwnerByIndex(_owner, index) ] ; } return result; } } }
// Accessing the Ownable method ensures that only the creator of the smart contract can interact with it
LineComment
mintCuriousAxolotl
function mintCuriousAxolotl(uint numberOfTokens) public payable { require(saleIsActive, "Sale must be active to mint Axolotl"); require(numberOfTokens > 0 && numberOfTokens <= maxAxolotlPurchase, "Can only mint 20 tokens at a time"); require(totalSupply().add(numberOfTokens) <= MAX_AXOLOTL, "Purchase would exceed max supply of Axolotls"); require(msg.value >= axolotlPrice.mul(numberOfTokens), "Ether value sent is not correct"); for(uint i = 0; i < numberOfTokens; i++) { uint mintIndex = totalSupply(); if (totalSupply() < MAX_AXOLOTL) { _safeMint(msg.sender, mintIndex); } } }
// Create a function to mint/create the NFT
LineComment
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 2583, 3296 ] }
3,229
CuriousAxolotlNFT
CuriousAxolotlNFT.sol
0x75e177433805cc252c18743b2c4d51e18ad970c0
Solidity
CuriousAxolotlNFT
contract CuriousAxolotlNFT is ERC721, Ownable { using SafeMath for uint256; using Counters for Counters.Counter; Counters.Counter private _tokenIds; event licenseisLocked(string _licenseText); string public AXOLOTL_PROVENANCE = "QmcXvN9tph2HKhMCr3jrcXr1BUdiWjhdR4M2AVnxGHAvvh"; // IPFS URL WILL BE ADDED WHEN AXOLOTLs ARE ALL SOLD OUT bool public saleIsActive = false; mapping(uint => string) public axolotlNames; using Strings for uint256; string public LICENSE_TEXT = "MIT"; // IT IS WHAT IT SAYS bool licenseLocked = false; // TEAM CAN'T EDIT THE LICENSE AFTER THIS GETS TRUE uint256 public constant axolotlPrice = 20000000000000000; // 0.020 ETH uint public constant maxAxolotlPurchase = 20; // Reserve 20 Axolotls for team - Giveaways/Prizes etc uint public axolotlReserve = 20; uint256 public constant MAX_AXOLOTL = 1000; event axolotlNameChange(address _by, uint _tokenId, string _name); // the name and symbol for the NFT constructor() public ERC721("CuriousAxolotl", "AXOLOTL") {} function withdraw() public onlyOwner { uint balance = address(this).balance; msg.sender.transfer(balance); } function reserveAxolotls(address _to, uint256 _reserveAmount) public onlyOwner { uint supply = totalSupply(); require(_reserveAmount > 0 && _reserveAmount <= axolotlReserve, "Not enough reserve left for team"); for (uint i = 0; i < _reserveAmount; i++) { _safeMint(_to, supply + i); } axolotlReserve = axolotlReserve.sub(_reserveAmount); } function setBaseURI(string memory baseURI) public onlyOwner { _setBaseURI(baseURI); } // Returns the license for tokens function tokenLicense(uint _id) public view returns(string memory) { require(_id < totalSupply(), "CHOOSE A AXOLOTL WITHIN RANGE"); return LICENSE_TEXT; } // Locks the license to prevent further changes function lockLicense() public onlyOwner { licenseLocked = true; emit licenseisLocked(LICENSE_TEXT); } // Change the license function changeLicense(string memory _license) public onlyOwner { require(licenseLocked == false, "License already locked"); LICENSE_TEXT = _license; } function flipSaleState() public onlyOwner { saleIsActive = !saleIsActive; } // Create a function to mint/create the NFT function mintCuriousAxolotl(uint numberOfTokens) public payable { require(saleIsActive, "Sale must be active to mint Axolotl"); require(numberOfTokens > 0 && numberOfTokens <= maxAxolotlPurchase, "Can only mint 20 tokens at a time"); require(totalSupply().add(numberOfTokens) <= MAX_AXOLOTL, "Purchase would exceed max supply of Axolotls"); require(msg.value >= axolotlPrice.mul(numberOfTokens), "Ether value sent is not correct"); for(uint i = 0; i < numberOfTokens; i++) { uint mintIndex = totalSupply(); if (totalSupply() < MAX_AXOLOTL) { _safeMint(msg.sender, mintIndex); } } } // GET ALL AXOLOTL OF A WALLET AS AN ARRAY OF STRINGS. function axolotlNamesOfOwner(address _owner) external view returns(string[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new string[](0); } else { string[] memory result = new string[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = axolotlNames[ tokenOfOwnerByIndex(_owner, index) ] ; } return result; } } }
// Accessing the Ownable method ensures that only the creator of the smart contract can interact with it
LineComment
axolotlNamesOfOwner
function axolotlNamesOfOwner(address _owner) external view returns(string[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new string[](0); } else { string[] memory result = new string[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = axolotlNames[ tokenOfOwnerByIndex(_owner, index) ] ; } return result; } }
// GET ALL AXOLOTL OF A WALLET AS AN ARRAY OF STRINGS.
LineComment
v0.7.3+commit.9bfce1f6
MIT
ipfs://f746f698b1f7097327eead01480889fee30091e43a0c56b79118819a73ad6300
{ "func_code_index": [ 3363, 3927 ] }
3,230
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
BLONDCOIN
function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); }
// ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 456, 794 ] }
3,231
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
totalSupply
function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; }
// ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 982, 1103 ] }
3,232
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
balanceOf
function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; }
// ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 1323, 1452 ] }
3,233
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transfer
function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; }
// ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 1796, 2073 ] }
3,234
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
approve
function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; }
// ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 2566, 2774 ] }
3,235
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transferFrom
function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; }
// ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 3305, 3663 ] }
3,236
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
allowance
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; }
// ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 3946, 4102 ] }
3,237
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
approveAndCall
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; }
// ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 4457, 4774 ] }
3,238
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
function () public payable { revert(); }
// ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 4966, 5025 ] }
3,239
BLONDCOIN
BLONDCOIN.sol
0x1c3bb10de15c31d5dbe48fbb7b87735d1b7d8c32
Solidity
BLONDCOIN
contract BLONDCOIN is ERC20Interface, Owned, SafeMath { string public symbol; string public name; uint8 public decimals; uint public _totalSupply; mapping(address => uint) balances; mapping(address => mapping(address => uint)) allowed; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ function BLONDCOIN() public { symbol = "BLO"; name = "BLONDCOIN"; decimals = 18; _totalSupply = 45000000000000000000000000; balances[0xff72c65aa864774aa029114c0f15a44bfc6bc4e0] = _totalSupply; Transfer(address(0), 0xff72c65aa864774aa029114c0f15a44bfc6bc4e0, _totalSupply); } // ------------------------------------------------------------------------ // Total supply // ------------------------------------------------------------------------ function totalSupply() public constant returns (uint) { return _totalSupply - balances[address(0)]; } // ------------------------------------------------------------------------ // Get the token balance for account tokenOwner // ------------------------------------------------------------------------ function balanceOf(address tokenOwner) public constant returns (uint balance) { return balances[tokenOwner]; } // ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to account // - Owner's account must have sufficient balance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transfer(address to, uint tokens) public returns (bool success) { balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(msg.sender, to, tokens); return true; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account // // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md // recommends that there are no checks for the approval double-spend attack // as this should be implemented in user interfaces // ------------------------------------------------------------------------ function approve(address spender, uint tokens) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); return true; } // ------------------------------------------------------------------------ // Transfer tokens from the from account to the to account // // The calling account must already have sufficient tokens approve(...)-d // for spending from the from account and // - From account must have sufficient balance to transfer // - Spender must have sufficient allowance to transfer // - 0 value transfers are allowed // ------------------------------------------------------------------------ function transferFrom(address from, address to, uint tokens) public returns (bool success) { balances[from] = safeSub(balances[from], tokens); allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); Transfer(from, to, tokens); return true; } // ------------------------------------------------------------------------ // Returns the amount of tokens approved by the owner that can be // transferred to the spender's account // ------------------------------------------------------------------------ function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { return allowed[tokenOwner][spender]; } // ------------------------------------------------------------------------ // Token owner can approve for spender to transferFrom(...) tokens // from the token owner's account. The spender contract function // receiveApproval(...) is then executed // ------------------------------------------------------------------------ function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { allowed[msg.sender][spender] = tokens; Approval(msg.sender, spender, tokens); ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); return true; } // ------------------------------------------------------------------------ // Don't accept ETH // ------------------------------------------------------------------------ function () public payable { revert(); } // ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------ function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); } }
// ---------------------------------------------------------------------------- // ERC20 Token, with the addition of symbol, name and decimals and assisted // token transfers // ----------------------------------------------------------------------------
LineComment
transferAnyERC20Token
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { return ERC20Interface(tokenAddress).transfer(owner, tokens); }
// ------------------------------------------------------------------------ // Owner can transfer out any accidentally sent ERC20 tokens // ------------------------------------------------------------------------
LineComment
v0.4.24+commit.e67f0147
bzzr://017d092fbdba6dec9e155baa1c645ad1cba0de70c3cde2cc5b980b9c8b8d61ba
{ "func_code_index": [ 5258, 5447 ] }
3,240
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 251, 437 ] }
3,241
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 707, 896 ] }
3,242
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1142, 1617 ] }
3,243
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2080, 2418 ] }
3,244
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2870, 3027 ] }
3,245
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
owner
function owner() public view returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 441, 525 ] }
3,246
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
isOwner
function isOwner() public view returns (bool) { return msg.sender == _owner; }
/** * @dev Returns true if the caller is the current owner. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 807, 904 ] }
3,247
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
renounceOwnership
function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1252, 1397 ] }
3,248
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1547, 1661 ] }
3,249
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Ownable
contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @dev Returns true if the caller is the current owner. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * > Note: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be aplied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
_transferOwnership
function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1762, 1996 ] }
3,250
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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); function decimals() external view returns (uint8); /** * @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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 94, 154 ] }
3,251
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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); function decimals() external view returns (uint8); /** * @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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 237, 310 ] }
3,252
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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); function decimals() external view returns (uint8); /** * @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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 534, 616 ] }
3,253
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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); function decimals() external view returns (uint8); /** * @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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 895, 983 ] }
3,254
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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); function decimals() external view returns (uint8); /** * @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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1638, 1717 ] }
3,255
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
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); function decimals() external view returns (uint8); /** * @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://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2030, 2132 ] }
3,256
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * This test is non-exhaustive, and there may be false-negatives: during the * execution of a contract's constructor, its address will be reported as * not containing a contract. * * > It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } }
/** * @dev Collection of functions related to the address type, */
NatSpecMultiLine
isContract
function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; }
/** * @dev Returns true if `account` is a contract. * * This test is non-exhaustive, and there may be false-negatives: during the * execution of a contract's constructor, its address will be reported as * not containing a contract. * * > It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 455, 882 ] }
3,257
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
getBalance
function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; }
/** * @return return the balance of `token` for certain `user` */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2053, 2241 ] }
3,258
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
getBalances
function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } }
/** * @return return the balance of multiple tokens for certain `user` */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2337, 2713 ] }
3,259
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
getFill
function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; }
/** * @return return the filled amount of order specified by `orderHash` */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2811, 2973 ] }
3,260
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
getFills
function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } }
/** * @return return the filled amount of multple orders specified by `orderHash` array */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 3086, 3442 ] }
3,261
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
getCancel
function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; }
/** * @return return true(false) if order specified by `orderHash` is(not) cancelled */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 3552, 3716 ] }
3,262
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
getCancels
function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } }
/** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 3843, 4206 ] }
3,263
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
getReferral
function getReferral( address user ) public view returns (address) { return referrals[user]; }
/** * @return return the referrer address of `user` */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 4283, 4442 ] }
3,264
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
setMakerFeeRate
function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; }
/** * @return set new rate for the maker fee received */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 4521, 4851 ] }
3,265
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
setTakerFeeRate
function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; }
/** * @return set new rate for the taker fee paid */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 4926, 5258 ] }
3,266
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeStorage
contract ExchangeStorage is Ownable { /** * @dev The minimum fee rate that the maker will receive * Note: 20% = 20 * 10^16 */ uint256 constant internal minMakerFeeRate = 200000000000000000; /** * @dev The maximum fee rate that the maker will receive * Note: 90% = 90 * 10^16 */ uint256 constant internal maxMakerFeeRate = 900000000000000000; /** * @dev The minimum fee rate that the taker will pay * Note: 0.1% = 0.1 * 10^16 */ uint256 constant internal minTakerFeeRate = 1000000000000000; /** * @dev The maximum fee rate that the taker will pay * Note: 1% = 1 * 10^16 */ uint256 constant internal maxTakerFeeRate = 10000000000000000; /** * @dev The referrer will receive 10% from each taker fee. * Note: 10% = 10 * 10^16 */ uint256 constant internal referralFeeRate = 100000000000000000; /** * @dev The amount of percentage the maker will receive from each taker fee. * Note: Initially: 50% = 50 * 10^16 */ uint256 public makerFeeRate; /** * @dev The amount of percentage the will pay for taking an order. * Note: Initially: 0.2% = 0.2 * 10^16 */ uint256 public takerFeeRate; /** * @dev 2-level map: tokenAddress -> userAddress -> balance */ mapping(address => mapping(address => uint256)) internal balances; /** * @dev map: orderHash -> filled amount */ mapping(bytes32 => uint256) internal filled; /** * @dev map: orderHash -> isCancelled */ mapping(bytes32 => bool) internal cancelled; /** * @dev map: user -> userReferrer */ mapping(address => address) internal referrals; /** * @dev The address where all exchange fees (0,08%) are kept. * Node: multisig wallet */ address public feeAccount; /** * @return return the balance of `token` for certain `user` */ function getBalance( address user, address token ) public view returns (uint256) { return balances[token][user]; } /** * @return return the balance of multiple tokens for certain `user` */ function getBalances( address user, address[] memory token ) public view returns(uint256[] memory balanceArray) { balanceArray = new uint256[](token.length); for(uint256 index = 0; index < token.length; index++) { balanceArray[index] = balances[token[index]][user]; } } /** * @return return the filled amount of order specified by `orderHash` */ function getFill( bytes32 orderHash ) public view returns (uint256) { return filled[orderHash]; } /** * @return return the filled amount of multple orders specified by `orderHash` array */ function getFills( bytes32[] memory orderHash ) public view returns (uint256[] memory filledArray) { filledArray = new uint256[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { filledArray[index] = filled[orderHash[index]]; } } /** * @return return true(false) if order specified by `orderHash` is(not) cancelled */ function getCancel( bytes32 orderHash ) public view returns (bool) { return cancelled[orderHash]; } /** * @return return array of true(false) if orders specified by `orderHash` array are(not) cancelled */ function getCancels( bytes32[] memory orderHash ) public view returns (bool[]memory cancelledArray) { cancelledArray = new bool[](orderHash.length); for(uint256 index = 0; index < orderHash.length; index++) { cancelledArray[index] = cancelled[orderHash[index]]; } } /** * @return return the referrer address of `user` */ function getReferral( address user ) public view returns (address) { return referrals[user]; } /** * @return set new rate for the maker fee received */ function setMakerFeeRate( uint256 newMakerFeeRate ) external onlyOwner { require( newMakerFeeRate >= minMakerFeeRate && newMakerFeeRate <= maxMakerFeeRate, "INVALID_MAKER_FEE_RATE" ); makerFeeRate = newMakerFeeRate; } /** * @return set new rate for the taker fee paid */ function setTakerFeeRate( uint256 newTakerFeeRate ) external onlyOwner { require( newTakerFeeRate >= minTakerFeeRate && newTakerFeeRate <= maxTakerFeeRate, "INVALID_TAKER_FEE_RATE" ); takerFeeRate = newTakerFeeRate; } /** * @return set new fee account */ function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; } }
setFeeAccount
function setFeeAccount( address newFeeAccount ) external onlyOwner { feeAccount = newFeeAccount; }
/** * @return set new fee account */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 5317, 5471 ] }
3,267
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
SafeERC20
library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
/** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */
NatSpecMultiLine
callOptionalReturn
function callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } }
/** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2082, 3201 ] }
3,268
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Exchange
contract Exchange is LibMath, LibOrder, LibSignatureValidator, ExchangeStorage { using SafeMath for uint256; /** * @dev emitted when a trade is executed */ event Trade( address indexed makerAddress, // Address that created the order address indexed takerAddress, // Address that filled the order bytes32 indexed orderHash, // Hash of the order address makerFilledAsset, // Address of assets filled for maker address takerFilledAsset, // Address of assets filled for taker uint256 makerFilledAmount, // Amount of assets filled for maker uint256 takerFilledAmount, // Amount of assets filled for taker uint256 takerFeePaid, // Amount of fee paid by the taker uint256 makerFeeReceived, // Amount of fee received by the maker uint256 referralFeeReceived // Amount of fee received by the referrer ); /** * @dev emitted when a cancel order is executed */ event Cancel( address indexed makerBuyToken, // Address of asset being bought. address makerSellToken, // Address of asset being sold. address indexed maker, // Address that created the order bytes32 indexed orderHash // Hash of the order ); /** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */ function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; } /** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */ function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); } /** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */ function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; } /** * @dev Cancel an order if msg.sender is the order signer. */ function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); } /** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */ function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); } /** * @dev Throws when the order status is invalid or the signer is not valid. */ function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; } /** * @dev Updates the contract state i.e. user balances */ function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); } }
getOrderInfo
function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; }
/** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1721, 3238 ] }
3,269
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Exchange
contract Exchange is LibMath, LibOrder, LibSignatureValidator, ExchangeStorage { using SafeMath for uint256; /** * @dev emitted when a trade is executed */ event Trade( address indexed makerAddress, // Address that created the order address indexed takerAddress, // Address that filled the order bytes32 indexed orderHash, // Hash of the order address makerFilledAsset, // Address of assets filled for maker address takerFilledAsset, // Address of assets filled for taker uint256 makerFilledAmount, // Amount of assets filled for maker uint256 takerFilledAmount, // Amount of assets filled for taker uint256 takerFeePaid, // Amount of fee paid by the taker uint256 makerFeeReceived, // Amount of fee received by the maker uint256 referralFeeReceived // Amount of fee received by the referrer ); /** * @dev emitted when a cancel order is executed */ event Cancel( address indexed makerBuyToken, // Address of asset being bought. address makerSellToken, // Address of asset being sold. address indexed maker, // Address that created the order bytes32 indexed orderHash // Hash of the order ); /** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */ function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; } /** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */ function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); } /** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */ function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; } /** * @dev Cancel an order if msg.sender is the order signer. */ function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); } /** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */ function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); } /** * @dev Throws when the order status is invalid or the signer is not valid. */ function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; } /** * @dev Updates the contract state i.e. user balances */ function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); } }
trade
function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); }
/** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 3369, 3579 ] }
3,270
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Exchange
contract Exchange is LibMath, LibOrder, LibSignatureValidator, ExchangeStorage { using SafeMath for uint256; /** * @dev emitted when a trade is executed */ event Trade( address indexed makerAddress, // Address that created the order address indexed takerAddress, // Address that filled the order bytes32 indexed orderHash, // Hash of the order address makerFilledAsset, // Address of assets filled for maker address takerFilledAsset, // Address of assets filled for taker uint256 makerFilledAmount, // Amount of assets filled for maker uint256 takerFilledAmount, // Amount of assets filled for taker uint256 takerFeePaid, // Amount of fee paid by the taker uint256 makerFeeReceived, // Amount of fee received by the maker uint256 referralFeeReceived // Amount of fee received by the referrer ); /** * @dev emitted when a cancel order is executed */ event Cancel( address indexed makerBuyToken, // Address of asset being bought. address makerSellToken, // Address of asset being sold. address indexed maker, // Address that created the order bytes32 indexed orderHash // Hash of the order ); /** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */ function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; } /** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */ function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); } /** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */ function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; } /** * @dev Cancel an order if msg.sender is the order signer. */ function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); } /** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */ function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); } /** * @dev Throws when the order status is invalid or the signer is not valid. */ function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; } /** * @dev Updates the contract state i.e. user balances */ function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); } }
_trade
function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; }
/** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 3716, 4976 ] }
3,271
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Exchange
contract Exchange is LibMath, LibOrder, LibSignatureValidator, ExchangeStorage { using SafeMath for uint256; /** * @dev emitted when a trade is executed */ event Trade( address indexed makerAddress, // Address that created the order address indexed takerAddress, // Address that filled the order bytes32 indexed orderHash, // Hash of the order address makerFilledAsset, // Address of assets filled for maker address takerFilledAsset, // Address of assets filled for taker uint256 makerFilledAmount, // Amount of assets filled for maker uint256 takerFilledAmount, // Amount of assets filled for taker uint256 takerFeePaid, // Amount of fee paid by the taker uint256 makerFeeReceived, // Amount of fee received by the maker uint256 referralFeeReceived // Amount of fee received by the referrer ); /** * @dev emitted when a cancel order is executed */ event Cancel( address indexed makerBuyToken, // Address of asset being bought. address makerSellToken, // Address of asset being sold. address indexed maker, // Address that created the order bytes32 indexed orderHash // Hash of the order ); /** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */ function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; } /** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */ function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); } /** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */ function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; } /** * @dev Cancel an order if msg.sender is the order signer. */ function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); } /** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */ function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); } /** * @dev Throws when the order status is invalid or the signer is not valid. */ function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; } /** * @dev Updates the contract state i.e. user balances */ function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); } }
cancelSingleOrder
function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); }
/** * @dev Cancel an order if msg.sender is the order signer. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 5063, 5668 ] }
3,272
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Exchange
contract Exchange is LibMath, LibOrder, LibSignatureValidator, ExchangeStorage { using SafeMath for uint256; /** * @dev emitted when a trade is executed */ event Trade( address indexed makerAddress, // Address that created the order address indexed takerAddress, // Address that filled the order bytes32 indexed orderHash, // Hash of the order address makerFilledAsset, // Address of assets filled for maker address takerFilledAsset, // Address of assets filled for taker uint256 makerFilledAmount, // Amount of assets filled for maker uint256 takerFilledAmount, // Amount of assets filled for taker uint256 takerFeePaid, // Amount of fee paid by the taker uint256 makerFeeReceived, // Amount of fee received by the maker uint256 referralFeeReceived // Amount of fee received by the referrer ); /** * @dev emitted when a cancel order is executed */ event Cancel( address indexed makerBuyToken, // Address of asset being bought. address makerSellToken, // Address of asset being sold. address indexed maker, // Address that created the order bytes32 indexed orderHash // Hash of the order ); /** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */ function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; } /** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */ function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); } /** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */ function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; } /** * @dev Cancel an order if msg.sender is the order signer. */ function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); } /** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */ function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); } /** * @dev Throws when the order status is invalid or the signer is not valid. */ function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; } /** * @dev Updates the contract state i.e. user balances */ function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); } }
getOrderFillResult
function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); }
/** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 6266, 7332 ] }
3,273
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Exchange
contract Exchange is LibMath, LibOrder, LibSignatureValidator, ExchangeStorage { using SafeMath for uint256; /** * @dev emitted when a trade is executed */ event Trade( address indexed makerAddress, // Address that created the order address indexed takerAddress, // Address that filled the order bytes32 indexed orderHash, // Hash of the order address makerFilledAsset, // Address of assets filled for maker address takerFilledAsset, // Address of assets filled for taker uint256 makerFilledAmount, // Amount of assets filled for maker uint256 takerFilledAmount, // Amount of assets filled for taker uint256 takerFeePaid, // Amount of fee paid by the taker uint256 makerFeeReceived, // Amount of fee received by the maker uint256 referralFeeReceived // Amount of fee received by the referrer ); /** * @dev emitted when a cancel order is executed */ event Cancel( address indexed makerBuyToken, // Address of asset being bought. address makerSellToken, // Address of asset being sold. address indexed maker, // Address that created the order bytes32 indexed orderHash // Hash of the order ); /** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */ function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; } /** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */ function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); } /** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */ function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; } /** * @dev Cancel an order if msg.sender is the order signer. */ function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); } /** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */ function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); } /** * @dev Throws when the order status is invalid or the signer is not valid. */ function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; } /** * @dev Updates the contract state i.e. user balances */ function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); } }
assertTakeOrder
function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; }
/** * @dev Throws when the order status is invalid or the signer is not valid. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 7436, 7951 ] }
3,274
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
Exchange
contract Exchange is LibMath, LibOrder, LibSignatureValidator, ExchangeStorage { using SafeMath for uint256; /** * @dev emitted when a trade is executed */ event Trade( address indexed makerAddress, // Address that created the order address indexed takerAddress, // Address that filled the order bytes32 indexed orderHash, // Hash of the order address makerFilledAsset, // Address of assets filled for maker address takerFilledAsset, // Address of assets filled for taker uint256 makerFilledAmount, // Amount of assets filled for maker uint256 takerFilledAmount, // Amount of assets filled for taker uint256 takerFeePaid, // Amount of fee paid by the taker uint256 makerFeeReceived, // Amount of fee received by the maker uint256 referralFeeReceived // Amount of fee received by the referrer ); /** * @dev emitted when a cancel order is executed */ event Cancel( address indexed makerBuyToken, // Address of asset being bought. address makerSellToken, // Address of asset being sold. address indexed maker, // Address that created the order bytes32 indexed orderHash // Hash of the order ); /** * @dev Compute the status of an order. * Should be called before a contract execution is performet in order to not waste gas. * @return OrderStatus.FILLABLE if the order is valid for taking. * Note: See LibOrder.sol to see all statuses */ function getOrderInfo( uint256 partialAmount, Order memory order ) public view returns (OrderInfo memory orderInfo) { // Compute the order hash orderInfo.hash = getPrefixedHash(order); // Fetch filled amount orderInfo.filledAmount = filled[orderInfo.hash]; // Check taker balance if(balances[order.makerBuyToken][order.taker] < order.takerSellAmount) { orderInfo.status = uint8(OrderStatus.INVALID_TAKER_AMOUNT); return orderInfo; } // Check maker balance if(balances[order.makerSellToken][order.maker] < partialAmount) { orderInfo.status = uint8(OrderStatus.INVALID_MAKER_AMOUNT); return orderInfo; } // Check if order is filled if (orderInfo.filledAmount.add(order.takerSellAmount) > order.makerBuyAmount) { orderInfo.status = uint8(OrderStatus.FULLY_FILLED); return orderInfo; } // Check for expiration if (block.number >= order.expiration) { orderInfo.status = uint8(OrderStatus.EXPIRED); return orderInfo; } // Check if order has been cancelled if (cancelled[orderInfo.hash]) { orderInfo.status = uint8(OrderStatus.CANCELLED); return orderInfo; } orderInfo.status = uint8(OrderStatus.FILLABLE); return orderInfo; } /** * @dev Execute a trade based on the input order and signature. * Reverts if order is not valid */ function trade( Order memory order, bytes memory signature ) public { bool result = _trade(order, signature); require(result, "INVALID_TRADE"); } /** * @dev Execute a trade based on the input order and signature. * If the order is valid returns true. */ function _trade( Order memory order, bytes memory signature ) internal returns(bool) { order.taker = msg.sender; uint256 takerReceivedAmount = getPartialAmount( order.makerSellAmount, order.makerBuyAmount, order.takerSellAmount ); OrderInfo memory orderInfo = getOrderInfo(takerReceivedAmount, order); uint8 status = assertTakeOrder(orderInfo.hash, orderInfo.status, order.maker, signature); if(status != uint8(OrderStatus.FILLABLE)) { return false; } OrderFill memory orderFill = getOrderFillResult(takerReceivedAmount, order); executeTrade(order, orderFill); filled[orderInfo.hash] = filled[orderInfo.hash].add(order.takerSellAmount); emit Trade( order.maker, order.taker, orderInfo.hash, order.makerBuyToken, order.makerSellToken, orderFill.makerFillAmount, orderFill.takerFillAmount, orderFill.takerFeePaid, orderFill.makerFeeReceived, orderFill.referralFeeReceived ); return true; } /** * @dev Cancel an order if msg.sender is the order signer. */ function cancelSingleOrder( Order memory order, bytes memory signature ) public { bytes32 orderHash = getPrefixedHash(order); require( recover(orderHash, signature) == msg.sender, "INVALID_SIGNER" ); require( cancelled[orderHash] == false, "ALREADY_CANCELLED" ); cancelled[orderHash] = true; emit Cancel( order.makerBuyToken, order.makerSellToken, msg.sender, orderHash ); } /** * @dev Computation of the following properties based on the order input: * takerFillAmount -> amount of assets received by the taker * makerFillAmount -> amount of assets received by the maker * takerFeePaid -> amount of fee paid by the taker (0.2% of takerFillAmount) * makerFeeReceived -> amount of fee received by the maker (50% of takerFeePaid) * referralFeeReceived -> amount of fee received by the taker referrer (10% of takerFeePaid) * exchangeFeeReceived -> amount of fee received by the exchange (40% of takerFeePaid) */ function getOrderFillResult( uint256 takerReceivedAmount, Order memory order ) internal view returns (OrderFill memory orderFill) { orderFill.takerFillAmount = takerReceivedAmount; orderFill.makerFillAmount = order.takerSellAmount; // 0.2% == 0.2*10^16 orderFill.takerFeePaid = getFeeAmount( takerReceivedAmount, takerFeeRate ); // 50% of taker fee == 50*10^16 orderFill.makerFeeReceived = getFeeAmount( orderFill.takerFeePaid, makerFeeRate ); // 10% of taker fee == 10*10^16 orderFill.referralFeeReceived = getFeeAmount( orderFill.takerFeePaid, referralFeeRate ); // exchangeFee = (takerFeePaid - makerFeeReceived - referralFeeReceived) orderFill.exchangeFeeReceived = orderFill.takerFeePaid.sub( orderFill.makerFeeReceived).sub( orderFill.referralFeeReceived); } /** * @dev Throws when the order status is invalid or the signer is not valid. */ function assertTakeOrder( bytes32 orderHash, uint8 status, address signer, bytes memory signature ) internal pure returns(uint8) { uint8 result = uint8(OrderStatus.FILLABLE); if(recover(orderHash, signature) != signer) { result = uint8(OrderStatus.INVALID_SIGNER); } if(status != uint8(OrderStatus.FILLABLE)) { result = status; } return status; } /** * @dev Updates the contract state i.e. user balances */ function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); } }
executeTrade
function executeTrade( Order memory order, OrderFill memory orderFill ) private { uint256 makerGiveAmount = orderFill.takerFillAmount.sub(orderFill.makerFeeReceived); uint256 takerFillAmount = orderFill.takerFillAmount.sub(orderFill.takerFeePaid); address referrer = referrals[order.taker]; address feeAddress = feeAccount; balances[order.makerSellToken][referrer] = balances[order.makerSellToken][referrer].add(orderFill.referralFeeReceived); balances[order.makerSellToken][feeAddress] = balances[order.makerSellToken][feeAddress].add(orderFill.exchangeFeeReceived); balances[order.makerBuyToken][order.taker] = balances[order.makerBuyToken][order.taker].sub(orderFill.makerFillAmount); balances[order.makerBuyToken][order.maker] = balances[order.makerBuyToken][order.maker].add(orderFill.makerFillAmount); balances[order.makerSellToken][order.taker] = balances[order.makerSellToken][order.taker].add(takerFillAmount); balances[order.makerSellToken][order.maker] = balances[order.makerSellToken][order.maker].sub(makerGiveAmount); }
/** * @dev Updates the contract state i.e. user balances */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 8033, 9211 ] }
3,275
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeKyberProxy
contract ExchangeKyberProxy is Exchange, LibKyberData { using SafeERC20 for IERC20; /** * @dev The precision used for calculating the amounts - 10*18 */ uint256 constant internal PRECISION = 1000000000000000000; /** * @dev Max decimals allowed when calculating amounts. */ uint256 constant internal MAX_DECIMALS = 18; /** * @dev Decimals of Ether. */ uint256 constant internal ETH_DECIMALS = 18; /** * @dev The address that represents ETH in Kyber Network Contracts. */ address constant internal KYBER_ETH_TOKEN_ADDRESS = address(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); uint256 constant internal MAX_DEST_AMOUNT = 2**256 - 1; /** * @dev KyberNetworkProxy contract address */ IKyberNetworkProxy constant internal kyberNetworkContract = IKyberNetworkProxy(0x818E6FECD516Ecc3849DAf6845e3EC868087B755); /** * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using KyberNetwork reserves. */ function kyberSwap( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public payable { address taker = msg.sender; KyberData memory kyberData = getSwapInfo( givenAmount, givenToken, receivedToken, taker ); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, taker, MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Exchange ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using the internal * balance mapping that keeps track of user's balances. It requires user to first invoke deposit function. * The function relies on KyberNetworkProxy contract. */ function kyberTrade( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public { address taker = msg.sender; KyberData memory kyberData = getTradeInfo( givenAmount, givenToken, receivedToken ); balances[givenToken][taker] = balances[givenToken][taker].sub(givenAmount); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, address(this), MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); balances[receivedToken][taker] = balances[receivedToken][taker].add(convertedAmount); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Helper function to determine what is being swapped. */ function getSwapInfo( uint256 givenAmount, address givenToken, address receivedToken, address taker ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { require(msg.value == givenAmount, "INVALID_ETH_VALUE"); kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } /** * @dev Helper function to determines what is being swapped using the internal balance mapping. */ function getTradeInfo( uint256 givenAmount, address givenToken, address receivedToken ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } function getExpectedRateBatch( address[] memory givenTokens, address[] memory receivedTokens, uint256[] memory givenAmounts ) public view returns(uint256[] memory, uint256[] memory) { uint256 size = givenTokens.length; uint256[] memory expectedRates = new uint256[](size); uint256[] memory slippageRates = new uint256[](size); for(uint256 index = 0; index < size; index++) { (expectedRates[index], slippageRates[index]) = kyberNetworkContract.getExpectedRate( givenTokens[index], receivedTokens[index], givenAmounts[index] ); } return (expectedRates, slippageRates); } }
kyberSwap
function kyberSwap( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public payable { address taker = msg.sender; KyberData memory kyberData = getSwapInfo( givenAmount, givenToken, receivedToken, taker ); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, taker, MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); }
/** * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using KyberNetwork reserves. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1073, 2040 ] }
3,276
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeKyberProxy
contract ExchangeKyberProxy is Exchange, LibKyberData { using SafeERC20 for IERC20; /** * @dev The precision used for calculating the amounts - 10*18 */ uint256 constant internal PRECISION = 1000000000000000000; /** * @dev Max decimals allowed when calculating amounts. */ uint256 constant internal MAX_DECIMALS = 18; /** * @dev Decimals of Ether. */ uint256 constant internal ETH_DECIMALS = 18; /** * @dev The address that represents ETH in Kyber Network Contracts. */ address constant internal KYBER_ETH_TOKEN_ADDRESS = address(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); uint256 constant internal MAX_DEST_AMOUNT = 2**256 - 1; /** * @dev KyberNetworkProxy contract address */ IKyberNetworkProxy constant internal kyberNetworkContract = IKyberNetworkProxy(0x818E6FECD516Ecc3849DAf6845e3EC868087B755); /** * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using KyberNetwork reserves. */ function kyberSwap( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public payable { address taker = msg.sender; KyberData memory kyberData = getSwapInfo( givenAmount, givenToken, receivedToken, taker ); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, taker, MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Exchange ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using the internal * balance mapping that keeps track of user's balances. It requires user to first invoke deposit function. * The function relies on KyberNetworkProxy contract. */ function kyberTrade( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public { address taker = msg.sender; KyberData memory kyberData = getTradeInfo( givenAmount, givenToken, receivedToken ); balances[givenToken][taker] = balances[givenToken][taker].sub(givenAmount); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, address(this), MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); balances[receivedToken][taker] = balances[receivedToken][taker].add(convertedAmount); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Helper function to determine what is being swapped. */ function getSwapInfo( uint256 givenAmount, address givenToken, address receivedToken, address taker ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { require(msg.value == givenAmount, "INVALID_ETH_VALUE"); kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } /** * @dev Helper function to determines what is being swapped using the internal balance mapping. */ function getTradeInfo( uint256 givenAmount, address givenToken, address receivedToken ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } function getExpectedRateBatch( address[] memory givenTokens, address[] memory receivedTokens, uint256[] memory givenAmounts ) public view returns(uint256[] memory, uint256[] memory) { uint256 size = givenTokens.length; uint256[] memory expectedRates = new uint256[](size); uint256[] memory slippageRates = new uint256[](size); for(uint256 index = 0; index < size; index++) { (expectedRates[index], slippageRates[index]) = kyberNetworkContract.getExpectedRate( givenTokens[index], receivedTokens[index], givenAmounts[index] ); } return (expectedRates, slippageRates); } }
kyberTrade
function kyberTrade( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public { address taker = msg.sender; KyberData memory kyberData = getTradeInfo( givenAmount, givenToken, receivedToken ); balances[givenToken][taker] = balances[givenToken][taker].sub(givenAmount); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, address(this), MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); balances[receivedToken][taker] = balances[receivedToken][taker].add(convertedAmount); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); }
/** * @dev Exchange ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using the internal * balance mapping that keeps track of user's balances. It requires user to first invoke deposit function. * The function relies on KyberNetworkProxy contract. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2313, 3437 ] }
3,277
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeKyberProxy
contract ExchangeKyberProxy is Exchange, LibKyberData { using SafeERC20 for IERC20; /** * @dev The precision used for calculating the amounts - 10*18 */ uint256 constant internal PRECISION = 1000000000000000000; /** * @dev Max decimals allowed when calculating amounts. */ uint256 constant internal MAX_DECIMALS = 18; /** * @dev Decimals of Ether. */ uint256 constant internal ETH_DECIMALS = 18; /** * @dev The address that represents ETH in Kyber Network Contracts. */ address constant internal KYBER_ETH_TOKEN_ADDRESS = address(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); uint256 constant internal MAX_DEST_AMOUNT = 2**256 - 1; /** * @dev KyberNetworkProxy contract address */ IKyberNetworkProxy constant internal kyberNetworkContract = IKyberNetworkProxy(0x818E6FECD516Ecc3849DAf6845e3EC868087B755); /** * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using KyberNetwork reserves. */ function kyberSwap( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public payable { address taker = msg.sender; KyberData memory kyberData = getSwapInfo( givenAmount, givenToken, receivedToken, taker ); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, taker, MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Exchange ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using the internal * balance mapping that keeps track of user's balances. It requires user to first invoke deposit function. * The function relies on KyberNetworkProxy contract. */ function kyberTrade( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public { address taker = msg.sender; KyberData memory kyberData = getTradeInfo( givenAmount, givenToken, receivedToken ); balances[givenToken][taker] = balances[givenToken][taker].sub(givenAmount); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, address(this), MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); balances[receivedToken][taker] = balances[receivedToken][taker].add(convertedAmount); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Helper function to determine what is being swapped. */ function getSwapInfo( uint256 givenAmount, address givenToken, address receivedToken, address taker ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { require(msg.value == givenAmount, "INVALID_ETH_VALUE"); kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } /** * @dev Helper function to determines what is being swapped using the internal balance mapping. */ function getTradeInfo( uint256 givenAmount, address givenToken, address receivedToken ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } function getExpectedRateBatch( address[] memory givenTokens, address[] memory receivedTokens, uint256[] memory givenAmounts ) public view returns(uint256[] memory, uint256[] memory) { uint256 size = givenTokens.length; uint256[] memory expectedRates = new uint256[](size); uint256[] memory slippageRates = new uint256[](size); for(uint256 index = 0; index < size; index++) { (expectedRates[index], slippageRates[index]) = kyberNetworkContract.getExpectedRate( givenTokens[index], receivedTokens[index], givenAmounts[index] ); } return (expectedRates, slippageRates); } }
getSwapInfo
function getSwapInfo( uint256 givenAmount, address givenToken, address receivedToken, address taker ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { require(msg.value == givenAmount, "INVALID_ETH_VALUE"); kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; }
/** * @dev Helper function to determine what is being swapped. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 3525, 5427 ] }
3,278
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeKyberProxy
contract ExchangeKyberProxy is Exchange, LibKyberData { using SafeERC20 for IERC20; /** * @dev The precision used for calculating the amounts - 10*18 */ uint256 constant internal PRECISION = 1000000000000000000; /** * @dev Max decimals allowed when calculating amounts. */ uint256 constant internal MAX_DECIMALS = 18; /** * @dev Decimals of Ether. */ uint256 constant internal ETH_DECIMALS = 18; /** * @dev The address that represents ETH in Kyber Network Contracts. */ address constant internal KYBER_ETH_TOKEN_ADDRESS = address(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); uint256 constant internal MAX_DEST_AMOUNT = 2**256 - 1; /** * @dev KyberNetworkProxy contract address */ IKyberNetworkProxy constant internal kyberNetworkContract = IKyberNetworkProxy(0x818E6FECD516Ecc3849DAf6845e3EC868087B755); /** * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using KyberNetwork reserves. */ function kyberSwap( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public payable { address taker = msg.sender; KyberData memory kyberData = getSwapInfo( givenAmount, givenToken, receivedToken, taker ); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, taker, MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Exchange ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using the internal * balance mapping that keeps track of user's balances. It requires user to first invoke deposit function. * The function relies on KyberNetworkProxy contract. */ function kyberTrade( uint256 givenAmount, address givenToken, address receivedToken, bytes32 hash ) public { address taker = msg.sender; KyberData memory kyberData = getTradeInfo( givenAmount, givenToken, receivedToken ); balances[givenToken][taker] = balances[givenToken][taker].sub(givenAmount); uint256 convertedAmount = kyberNetworkContract.trade.value(kyberData.value)( kyberData.givenToken, givenAmount, kyberData.receivedToken, address(this), MAX_DEST_AMOUNT, kyberData.rate, feeAccount ); balances[receivedToken][taker] = balances[receivedToken][taker].add(convertedAmount); emit Trade( address(kyberNetworkContract), taker, hash, givenToken, receivedToken, givenAmount, convertedAmount, 0, 0, 0 ); } /** * @dev Helper function to determine what is being swapped. */ function getSwapInfo( uint256 givenAmount, address givenToken, address receivedToken, address taker ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { require(msg.value == givenAmount, "INVALID_ETH_VALUE"); kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeTransferFrom(taker, address(this), givenAmount); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } /** * @dev Helper function to determines what is being swapped using the internal balance mapping. */ function getTradeInfo( uint256 givenAmount, address givenToken, address receivedToken ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; } function getExpectedRateBatch( address[] memory givenTokens, address[] memory receivedTokens, uint256[] memory givenAmounts ) public view returns(uint256[] memory, uint256[] memory) { uint256 size = givenTokens.length; uint256[] memory expectedRates = new uint256[](size); uint256[] memory slippageRates = new uint256[](size); for(uint256 index = 0; index < size; index++) { (expectedRates[index], slippageRates[index]) = kyberNetworkContract.getExpectedRate( givenTokens[index], receivedTokens[index], givenAmounts[index] ); } return (expectedRates, slippageRates); } }
getTradeInfo
function getTradeInfo( uint256 givenAmount, address givenToken, address receivedToken ) private returns(KyberData memory) { KyberData memory kyberData; uint256 givenTokenDecimals; uint256 receivedTokenDecimals; if(givenToken == address(0x0)) { kyberData.givenToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.receivedToken = receivedToken; kyberData.value = givenAmount; givenTokenDecimals = ETH_DECIMALS; receivedTokenDecimals = IERC20(receivedToken).decimals(); } else if(receivedToken == address(0x0)) { kyberData.givenToken = givenToken; kyberData.receivedToken = KYBER_ETH_TOKEN_ADDRESS; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = ETH_DECIMALS; IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } else { kyberData.givenToken = givenToken; kyberData.receivedToken = receivedToken; kyberData.value = 0; givenTokenDecimals = IERC20(givenToken).decimals(); receivedTokenDecimals = IERC20(receivedToken).decimals(); IERC20(givenToken).safeApprove(address(kyberNetworkContract), givenAmount); } (kyberData.rate, ) = kyberNetworkContract.getExpectedRate( kyberData.givenToken, kyberData.receivedToken, givenAmount ); return kyberData; }
/** * @dev Helper function to determines what is being swapped using the internal balance mapping. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 5560, 7194 ] }
3,279
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeBatchTrade
contract ExchangeBatchTrade is Exchange { /** * @dev Cancel an array of orders if msg.sender is the order signer. */ function cancelMultipleOrders( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { cancelSingleOrder( orders[index], signatures[index] ); } } /** * @dev Execute multiple trades based on the input orders and signatures. * Note: reverts of one or more trades fail. */ function takeAllOrRevert( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { bool result = _trade(orders[index], signatures[index]); require(result, "INVALID_TAKEALL"); } } /** * @dev Execute multiple trades based on the input orders and signatures. * Note: does not revert if one or more trades fail. */ function takeAllPossible( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { _trade(orders[index], signatures[index]); } } }
cancelMultipleOrders
function cancelMultipleOrders( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { cancelSingleOrder( orders[index], signatures[index] ); } }
/** * @dev Cancel an array of orders if msg.sender is the order signer. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 139, 471 ] }
3,280
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeBatchTrade
contract ExchangeBatchTrade is Exchange { /** * @dev Cancel an array of orders if msg.sender is the order signer. */ function cancelMultipleOrders( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { cancelSingleOrder( orders[index], signatures[index] ); } } /** * @dev Execute multiple trades based on the input orders and signatures. * Note: reverts of one or more trades fail. */ function takeAllOrRevert( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { bool result = _trade(orders[index], signatures[index]); require(result, "INVALID_TAKEALL"); } } /** * @dev Execute multiple trades based on the input orders and signatures. * Note: does not revert if one or more trades fail. */ function takeAllPossible( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { _trade(orders[index], signatures[index]); } } }
takeAllOrRevert
function takeAllOrRevert( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { bool result = _trade(orders[index], signatures[index]); require(result, "INVALID_TAKEALL"); } }
/** * @dev Execute multiple trades based on the input orders and signatures. * Note: reverts of one or more trades fail. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 624, 954 ] }
3,281
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeBatchTrade
contract ExchangeBatchTrade is Exchange { /** * @dev Cancel an array of orders if msg.sender is the order signer. */ function cancelMultipleOrders( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { cancelSingleOrder( orders[index], signatures[index] ); } } /** * @dev Execute multiple trades based on the input orders and signatures. * Note: reverts of one or more trades fail. */ function takeAllOrRevert( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { bool result = _trade(orders[index], signatures[index]); require(result, "INVALID_TAKEALL"); } } /** * @dev Execute multiple trades based on the input orders and signatures. * Note: does not revert if one or more trades fail. */ function takeAllPossible( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { _trade(orders[index], signatures[index]); } } }
takeAllPossible
function takeAllPossible( Order[] memory orders, bytes[] memory signatures ) public { for (uint256 index = 0; index < orders.length; index++) { _trade(orders[index], signatures[index]); } }
/** * @dev Execute multiple trades based on the input orders and signatures. * Note: does not revert if one or more trades fail. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1115, 1382 ] }
3,282
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeMovements
contract ExchangeMovements is ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev emitted when a deposit is received */ event Deposit( address indexed token, address indexed user, address indexed referral, address beneficiary, uint256 amount, uint256 balance ); /** * @dev emitted when a withdraw is received */ event Withdraw( address indexed token, address indexed user, uint256 amount, uint256 balance ); /** * @dev emitted when a transfer is received */ event Transfer( address indexed token, address indexed user, address indexed beneficiary, uint256 amount, uint256 userBalance, uint256 beneficiaryBalance ); /** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */ function deposit( address token, uint256 amount, address beneficiary, address referral ) public payable { uint256 value = amount; address user = msg.sender; if(token == address(0x0)) { value = msg.value; } else { IERC20(token).safeTransferFrom(user, address(this), value); } balances[token][beneficiary] = balances[token][beneficiary].add(value); if(referrals[user] == address(0x0)) { referrals[user] = referral; } emit Deposit( token, user, referrals[user], beneficiary, value, balances[token][beneficiary] ); } /** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */ function withdraw( address token, uint amount ) public { address payable user = msg.sender; require( balances[token][user] >= amount, "INVALID_WITHDRAW" ); balances[token][user] = balances[token][user].sub(amount); if (token == address(0x0)) { user.transfer(amount); } else { IERC20(token).safeTransfer(user, amount); } emit Withdraw( token, user, amount, balances[token][user] ); } /** * @dev Transfer assets between two users inside the exchange. Updates the level 2 map `balances` */ function transfer( address token, address to, uint256 amount ) external payable { address user = msg.sender; require( balances[token][user] >= amount, "INVALID_TRANSFER" ); balances[token][user] = balances[token][user].sub(amount); balances[token][to] = balances[token][to].add(amount); emit Transfer( token, user, to, amount, balances[token][user], balances[token][to] ); } }
deposit
function deposit( address token, uint256 amount, address beneficiary, address referral ) public payable { uint256 value = amount; address user = msg.sender; if(token == address(0x0)) { value = msg.value; } else { IERC20(token).safeTransferFrom(user, address(this), value); } balances[token][beneficiary] = balances[token][beneficiary].add(value); if(referrals[user] == address(0x0)) { referrals[user] = referral; } emit Deposit( token, user, referrals[user], beneficiary, value, balances[token][beneficiary] ); }
/** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1058, 1859 ] }
3,283
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeMovements
contract ExchangeMovements is ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev emitted when a deposit is received */ event Deposit( address indexed token, address indexed user, address indexed referral, address beneficiary, uint256 amount, uint256 balance ); /** * @dev emitted when a withdraw is received */ event Withdraw( address indexed token, address indexed user, uint256 amount, uint256 balance ); /** * @dev emitted when a transfer is received */ event Transfer( address indexed token, address indexed user, address indexed beneficiary, uint256 amount, uint256 userBalance, uint256 beneficiaryBalance ); /** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */ function deposit( address token, uint256 amount, address beneficiary, address referral ) public payable { uint256 value = amount; address user = msg.sender; if(token == address(0x0)) { value = msg.value; } else { IERC20(token).safeTransferFrom(user, address(this), value); } balances[token][beneficiary] = balances[token][beneficiary].add(value); if(referrals[user] == address(0x0)) { referrals[user] = referral; } emit Deposit( token, user, referrals[user], beneficiary, value, balances[token][beneficiary] ); } /** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */ function withdraw( address token, uint amount ) public { address payable user = msg.sender; require( balances[token][user] >= amount, "INVALID_WITHDRAW" ); balances[token][user] = balances[token][user].sub(amount); if (token == address(0x0)) { user.transfer(amount); } else { IERC20(token).safeTransfer(user, amount); } emit Withdraw( token, user, amount, balances[token][user] ); } /** * @dev Transfer assets between two users inside the exchange. Updates the level 2 map `balances` */ function transfer( address token, address to, uint256 amount ) external payable { address user = msg.sender; require( balances[token][user] >= amount, "INVALID_TRANSFER" ); balances[token][user] = balances[token][user].sub(amount); balances[token][to] = balances[token][to].add(amount); emit Transfer( token, user, to, amount, balances[token][user], balances[token][to] ); } }
withdraw
function withdraw( address token, uint amount ) public { address payable user = msg.sender; require( balances[token][user] >= amount, "INVALID_WITHDRAW" ); balances[token][user] = balances[token][user].sub(amount); if (token == address(0x0)) { user.transfer(amount); } else { IERC20(token).safeTransfer(user, amount); } emit Withdraw( token, user, amount, balances[token][user] ); }
/** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2020, 2642 ] }
3,284
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeMovements
contract ExchangeMovements is ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev emitted when a deposit is received */ event Deposit( address indexed token, address indexed user, address indexed referral, address beneficiary, uint256 amount, uint256 balance ); /** * @dev emitted when a withdraw is received */ event Withdraw( address indexed token, address indexed user, uint256 amount, uint256 balance ); /** * @dev emitted when a transfer is received */ event Transfer( address indexed token, address indexed user, address indexed beneficiary, uint256 amount, uint256 userBalance, uint256 beneficiaryBalance ); /** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */ function deposit( address token, uint256 amount, address beneficiary, address referral ) public payable { uint256 value = amount; address user = msg.sender; if(token == address(0x0)) { value = msg.value; } else { IERC20(token).safeTransferFrom(user, address(this), value); } balances[token][beneficiary] = balances[token][beneficiary].add(value); if(referrals[user] == address(0x0)) { referrals[user] = referral; } emit Deposit( token, user, referrals[user], beneficiary, value, balances[token][beneficiary] ); } /** * @dev Updates the level 2 map `balances` based on the input * Note: token address is (0x0) when the deposit is for ETH */ function withdraw( address token, uint amount ) public { address payable user = msg.sender; require( balances[token][user] >= amount, "INVALID_WITHDRAW" ); balances[token][user] = balances[token][user].sub(amount); if (token == address(0x0)) { user.transfer(amount); } else { IERC20(token).safeTransfer(user, amount); } emit Withdraw( token, user, amount, balances[token][user] ); } /** * @dev Transfer assets between two users inside the exchange. Updates the level 2 map `balances` */ function transfer( address token, address to, uint256 amount ) external payable { address user = msg.sender; require( balances[token][user] >= amount, "INVALID_TRANSFER" ); balances[token][user] = balances[token][user].sub(amount); balances[token][to] = balances[token][to].add(amount); emit Transfer( token, user, to, amount, balances[token][user], balances[token][to] ); } }
transfer
function transfer( address token, address to, uint256 amount ) external payable { address user = msg.sender; require( balances[token][user] >= amount, "INVALID_TRANSFER" ); balances[token][user] = balances[token][user].sub(amount); balances[token][to] = balances[token][to].add(amount); emit Transfer( token, user, to, amount, balances[token][user], balances[token][to] ); }
/** * @dev Transfer assets between two users inside the exchange. Updates the level 2 map `balances` */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2768, 3382 ] }
3,285
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeUpgradability
contract ExchangeUpgradability is Ownable, ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev version of the exchange */ uint8 constant public VERSION = 1; /** * @dev the address of the upgraded exchange contract */ address public newExchange; /** * @dev flag to allow migrating to an upgraded contract */ bool public migrationAllowed; /** * @dev emitted when funds are migrated */ event FundsMigrated(address indexed user, address indexed newExchange); /** * @dev Owner can set the address of the new version of the exchange contract. */ function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; } /** * @dev Enables/Disables the migrations. Can be called only by the owner. */ function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; } /** * @dev Migrating assets of the caller to the new exchange contract */ function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); } /** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */ function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } } /** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */ function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } } /** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */ function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants } /** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */ function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); } }
setNewExchangeAddress
function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; }
/** * @dev Owner can set the address of the new version of the exchange contract. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 707, 844 ] }
3,286
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeUpgradability
contract ExchangeUpgradability is Ownable, ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev version of the exchange */ uint8 constant public VERSION = 1; /** * @dev the address of the upgraded exchange contract */ address public newExchange; /** * @dev flag to allow migrating to an upgraded contract */ bool public migrationAllowed; /** * @dev emitted when funds are migrated */ event FundsMigrated(address indexed user, address indexed newExchange); /** * @dev Owner can set the address of the new version of the exchange contract. */ function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; } /** * @dev Enables/Disables the migrations. Can be called only by the owner. */ function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; } /** * @dev Migrating assets of the caller to the new exchange contract */ function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); } /** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */ function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } } /** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */ function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } } /** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */ function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants } /** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */ function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); } }
allowOrRestrictMigrations
function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; }
/** * @dev Enables/Disables the migrations. Can be called only by the owner. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 942, 1081 ] }
3,287
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeUpgradability
contract ExchangeUpgradability is Ownable, ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev version of the exchange */ uint8 constant public VERSION = 1; /** * @dev the address of the upgraded exchange contract */ address public newExchange; /** * @dev flag to allow migrating to an upgraded contract */ bool public migrationAllowed; /** * @dev emitted when funds are migrated */ event FundsMigrated(address indexed user, address indexed newExchange); /** * @dev Owner can set the address of the new version of the exchange contract. */ function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; } /** * @dev Enables/Disables the migrations. Can be called only by the owner. */ function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; } /** * @dev Migrating assets of the caller to the new exchange contract */ function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); } /** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */ function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } } /** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */ function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } } /** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */ function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants } /** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */ function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); } }
migrateFunds
function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); }
/** * @dev Migrating assets of the caller to the new exchange contract */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1173, 1604 ] }
3,288
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeUpgradability
contract ExchangeUpgradability is Ownable, ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev version of the exchange */ uint8 constant public VERSION = 1; /** * @dev the address of the upgraded exchange contract */ address public newExchange; /** * @dev flag to allow migrating to an upgraded contract */ bool public migrationAllowed; /** * @dev emitted when funds are migrated */ event FundsMigrated(address indexed user, address indexed newExchange); /** * @dev Owner can set the address of the new version of the exchange contract. */ function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; } /** * @dev Enables/Disables the migrations. Can be called only by the owner. */ function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; } /** * @dev Migrating assets of the caller to the new exchange contract */ function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); } /** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */ function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } } /** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */ function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } } /** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */ function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants } /** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */ function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); } }
migrateEthers
function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } }
/** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 1723, 2044 ] }
3,289
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeUpgradability
contract ExchangeUpgradability is Ownable, ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev version of the exchange */ uint8 constant public VERSION = 1; /** * @dev the address of the upgraded exchange contract */ address public newExchange; /** * @dev flag to allow migrating to an upgraded contract */ bool public migrationAllowed; /** * @dev emitted when funds are migrated */ event FundsMigrated(address indexed user, address indexed newExchange); /** * @dev Owner can set the address of the new version of the exchange contract. */ function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; } /** * @dev Enables/Disables the migrations. Can be called only by the owner. */ function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; } /** * @dev Migrating assets of the caller to the new exchange contract */ function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); } /** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */ function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } } /** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */ function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } } /** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */ function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants } /** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */ function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); } }
migrateTokens
function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } }
/** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2163, 2804 ] }
3,290
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeUpgradability
contract ExchangeUpgradability is Ownable, ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev version of the exchange */ uint8 constant public VERSION = 1; /** * @dev the address of the upgraded exchange contract */ address public newExchange; /** * @dev flag to allow migrating to an upgraded contract */ bool public migrationAllowed; /** * @dev emitted when funds are migrated */ event FundsMigrated(address indexed user, address indexed newExchange); /** * @dev Owner can set the address of the new version of the exchange contract. */ function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; } /** * @dev Enables/Disables the migrations. Can be called only by the owner. */ function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; } /** * @dev Migrating assets of the caller to the new exchange contract */ function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); } /** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */ function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } } /** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */ function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } } /** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */ function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants } /** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */ function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); } }
importEthers
function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants }
/** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 2932, 3550 ] }
3,291
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeUpgradability
contract ExchangeUpgradability is Ownable, ExchangeStorage { using SafeERC20 for IERC20; using SafeMath for uint256; /** * @dev version of the exchange */ uint8 constant public VERSION = 1; /** * @dev the address of the upgraded exchange contract */ address public newExchange; /** * @dev flag to allow migrating to an upgraded contract */ bool public migrationAllowed; /** * @dev emitted when funds are migrated */ event FundsMigrated(address indexed user, address indexed newExchange); /** * @dev Owner can set the address of the new version of the exchange contract. */ function setNewExchangeAddress(address exchange) external onlyOwner { newExchange = exchange; } /** * @dev Enables/Disables the migrations. Can be called only by the owner. */ function allowOrRestrictMigrations() external onlyOwner { migrationAllowed = !migrationAllowed; } /** * @dev Migrating assets of the caller to the new exchange contract */ function migrateFunds(address[] calldata tokens) external { require( false != migrationAllowed, "MIGRATIONS_DISALLOWED" ); require( IExchangeUpgradability(newExchange).VERSION() > VERSION, "INVALID_VERSION" ); migrateEthers(); migrateTokens(tokens); emit FundsMigrated(msg.sender, newExchange); } /** * @dev Helper function to migrate user's Ethers. Should be called in migrateFunds() function. */ function migrateEthers() private { address user = msg.sender; uint256 etherAmount = balances[address(0x0)][user]; if (etherAmount > 0) { balances[address(0x0)][user] = 0; IExchangeUpgradability(newExchange).importEthers.value(etherAmount)(user); } } /** * @dev Helper function to migrate user's tokens. Should be called in migrateFunds() function. */ function migrateTokens(address[] memory tokens) private { address user = msg.sender; address exchange = newExchange; for (uint256 index = 0; index < tokens.length; index++) { address tokenAddress = tokens[index]; uint256 tokenAmount = balances[tokenAddress][user]; if (0 == tokenAmount) { continue; } IERC20(tokenAddress).safeApprove(exchange, tokenAmount); balances[tokenAddress][user] = 0; IExchangeUpgradability(exchange).importTokens(tokenAddress, tokenAmount, user); } } /** * @dev Helper function to migrate user's Ethers. Should be called only from the new exchange contract. */ function importEthers(address user) external payable { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( user != address(0x0), "INVALID_USER" ); require( msg.value > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); balances[address(0x0)][user] = balances[address(0x0)][user].add(msg.value); // todo: constants } /** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */ function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); } }
importTokens
function importTokens( address token, uint256 amount, address user ) external { require( false != migrationAllowed, "MIGRATION_DISALLOWED" ); require( token != address(0x0), "INVALID_TOKEN" ); require( user != address(0x0), "INVALID_USER" ); require( amount > 0, "INVALID_AMOUNT" ); require( IExchangeUpgradability(msg.sender).VERSION() < VERSION, "INVALID_VERSION" ); IERC20(token).safeTransferFrom(msg.sender, address(this), amount); balances[token][user] = balances[token][user].add(amount); }
/** * @dev Helper function to migrate user's Tokens. Should be called only from the new exchange contract. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 3682, 4484 ] }
3,292
WeiDex
WeiDex.sol
0x2bde6edff9304ead741ff7f4e0a1a636135cba2c
Solidity
ExchangeSwap
contract ExchangeSwap is Exchange, ExchangeMovements { /** * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using off-chain signed messages. * The flow of the function is Deposit -> Trade -> Withdraw to allow users to directly * take liquidity without the need of deposit and withdraw. */ function swapFill( Order[] memory orders, bytes[] memory signatures, uint256 givenAmount, address givenToken, address receivedToken, address referral ) public payable { address taker = msg.sender; uint256 balanceGivenBefore = balances[givenToken][taker]; uint256 balanceReceivedBefore = balances[receivedToken][taker]; deposit(givenToken, givenAmount, taker, referral); for (uint256 index = 0; index < orders.length; index++) { require(orders[index].makerBuyToken == givenToken, "GIVEN_TOKEN"); require(orders[index].makerSellToken == receivedToken, "RECEIVED_TOKEN"); _trade(orders[index], signatures[index]); } uint256 balanceGivenAfter = balances[givenToken][taker]; uint256 balanceReceivedAfter = balances[receivedToken][taker]; uint256 balanceGivenDelta = balanceGivenAfter.sub(balanceGivenBefore); uint256 balanceReceivedDelta = balanceReceivedAfter.sub(balanceReceivedBefore); if(balanceGivenDelta > 0) { withdraw(givenToken, balanceGivenDelta); } if(balanceReceivedDelta > 0) { withdraw(receivedToken, balanceReceivedDelta); } } }
swapFill
function swapFill( Order[] memory orders, bytes[] memory signatures, uint256 givenAmount, address givenToken, address receivedToken, address referral ) public payable { address taker = msg.sender; uint256 balanceGivenBefore = balances[givenToken][taker]; uint256 balanceReceivedBefore = balances[receivedToken][taker]; deposit(givenToken, givenAmount, taker, referral); for (uint256 index = 0; index < orders.length; index++) { require(orders[index].makerBuyToken == givenToken, "GIVEN_TOKEN"); require(orders[index].makerSellToken == receivedToken, "RECEIVED_TOKEN"); _trade(orders[index], signatures[index]); } uint256 balanceGivenAfter = balances[givenToken][taker]; uint256 balanceReceivedAfter = balances[receivedToken][taker]; uint256 balanceGivenDelta = balanceGivenAfter.sub(balanceGivenBefore); uint256 balanceReceivedDelta = balanceReceivedAfter.sub(balanceReceivedBefore); if(balanceGivenDelta > 0) { withdraw(givenToken, balanceGivenDelta); } if(balanceReceivedDelta > 0) { withdraw(receivedToken, balanceReceivedDelta); } }
/** * @dev Swaps ETH/TOKEN, TOKEN/ETH or TOKEN/TOKEN using off-chain signed messages. * The flow of the function is Deposit -> Trade -> Withdraw to allow users to directly * take liquidity without the need of deposit and withdraw. */
NatSpecMultiLine
v0.5.10+commit.5a6ea5b1
bzzr://b58a6ab95c800b680478fb92810bd8eaa1fae0f568cede962069c0bcf7f41146
{ "func_code_index": [ 326, 1661 ] }
3,293
CryptoCrowd
CryptoCrowd.sol
0x2df816710cd7ed473718bf0da9a8fdc4e982a130
Solidity
CryptoCrowd
contract CryptoCrowd is Context, IERC20, Ownable { using SafeMath for uint256; string private constant _name = "Crypto Crowd";// string private constant _symbol = "CROWD";// uint8 private constant _decimals = 9; mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _redisFeeOnBuy = 1; uint256 private _taxFeeOnBuy = 9; uint256 private _redisFeeOnSell = 1; uint256 private _taxFeeOnSell = 19; //Original Fee uint256 private _redisFee = _redisFeeOnSell; uint256 private _taxFee = _taxFeeOnSell; uint256 private _previousredisFee = _redisFee; uint256 private _previoustaxFee = _taxFee; mapping(address => bool) public bots; mapping (address => uint256) public _buyMap; address payable private _developmentAddress = payable(0xA76aCe0845138dc256E70102f3951813bFE6CC8b); address payable private _marketingAddress = payable(0x158e9b2322A4542F3FFc97cbEc269aBa3C8af848); IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = true; uint256 public _maxTxAmount = 10000 * 10**9; uint256 public _maxWalletSize = 1000000 * 10**9; uint256 public _swapTokensAtAmount = 10000 * 10**9; event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor() { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);// uniswapV2Router = _uniswapV2Router; uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_developmentAddress] = true; _isExcludedFromFee[_marketingAddress] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function tokenFromReflection(uint256 rAmount) private view returns (uint256) { require( rAmount <= _rTotal, "Amount must be less than total reflections" ); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function removeAllFee() private { if (_redisFee == 0 && _taxFee == 0) return; _previousredisFee = _redisFee; _previoustaxFee = _taxFee; _redisFee = 0; _taxFee = 0; } function restoreAllFee() private { _redisFee = _previousredisFee; _taxFee = _previoustaxFee; } function _approve( address owner, address spender, uint256 amount ) private { 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 _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) { //Trade start check if (!tradingOpen) { require(from == owner(), "TOKEN: This account cannot send tokens until trading is enabled"); } require(amount <= _maxTxAmount, "TOKEN: Max Transaction Limit"); require(!bots[from] && !bots[to], "TOKEN: Your account is blacklisted!"); if(to != uniswapV2Pair) { require(balanceOf(to) + amount < _maxWalletSize, "TOKEN: Balance exceeds wallet size!"); } uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= _swapTokensAtAmount; if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } if (canSwap && !inSwap && from != uniswapV2Pair && swapEnabled && !_isExcludedFromFee[from] && !_isExcludedFromFee[to]) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; //Transfer Tokens if ((_isExcludedFromFee[from] || _isExcludedFromFee[to]) || (from != uniswapV2Pair && to != uniswapV2Pair)) { takeFee = false; } else { //Set Fee for Buys if(from == uniswapV2Pair && to != address(uniswapV2Router)) { _redisFee = _redisFeeOnBuy; _taxFee = _taxFeeOnBuy; } //Set Fee for Sells if (to == uniswapV2Pair && from != address(uniswapV2Router)) { _redisFee = _redisFeeOnSell; _taxFee = _taxFeeOnSell; } } _tokenTransfer(from, to, amount, takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _marketingAddress.transfer(amount); } function setTrading(bool _tradingOpen) public onlyOwner { tradingOpen = _tradingOpen; } function manualswap() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function blockBots(address[] memory bots_) public onlyOwner { for (uint256 i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function unblockBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _redisFee, _taxFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues( uint256 tAmount, uint256 redisFee, uint256 taxFee ) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(redisFee).div(100); uint256 tTeam = tAmount.mul(taxFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues( uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate ) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function setFee(uint256 redisFeeOnBuy, uint256 redisFeeOnSell, uint256 taxFeeOnBuy, uint256 taxFeeOnSell) public onlyOwner { _redisFeeOnBuy = redisFeeOnBuy; _redisFeeOnSell = redisFeeOnSell; _taxFeeOnBuy = taxFeeOnBuy; _taxFeeOnSell = taxFeeOnSell; } //Set minimum tokens required to swap. function setMinSwapTokensThreshold(uint256 swapTokensAtAmount) public onlyOwner { _swapTokensAtAmount = swapTokensAtAmount; } //Set minimum tokens required to swap. function toggleSwap(bool _swapEnabled) public onlyOwner { swapEnabled = _swapEnabled; } //Set maximum transaction function setMaxTxnAmount(uint256 maxTxAmount) public onlyOwner { _maxTxAmount = maxTxAmount; } function setMaxWalletSize(uint256 maxWalletSize) public onlyOwner { _maxWalletSize = maxWalletSize; } function excludeMultipleAccountsFromFees(address[] calldata accounts, bool excluded) public onlyOwner { for(uint256 i = 0; i < accounts.length; i++) { _isExcludedFromFee[accounts[i]] = excluded; } } }
setMinSwapTokensThreshold
function setMinSwapTokensThreshold(uint256 swapTokensAtAmount) public onlyOwner { _swapTokensAtAmount = swapTokensAtAmount; }
//Set minimum tokens required to swap.
LineComment
v0.8.9+commit.e5eed63a
Unlicense
ipfs://fc822de242e02f4f76ff67d402acb10718a7cfde87916945cf468a1821d19f03
{ "func_code_index": [ 12715, 12859 ] }
3,294
CryptoCrowd
CryptoCrowd.sol
0x2df816710cd7ed473718bf0da9a8fdc4e982a130
Solidity
CryptoCrowd
contract CryptoCrowd is Context, IERC20, Ownable { using SafeMath for uint256; string private constant _name = "Crypto Crowd";// string private constant _symbol = "CROWD";// uint8 private constant _decimals = 9; mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _redisFeeOnBuy = 1; uint256 private _taxFeeOnBuy = 9; uint256 private _redisFeeOnSell = 1; uint256 private _taxFeeOnSell = 19; //Original Fee uint256 private _redisFee = _redisFeeOnSell; uint256 private _taxFee = _taxFeeOnSell; uint256 private _previousredisFee = _redisFee; uint256 private _previoustaxFee = _taxFee; mapping(address => bool) public bots; mapping (address => uint256) public _buyMap; address payable private _developmentAddress = payable(0xA76aCe0845138dc256E70102f3951813bFE6CC8b); address payable private _marketingAddress = payable(0x158e9b2322A4542F3FFc97cbEc269aBa3C8af848); IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = true; uint256 public _maxTxAmount = 10000 * 10**9; uint256 public _maxWalletSize = 1000000 * 10**9; uint256 public _swapTokensAtAmount = 10000 * 10**9; event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor() { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);// uniswapV2Router = _uniswapV2Router; uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_developmentAddress] = true; _isExcludedFromFee[_marketingAddress] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function tokenFromReflection(uint256 rAmount) private view returns (uint256) { require( rAmount <= _rTotal, "Amount must be less than total reflections" ); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function removeAllFee() private { if (_redisFee == 0 && _taxFee == 0) return; _previousredisFee = _redisFee; _previoustaxFee = _taxFee; _redisFee = 0; _taxFee = 0; } function restoreAllFee() private { _redisFee = _previousredisFee; _taxFee = _previoustaxFee; } function _approve( address owner, address spender, uint256 amount ) private { 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 _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) { //Trade start check if (!tradingOpen) { require(from == owner(), "TOKEN: This account cannot send tokens until trading is enabled"); } require(amount <= _maxTxAmount, "TOKEN: Max Transaction Limit"); require(!bots[from] && !bots[to], "TOKEN: Your account is blacklisted!"); if(to != uniswapV2Pair) { require(balanceOf(to) + amount < _maxWalletSize, "TOKEN: Balance exceeds wallet size!"); } uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= _swapTokensAtAmount; if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } if (canSwap && !inSwap && from != uniswapV2Pair && swapEnabled && !_isExcludedFromFee[from] && !_isExcludedFromFee[to]) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; //Transfer Tokens if ((_isExcludedFromFee[from] || _isExcludedFromFee[to]) || (from != uniswapV2Pair && to != uniswapV2Pair)) { takeFee = false; } else { //Set Fee for Buys if(from == uniswapV2Pair && to != address(uniswapV2Router)) { _redisFee = _redisFeeOnBuy; _taxFee = _taxFeeOnBuy; } //Set Fee for Sells if (to == uniswapV2Pair && from != address(uniswapV2Router)) { _redisFee = _redisFeeOnSell; _taxFee = _taxFeeOnSell; } } _tokenTransfer(from, to, amount, takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _marketingAddress.transfer(amount); } function setTrading(bool _tradingOpen) public onlyOwner { tradingOpen = _tradingOpen; } function manualswap() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function blockBots(address[] memory bots_) public onlyOwner { for (uint256 i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function unblockBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _redisFee, _taxFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues( uint256 tAmount, uint256 redisFee, uint256 taxFee ) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(redisFee).div(100); uint256 tTeam = tAmount.mul(taxFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues( uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate ) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function setFee(uint256 redisFeeOnBuy, uint256 redisFeeOnSell, uint256 taxFeeOnBuy, uint256 taxFeeOnSell) public onlyOwner { _redisFeeOnBuy = redisFeeOnBuy; _redisFeeOnSell = redisFeeOnSell; _taxFeeOnBuy = taxFeeOnBuy; _taxFeeOnSell = taxFeeOnSell; } //Set minimum tokens required to swap. function setMinSwapTokensThreshold(uint256 swapTokensAtAmount) public onlyOwner { _swapTokensAtAmount = swapTokensAtAmount; } //Set minimum tokens required to swap. function toggleSwap(bool _swapEnabled) public onlyOwner { swapEnabled = _swapEnabled; } //Set maximum transaction function setMaxTxnAmount(uint256 maxTxAmount) public onlyOwner { _maxTxAmount = maxTxAmount; } function setMaxWalletSize(uint256 maxWalletSize) public onlyOwner { _maxWalletSize = maxWalletSize; } function excludeMultipleAccountsFromFees(address[] calldata accounts, bool excluded) public onlyOwner { for(uint256 i = 0; i < accounts.length; i++) { _isExcludedFromFee[accounts[i]] = excluded; } } }
toggleSwap
function toggleSwap(bool _swapEnabled) public onlyOwner { swapEnabled = _swapEnabled; }
//Set minimum tokens required to swap.
LineComment
v0.8.9+commit.e5eed63a
Unlicense
ipfs://fc822de242e02f4f76ff67d402acb10718a7cfde87916945cf468a1821d19f03
{ "func_code_index": [ 12907, 13013 ] }
3,295
CryptoCrowd
CryptoCrowd.sol
0x2df816710cd7ed473718bf0da9a8fdc4e982a130
Solidity
CryptoCrowd
contract CryptoCrowd is Context, IERC20, Ownable { using SafeMath for uint256; string private constant _name = "Crypto Crowd";// string private constant _symbol = "CROWD";// uint8 private constant _decimals = 9; mapping(address => uint256) private _rOwned; mapping(address => uint256) private _tOwned; mapping(address => mapping(address => uint256)) private _allowances; mapping(address => bool) private _isExcludedFromFee; uint256 private constant MAX = ~uint256(0); uint256 private constant _tTotal = 1000000 * 10**9; uint256 private _rTotal = (MAX - (MAX % _tTotal)); uint256 private _tFeeTotal; uint256 private _redisFeeOnBuy = 1; uint256 private _taxFeeOnBuy = 9; uint256 private _redisFeeOnSell = 1; uint256 private _taxFeeOnSell = 19; //Original Fee uint256 private _redisFee = _redisFeeOnSell; uint256 private _taxFee = _taxFeeOnSell; uint256 private _previousredisFee = _redisFee; uint256 private _previoustaxFee = _taxFee; mapping(address => bool) public bots; mapping (address => uint256) public _buyMap; address payable private _developmentAddress = payable(0xA76aCe0845138dc256E70102f3951813bFE6CC8b); address payable private _marketingAddress = payable(0x158e9b2322A4542F3FFc97cbEc269aBa3C8af848); IUniswapV2Router02 public uniswapV2Router; address public uniswapV2Pair; bool private tradingOpen; bool private inSwap = false; bool private swapEnabled = true; uint256 public _maxTxAmount = 10000 * 10**9; uint256 public _maxWalletSize = 1000000 * 10**9; uint256 public _swapTokensAtAmount = 10000 * 10**9; event MaxTxAmountUpdated(uint256 _maxTxAmount); modifier lockTheSwap { inSwap = true; _; inSwap = false; } constructor() { _rOwned[_msgSender()] = _rTotal; IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);// uniswapV2Router = _uniswapV2Router; uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()) .createPair(address(this), _uniswapV2Router.WETH()); _isExcludedFromFee[owner()] = true; _isExcludedFromFee[address(this)] = true; _isExcludedFromFee[_developmentAddress] = true; _isExcludedFromFee[_marketingAddress] = true; emit Transfer(address(0), _msgSender(), _tTotal); } function name() public pure returns (string memory) { return _name; } function symbol() public pure returns (string memory) { return _symbol; } function decimals() public pure returns (uint8) { return _decimals; } function totalSupply() public pure override returns (uint256) { return _tTotal; } function balanceOf(address account) public view override returns (uint256) { return tokenFromReflection(_rOwned[account]); } function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } function allowance(address owner, address spender) public view override returns (uint256) { return _allowances[owner][spender]; } function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub( amount, "ERC20: transfer amount exceeds allowance" ) ); return true; } function tokenFromReflection(uint256 rAmount) private view returns (uint256) { require( rAmount <= _rTotal, "Amount must be less than total reflections" ); uint256 currentRate = _getRate(); return rAmount.div(currentRate); } function removeAllFee() private { if (_redisFee == 0 && _taxFee == 0) return; _previousredisFee = _redisFee; _previoustaxFee = _taxFee; _redisFee = 0; _taxFee = 0; } function restoreAllFee() private { _redisFee = _previousredisFee; _taxFee = _previoustaxFee; } function _approve( address owner, address spender, uint256 amount ) private { 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 _transfer( address from, address to, uint256 amount ) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero"); if (from != owner() && to != owner()) { //Trade start check if (!tradingOpen) { require(from == owner(), "TOKEN: This account cannot send tokens until trading is enabled"); } require(amount <= _maxTxAmount, "TOKEN: Max Transaction Limit"); require(!bots[from] && !bots[to], "TOKEN: Your account is blacklisted!"); if(to != uniswapV2Pair) { require(balanceOf(to) + amount < _maxWalletSize, "TOKEN: Balance exceeds wallet size!"); } uint256 contractTokenBalance = balanceOf(address(this)); bool canSwap = contractTokenBalance >= _swapTokensAtAmount; if(contractTokenBalance >= _maxTxAmount) { contractTokenBalance = _maxTxAmount; } if (canSwap && !inSwap && from != uniswapV2Pair && swapEnabled && !_isExcludedFromFee[from] && !_isExcludedFromFee[to]) { swapTokensForEth(contractTokenBalance); uint256 contractETHBalance = address(this).balance; if (contractETHBalance > 0) { sendETHToFee(address(this).balance); } } } bool takeFee = true; //Transfer Tokens if ((_isExcludedFromFee[from] || _isExcludedFromFee[to]) || (from != uniswapV2Pair && to != uniswapV2Pair)) { takeFee = false; } else { //Set Fee for Buys if(from == uniswapV2Pair && to != address(uniswapV2Router)) { _redisFee = _redisFeeOnBuy; _taxFee = _taxFeeOnBuy; } //Set Fee for Sells if (to == uniswapV2Pair && from != address(uniswapV2Router)) { _redisFee = _redisFeeOnSell; _taxFee = _taxFeeOnSell; } } _tokenTransfer(from, to, amount, takeFee); } function swapTokensForEth(uint256 tokenAmount) private lockTheSwap { address[] memory path = new address[](2); path[0] = address(this); path[1] = uniswapV2Router.WETH(); _approve(address(this), address(uniswapV2Router), tokenAmount); uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens( tokenAmount, 0, path, address(this), block.timestamp ); } function sendETHToFee(uint256 amount) private { _marketingAddress.transfer(amount); } function setTrading(bool _tradingOpen) public onlyOwner { tradingOpen = _tradingOpen; } function manualswap() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractBalance = balanceOf(address(this)); swapTokensForEth(contractBalance); } function manualsend() external { require(_msgSender() == _developmentAddress || _msgSender() == _marketingAddress); uint256 contractETHBalance = address(this).balance; sendETHToFee(contractETHBalance); } function blockBots(address[] memory bots_) public onlyOwner { for (uint256 i = 0; i < bots_.length; i++) { bots[bots_[i]] = true; } } function unblockBot(address notbot) public onlyOwner { bots[notbot] = false; } function _tokenTransfer( address sender, address recipient, uint256 amount, bool takeFee ) private { if (!takeFee) removeAllFee(); _transferStandard(sender, recipient, amount); if (!takeFee) restoreAllFee(); } function _transferStandard( address sender, address recipient, uint256 tAmount ) private { ( uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tTeam ) = _getValues(tAmount); _rOwned[sender] = _rOwned[sender].sub(rAmount); _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); _takeTeam(tTeam); _reflectFee(rFee, tFee); emit Transfer(sender, recipient, tTransferAmount); } function _takeTeam(uint256 tTeam) private { uint256 currentRate = _getRate(); uint256 rTeam = tTeam.mul(currentRate); _rOwned[address(this)] = _rOwned[address(this)].add(rTeam); } function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } receive() external payable {} function _getValues(uint256 tAmount) private view returns ( uint256, uint256, uint256, uint256, uint256, uint256 ) { (uint256 tTransferAmount, uint256 tFee, uint256 tTeam) = _getTValues(tAmount, _redisFee, _taxFee); uint256 currentRate = _getRate(); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tTeam, currentRate); return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tTeam); } function _getTValues( uint256 tAmount, uint256 redisFee, uint256 taxFee ) private pure returns ( uint256, uint256, uint256 ) { uint256 tFee = tAmount.mul(redisFee).div(100); uint256 tTeam = tAmount.mul(taxFee).div(100); uint256 tTransferAmount = tAmount.sub(tFee).sub(tTeam); return (tTransferAmount, tFee, tTeam); } function _getRValues( uint256 tAmount, uint256 tFee, uint256 tTeam, uint256 currentRate ) private pure returns ( uint256, uint256, uint256 ) { uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rTeam = tTeam.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rTeam); return (rAmount, rTransferAmount, rFee); } function _getRate() private view returns (uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } function _getCurrentSupply() private view returns (uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } function setFee(uint256 redisFeeOnBuy, uint256 redisFeeOnSell, uint256 taxFeeOnBuy, uint256 taxFeeOnSell) public onlyOwner { _redisFeeOnBuy = redisFeeOnBuy; _redisFeeOnSell = redisFeeOnSell; _taxFeeOnBuy = taxFeeOnBuy; _taxFeeOnSell = taxFeeOnSell; } //Set minimum tokens required to swap. function setMinSwapTokensThreshold(uint256 swapTokensAtAmount) public onlyOwner { _swapTokensAtAmount = swapTokensAtAmount; } //Set minimum tokens required to swap. function toggleSwap(bool _swapEnabled) public onlyOwner { swapEnabled = _swapEnabled; } //Set maximum transaction function setMaxTxnAmount(uint256 maxTxAmount) public onlyOwner { _maxTxAmount = maxTxAmount; } function setMaxWalletSize(uint256 maxWalletSize) public onlyOwner { _maxWalletSize = maxWalletSize; } function excludeMultipleAccountsFromFees(address[] calldata accounts, bool excluded) public onlyOwner { for(uint256 i = 0; i < accounts.length; i++) { _isExcludedFromFee[accounts[i]] = excluded; } } }
setMaxTxnAmount
function setMaxTxnAmount(uint256 maxTxAmount) public onlyOwner { _maxTxAmount = maxTxAmount; }
//Set maximum transaction
LineComment
v0.8.9+commit.e5eed63a
Unlicense
ipfs://fc822de242e02f4f76ff67d402acb10718a7cfde87916945cf468a1821d19f03
{ "func_code_index": [ 13048, 13161 ] }
3,296
SIB
SIB.sol
0x6d03c06b762100e211a9c3280aebac3b7675486e
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. * * IMPORTANT: 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); }
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://5dcc9e7b65467b7f808dd69116a78c1080274f18d745caed11020fbdec624dbc
{ "func_code_index": [ 104, 168 ] }
3,297
SIB
SIB.sol
0x6d03c06b762100e211a9c3280aebac3b7675486e
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. * * IMPORTANT: 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); }
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://5dcc9e7b65467b7f808dd69116a78c1080274f18d745caed11020fbdec624dbc
{ "func_code_index": [ 261, 338 ] }
3,298
SIB
SIB.sol
0x6d03c06b762100e211a9c3280aebac3b7675486e
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. * * IMPORTANT: 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); }
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.6.12+commit.27d51765
None
ipfs://5dcc9e7b65467b7f808dd69116a78c1080274f18d745caed11020fbdec624dbc
{ "func_code_index": [ 584, 670 ] }
3,299