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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
11060,
11175
]
} | 307 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
11397,
11652
]
} | 308 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
11983,
12392
]
} | 309 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
12616,
13166
]
} | 310 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
13498,
14102
]
} | 311 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
14253,
14473
]
} | 312 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
14698,
14803
]
} | 313 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
15363,
15992
]
} | 314 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | 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_) public {
_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);
}
function _approve(address to, uint256 tokenId) private {
_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 { }
} | _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.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
16791,
16889
]
} | 315 |
||
HogeNFTv3 | HogeNFTv3.sol | 0xae58a033b6d7e66014fe88227c97680cc6ccecd9 | Solidity | HogeNFTv3 | contract HogeNFTv3 is Context, AccessControl, ERC721 {
using Counters for Counters.Counter;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
Counters.Counter private _tokenIdTracker;
address private _owner;
event Received(address, uint);
event Mint(address from, address to, string uri);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
receive() external payable {
emit Received(msg.sender, msg.value);
}
constructor(string memory name, string memory symbol, string memory baseURI) public ERC721(name, symbol) {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(MINTER_ROLE, _msgSender());
_setupRole(PAUSER_ROLE, _msgSender());
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
_setBaseURI(baseURI);
}
function mint(address to, string memory uri) public returns (uint) {
emit Mint(_msgSender(), to, uri);
require(hasRole(MINTER_ROLE, _msgSender()), "Must have minter role to mint");
_safeMint(to, _tokenIdTracker.current());
_setTokenURI(_tokenIdTracker.current(), uri);
_tokenIdTracker.increment();
}
function burn(uint256 tokenId) public virtual {
require(_isApprovedOrOwner(_msgSender(), tokenId), "Burn: Caller is not owner nor approved");
_burn(tokenId);
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721) {
super._beforeTokenTransfer(from, to, tokenId);
}
// Begin Ownable interface from openzeppelin
// Primarily used for OpenSea storefront management, AccessControl is used for choosing who can mint.
// Owner, MINTER_ROLE, PAUSER_ROLE can all be separate addresses!
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(isOwner());
_;
}
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0));
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
function contractURI() public view returns (string memory) {
return "https://www.hogemint.com/uri/contract-HogeNFTv3";
}
} | owner | function owner() public view returns (address) {
return _owner;
}
| // Begin Ownable interface from openzeppelin
// Primarily used for OpenSea storefront management, AccessControl is used for choosing who can mint.
// Owner, MINTER_ROLE, PAUSER_ROLE can all be separate addresses! | LineComment | v0.7.6+commit.7338295f | MIT | ipfs://c9934b71fc610797d2cdb07781f8b745bc463b58cb1b7325cc49abe91d425949 | {
"func_code_index": [
1770,
1838
]
} | 316 |
||
yCurveGrantPool | yCurveGrantPool.sol | 0x35a618b7844c90e19975e5697c9281421be01f6e | Solidity | Context | contract Context {
constructor () internal { }
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
} | _msgSender | function _msgSender() internal view returns (address payable) {
return msg.sender;
}
| // solhint-disable-previous-line no-empty-blocks | LineComment | v0.5.12+commit.7709ece9 | MIT | bzzr://849fa1025011f5f399b18ace13959cf60c57cacb5bd77acce18b71ac86f2ad71 | {
"func_code_index": [
109,
212
]
} | 317 |
||
yCurveGrantPool | yCurveGrantPool.sol | 0x35a618b7844c90e19975e5697c9281421be01f6e | Solidity | yCurveGrantPool | contract yCurveGrantPool is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using Address for address;
using SafeMath for uint256;
address public DAI;
address public yDAI;
address public USDC;
address public yUSDC;
address public USDT;
address public yUSDT;
address public TUSD;
address public yTUSD;
address public SWAP;
address public CURVE;
constructor () public {
DAI = address(0x6B175474E89094C44Da98b954EedeAC495271d0F);
yDAI = address(0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01);
USDC = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
yUSDC = address(0xd6aD7a6750A7593E092a9B218d66C0A814a3436e);
USDT = address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
yUSDT = address(0x83f798e925BcD4017Eb265844FDDAbb448f1707D);
TUSD = address(0x0000000000085d4780B73119b644AE5ecd22b376);
yTUSD = address(0x73a052500105205d34Daf004eAb301916DA8190f);
SWAP = address(0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51);
CURVE = address(0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8);
approveToken();
}
function() external payable {
}
function approveToken() public {
IERC20(yDAI).safeApprove(SWAP, uint(-1));
IERC20(yUSDC).safeApprove(SWAP, uint(-1));
IERC20(yUSDT).safeApprove(SWAP, uint(-1));
IERC20(yTUSD).safeApprove(SWAP, uint(-1));
}
function donate(uint256 _amount) external nonReentrant onlyOwner {
ICurveFi(SWAP).remove_liquidity(_amount, [uint256(0),0,0,0]);
uint256 _ydai = IERC20(yDAI).balanceOf(address(this));
uint256 _yusdc = IERC20(yUSDC).balanceOf(address(this));
uint256 _yusdt = IERC20(yUSDT).balanceOf(address(this));
uint256 _ytusd = IERC20(yTUSD).balanceOf(address(this));
if (_ydai > 0) {
yERC20(yDAI).withdraw(_ydai);
IERC20(DAI).safeTransfer(yDAI, IERC20(DAI).balanceOf(address(this)));
}
if (_yusdc > 0) {
yERC20(yUSDC).withdraw(_yusdc);
IERC20(USDC).safeTransfer(yUSDC, IERC20(USDC).balanceOf(address(this)));
}
if (_yusdt > 0) {
yERC20(yUSDT).withdraw(_yusdt);
IERC20(USDT).safeTransfer(yUSDT, IERC20(USDT).balanceOf(address(this)));
}
if (_ytusd > 0) {
yERC20(yTUSD).withdraw(_ytusd);
IERC20(TUSD).safeTransfer(yTUSD, IERC20(TUSD).balanceOf(address(this)));
}
}
// incase of half-way error
function inCaseTokenGetsStuck(IERC20 _TokenAddress) onlyOwner public {
uint qty = _TokenAddress.balanceOf(address(this));
_TokenAddress.safeTransfer(msg.sender, qty);
}
// incase of half-way error
function inCaseETHGetsStuck() onlyOwner public{
(bool result, ) = msg.sender.call.value(address(this).balance)("");
require(result, "transfer of ETH failed");
}
} | inCaseTokenGetsStuck | function inCaseTokenGetsStuck(IERC20 _TokenAddress) onlyOwner public {
uint qty = _TokenAddress.balanceOf(address(this));
_TokenAddress.safeTransfer(msg.sender, qty);
}
| // incase of half-way error | LineComment | v0.5.12+commit.7709ece9 | MIT | bzzr://849fa1025011f5f399b18ace13959cf60c57cacb5bd77acce18b71ac86f2ad71 | {
"func_code_index": [
2412,
2600
]
} | 318 |
||
yCurveGrantPool | yCurveGrantPool.sol | 0x35a618b7844c90e19975e5697c9281421be01f6e | Solidity | yCurveGrantPool | contract yCurveGrantPool is ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using Address for address;
using SafeMath for uint256;
address public DAI;
address public yDAI;
address public USDC;
address public yUSDC;
address public USDT;
address public yUSDT;
address public TUSD;
address public yTUSD;
address public SWAP;
address public CURVE;
constructor () public {
DAI = address(0x6B175474E89094C44Da98b954EedeAC495271d0F);
yDAI = address(0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01);
USDC = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
yUSDC = address(0xd6aD7a6750A7593E092a9B218d66C0A814a3436e);
USDT = address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
yUSDT = address(0x83f798e925BcD4017Eb265844FDDAbb448f1707D);
TUSD = address(0x0000000000085d4780B73119b644AE5ecd22b376);
yTUSD = address(0x73a052500105205d34Daf004eAb301916DA8190f);
SWAP = address(0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51);
CURVE = address(0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8);
approveToken();
}
function() external payable {
}
function approveToken() public {
IERC20(yDAI).safeApprove(SWAP, uint(-1));
IERC20(yUSDC).safeApprove(SWAP, uint(-1));
IERC20(yUSDT).safeApprove(SWAP, uint(-1));
IERC20(yTUSD).safeApprove(SWAP, uint(-1));
}
function donate(uint256 _amount) external nonReentrant onlyOwner {
ICurveFi(SWAP).remove_liquidity(_amount, [uint256(0),0,0,0]);
uint256 _ydai = IERC20(yDAI).balanceOf(address(this));
uint256 _yusdc = IERC20(yUSDC).balanceOf(address(this));
uint256 _yusdt = IERC20(yUSDT).balanceOf(address(this));
uint256 _ytusd = IERC20(yTUSD).balanceOf(address(this));
if (_ydai > 0) {
yERC20(yDAI).withdraw(_ydai);
IERC20(DAI).safeTransfer(yDAI, IERC20(DAI).balanceOf(address(this)));
}
if (_yusdc > 0) {
yERC20(yUSDC).withdraw(_yusdc);
IERC20(USDC).safeTransfer(yUSDC, IERC20(USDC).balanceOf(address(this)));
}
if (_yusdt > 0) {
yERC20(yUSDT).withdraw(_yusdt);
IERC20(USDT).safeTransfer(yUSDT, IERC20(USDT).balanceOf(address(this)));
}
if (_ytusd > 0) {
yERC20(yTUSD).withdraw(_ytusd);
IERC20(TUSD).safeTransfer(yTUSD, IERC20(TUSD).balanceOf(address(this)));
}
}
// incase of half-way error
function inCaseTokenGetsStuck(IERC20 _TokenAddress) onlyOwner public {
uint qty = _TokenAddress.balanceOf(address(this));
_TokenAddress.safeTransfer(msg.sender, qty);
}
// incase of half-way error
function inCaseETHGetsStuck() onlyOwner public{
(bool result, ) = msg.sender.call.value(address(this).balance)("");
require(result, "transfer of ETH failed");
}
} | inCaseETHGetsStuck | function inCaseETHGetsStuck() onlyOwner public{
(bool result, ) = msg.sender.call.value(address(this).balance)("");
require(result, "transfer of ETH failed");
}
| // incase of half-way error | LineComment | v0.5.12+commit.7709ece9 | MIT | bzzr://849fa1025011f5f399b18ace13959cf60c57cacb5bd77acce18b71ac86f2ad71 | {
"func_code_index": [
2634,
2814
]
} | 319 |
||
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
268,
659
]
} | 320 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
865,
977
]
} | 321 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
401,
853
]
} | 322 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
1485,
1675
]
} | 323 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
1999,
2130
]
} | 324 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
2375,
2639
]
} | 325 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | Ownable | function Ownable() public {
owner = msg.sender;
}
| /**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
261,
321
]
} | 326 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
| /**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
644,
820
]
} | 327 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | MintableToken | contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(address(0), _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}
} | /**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/ | NatSpecMultiLine | mint | function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(address(0), _to, _amount);
return true;
}
| /**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
483,
754
]
} | 328 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | MintableToken | contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(address(0), _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}
} | /**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/ | NatSpecMultiLine | finishMinting | function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}
| /**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
871,
1013
]
} | 329 |
|
ICO | ICO.sol | 0x85f8c84b0f7a212b23b5586889ec3152aff5cc99 | Solidity | BurnableToken | contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
} | /**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/ | NatSpecMultiLine | burn | function burn(uint256 _value) public {
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
| /**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/ | NatSpecMultiLine | v0.4.20+commit.3155dd80 | bzzr://9616334fedcaabb3da6475f1145ca8a372a8747e294f0a242fcae29fbdb4a5b8 | {
"func_code_index": [
222,
680
]
} | 330 |
|
CvxCrvStrategy | contracts/strategies/CvxCrvStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | CvxCrvStrategy | contract CvxCrvStrategy is ClaimableStrategy {
uint256 public constant MAX_BPS = 10000;
struct Settings {
address crvRewards;
address cvxRewards;
address convexBooster;
address crvDepositor;
address crvToken;
uint256 poolIndex;
address cvxCrvToken;
address curveCvxCrvStableSwapPool;
uint256 curveCvxCrvIndexInStableSwapPool;
uint256 curveAddLiquiditySlippageTolerance; // in bps, ex: 9500 == 5%
}
Settings public poolSettings;
function configure(
address _wantAddress,
address _controllerAddress,
address _governance,
Settings memory _poolSettings
) public onlyOwner initializer {
_configure(_wantAddress, _controllerAddress, _governance);
poolSettings = _poolSettings;
}
function setPoolIndex(uint256 _newPoolIndex) external onlyOwner {
poolSettings.poolIndex = _newPoolIndex;
}
function checkPoolIndex(uint256 index) public view returns (bool) {
IBooster.PoolInfo memory _pool = IBooster(poolSettings.convexBooster)
.poolInfo(index);
return _pool.lptoken == _want;
}
/// @dev Function that controller calls
function deposit() external override onlyController {
if (checkPoolIndex(poolSettings.poolIndex)) {
IERC20 wantToken = IERC20(_want);
if (
wantToken.allowance(
address(this),
poolSettings.convexBooster
) == 0
) {
wantToken.approve(poolSettings.convexBooster, uint256(-1));
}
//true means that the received lp tokens will immediately be stakes
IBooster(poolSettings.convexBooster).depositAll(
poolSettings.poolIndex,
true
);
}
}
function getRewards() external override {
require(
IRewards(poolSettings.crvRewards).getReward(),
"!getRewardsCRV"
);
ICVXRewards(poolSettings.cvxRewards).getReward(true);
}
function _withdrawSome(uint256 _amount)
internal
override
returns (uint256)
{
IRewards(poolSettings.crvRewards).withdraw(_amount, true);
require(
IBooster(poolSettings.convexBooster).withdraw(
poolSettings.poolIndex,
_amount
),
"!withdrawSome"
);
return _amount;
}
function _convertTokens(uint256 _amount) internal{
IERC20 convertToken = IERC20(poolSettings.crvToken);
convertToken.safeTransferFrom(
msg.sender,
address(this),
_amount
);
if (
convertToken.allowance(address(this), poolSettings.crvDepositor) == 0
) {
convertToken.approve(poolSettings.crvDepositor, uint256(-1));
}
//address(0) means that we'll not stake immediately
//for provided sender (cause it's zero addr)
IRewards(poolSettings.crvDepositor).depositAll(true, address(0));
}
function convertTokens(uint256 _amount) external {
_convertTokens(_amount);
IERC20 _cxvCRV = IERC20(poolSettings.cvxCrvToken);
uint256 cvxCrvAmount = _cxvCRV.balanceOf(address(this));
_cxvCRV.safeTransfer(msg.sender, cvxCrvAmount);
}
function convertAndStakeTokens(uint256 _amount, uint256 minCurveCvxCrvLPAmount) external {
_convertTokens(_amount);
IERC20 _cvxCrv = IERC20(poolSettings.cvxCrvToken);
uint256 cvxCrvBalance = _cvxCrv.balanceOf(address(this));
uint256[2] memory _amounts;
_amounts[poolSettings.curveCvxCrvIndexInStableSwapPool] = cvxCrvBalance;
ICurveCvxCrvStableSwap stableSwapPool = ICurveCvxCrvStableSwap(
poolSettings.curveCvxCrvStableSwapPool
);
_cvxCrv.approve(poolSettings.curveCvxCrvStableSwapPool, cvxCrvBalance);
uint256 actualCurveCvxCrvLPAmount = stableSwapPool.add_liquidity(
_amounts,
minCurveCvxCrvLPAmount,
address(this)
);
IERC20 _stakingToken = IERC20(_want);
address vault = IController(controller).vaults(_want);
_stakingToken.approve(vault, actualCurveCvxCrvLPAmount);
IVaultTransfers(vault).depositFor(actualCurveCvxCrvLPAmount, msg.sender);
}
} | /// @title CvxCrvStrategy | NatSpecSingleLine | deposit | function deposit() external override onlyController {
if (checkPoolIndex(poolSettings.poolIndex)) {
IERC20 wantToken = IERC20(_want);
if (
wantToken.allowance(
address(this),
poolSettings.convexBooster
) == 0
) {
wantToken.approve(poolSettings.convexBooster, uint256(-1));
}
//true means that the received lp tokens will immediately be stakes
IBooster(poolSettings.convexBooster).depositAll(
poolSettings.poolIndex,
true
);
}
}
| /// @dev Function that controller calls | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
1269,
1942
]
} | 331 |
||
CvxCrvStrategy | contracts/strategies/base/BaseStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | BaseStrategy | abstract contract BaseStrategy is IStrategy, Ownable, Initializable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
event Withdrawn(
address indexed _token,
uint256 indexed _amount,
address indexed _to
);
/// @notice reward token address
address internal _want;
/// @notice Controller instance getter, used to simplify controller-related actions
address public controller;
/// @dev Prevents other msg.sender than controller address
modifier onlyController() {
require(_msgSender() == controller, "!controller");
_;
}
/// @dev Prevents other msg.sender than controller or vault addresses
modifier onlyControllerOrVault() {
require(
_msgSender() == controller ||
_msgSender() == IController(controller).vaults(_want),
"!controller|vault"
);
_;
}
/// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance
function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
/// @notice Usual setter with check if param is new
/// @param _newController New value
function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
/// @notice Usual setter with check if param is new
/// @param _newWant New value
function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
/// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb)
function want() external view override returns (address) {
return _want;
}
/// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller
function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
/// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault
function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
/// @notice balance of this address in "want" tokens
function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
function _withdrawSome(uint256 _amount) internal virtual returns (uint256);
} | _configure | function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
| /// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
1301,
1562
]
} | 332 |
||||
CvxCrvStrategy | contracts/strategies/base/BaseStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | BaseStrategy | abstract contract BaseStrategy is IStrategy, Ownable, Initializable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
event Withdrawn(
address indexed _token,
uint256 indexed _amount,
address indexed _to
);
/// @notice reward token address
address internal _want;
/// @notice Controller instance getter, used to simplify controller-related actions
address public controller;
/// @dev Prevents other msg.sender than controller address
modifier onlyController() {
require(_msgSender() == controller, "!controller");
_;
}
/// @dev Prevents other msg.sender than controller or vault addresses
modifier onlyControllerOrVault() {
require(
_msgSender() == controller ||
_msgSender() == IController(controller).vaults(_want),
"!controller|vault"
);
_;
}
/// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance
function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
/// @notice Usual setter with check if param is new
/// @param _newController New value
function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
/// @notice Usual setter with check if param is new
/// @param _newWant New value
function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
/// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb)
function want() external view override returns (address) {
return _want;
}
/// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller
function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
/// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault
function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
/// @notice balance of this address in "want" tokens
function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
function _withdrawSome(uint256 _amount) internal virtual returns (uint256);
} | setController | function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
| /// @notice Usual setter with check if param is new
/// @param _newController New value | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
1663,
1845
]
} | 333 |
||||
CvxCrvStrategy | contracts/strategies/base/BaseStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | BaseStrategy | abstract contract BaseStrategy is IStrategy, Ownable, Initializable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
event Withdrawn(
address indexed _token,
uint256 indexed _amount,
address indexed _to
);
/// @notice reward token address
address internal _want;
/// @notice Controller instance getter, used to simplify controller-related actions
address public controller;
/// @dev Prevents other msg.sender than controller address
modifier onlyController() {
require(_msgSender() == controller, "!controller");
_;
}
/// @dev Prevents other msg.sender than controller or vault addresses
modifier onlyControllerOrVault() {
require(
_msgSender() == controller ||
_msgSender() == IController(controller).vaults(_want),
"!controller|vault"
);
_;
}
/// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance
function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
/// @notice Usual setter with check if param is new
/// @param _newController New value
function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
/// @notice Usual setter with check if param is new
/// @param _newWant New value
function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
/// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb)
function want() external view override returns (address) {
return _want;
}
/// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller
function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
/// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault
function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
/// @notice balance of this address in "want" tokens
function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
function _withdrawSome(uint256 _amount) internal virtual returns (uint256);
} | setWant | function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
| /// @notice Usual setter with check if param is new
/// @param _newWant New value | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
1940,
2088
]
} | 334 |
||||
CvxCrvStrategy | contracts/strategies/base/BaseStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | BaseStrategy | abstract contract BaseStrategy is IStrategy, Ownable, Initializable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
event Withdrawn(
address indexed _token,
uint256 indexed _amount,
address indexed _to
);
/// @notice reward token address
address internal _want;
/// @notice Controller instance getter, used to simplify controller-related actions
address public controller;
/// @dev Prevents other msg.sender than controller address
modifier onlyController() {
require(_msgSender() == controller, "!controller");
_;
}
/// @dev Prevents other msg.sender than controller or vault addresses
modifier onlyControllerOrVault() {
require(
_msgSender() == controller ||
_msgSender() == IController(controller).vaults(_want),
"!controller|vault"
);
_;
}
/// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance
function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
/// @notice Usual setter with check if param is new
/// @param _newController New value
function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
/// @notice Usual setter with check if param is new
/// @param _newWant New value
function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
/// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb)
function want() external view override returns (address) {
return _want;
}
/// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller
function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
/// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault
function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
/// @notice balance of this address in "want" tokens
function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
function _withdrawSome(uint256 _amount) internal virtual returns (uint256);
} | want | function want() external view override returns (address) {
return _want;
}
| /// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb) | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
2199,
2292
]
} | 335 |
||||
CvxCrvStrategy | contracts/strategies/base/BaseStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | BaseStrategy | abstract contract BaseStrategy is IStrategy, Ownable, Initializable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
event Withdrawn(
address indexed _token,
uint256 indexed _amount,
address indexed _to
);
/// @notice reward token address
address internal _want;
/// @notice Controller instance getter, used to simplify controller-related actions
address public controller;
/// @dev Prevents other msg.sender than controller address
modifier onlyController() {
require(_msgSender() == controller, "!controller");
_;
}
/// @dev Prevents other msg.sender than controller or vault addresses
modifier onlyControllerOrVault() {
require(
_msgSender() == controller ||
_msgSender() == IController(controller).vaults(_want),
"!controller|vault"
);
_;
}
/// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance
function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
/// @notice Usual setter with check if param is new
/// @param _newController New value
function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
/// @notice Usual setter with check if param is new
/// @param _newWant New value
function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
/// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb)
function want() external view override returns (address) {
return _want;
}
/// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller
function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
/// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault
function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
/// @notice balance of this address in "want" tokens
function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
function _withdrawSome(uint256 _amount) internal virtual returns (uint256);
} | withdraw | function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
| /// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
2423,
2754
]
} | 336 |
||||
CvxCrvStrategy | contracts/strategies/base/BaseStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | BaseStrategy | abstract contract BaseStrategy is IStrategy, Ownable, Initializable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
event Withdrawn(
address indexed _token,
uint256 indexed _amount,
address indexed _to
);
/// @notice reward token address
address internal _want;
/// @notice Controller instance getter, used to simplify controller-related actions
address public controller;
/// @dev Prevents other msg.sender than controller address
modifier onlyController() {
require(_msgSender() == controller, "!controller");
_;
}
/// @dev Prevents other msg.sender than controller or vault addresses
modifier onlyControllerOrVault() {
require(
_msgSender() == controller ||
_msgSender() == IController(controller).vaults(_want),
"!controller|vault"
);
_;
}
/// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance
function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
/// @notice Usual setter with check if param is new
/// @param _newController New value
function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
/// @notice Usual setter with check if param is new
/// @param _newWant New value
function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
/// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb)
function want() external view override returns (address) {
return _want;
}
/// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller
function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
/// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault
function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
/// @notice balance of this address in "want" tokens
function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
function _withdrawSome(uint256 _amount) internal virtual returns (uint256);
} | withdraw | function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
| /// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
2915,
3439
]
} | 337 |
||||
CvxCrvStrategy | contracts/strategies/base/BaseStrategy.sol | 0x958477765fa9b37e93ce9320af8cd53db5f1866c | Solidity | BaseStrategy | abstract contract BaseStrategy is IStrategy, Ownable, Initializable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
event Withdrawn(
address indexed _token,
uint256 indexed _amount,
address indexed _to
);
/// @notice reward token address
address internal _want;
/// @notice Controller instance getter, used to simplify controller-related actions
address public controller;
/// @dev Prevents other msg.sender than controller address
modifier onlyController() {
require(_msgSender() == controller, "!controller");
_;
}
/// @dev Prevents other msg.sender than controller or vault addresses
modifier onlyControllerOrVault() {
require(
_msgSender() == controller ||
_msgSender() == IController(controller).vaults(_want),
"!controller|vault"
);
_;
}
/// @notice Default initialize method for solving migration linearization problem
/// @dev Called once only by deployer
/// @param _wantAddress address of eurxb instance or address of TokenWrapper(EURxb) instance
/// @param _controllerAddress address of controller instance
function _configure(
address _wantAddress,
address _controllerAddress,
address _governance
) internal {
_want = _wantAddress;
controller = _controllerAddress;
transferOwnership(_governance);
}
/// @notice Usual setter with check if param is new
/// @param _newController New value
function setController(address _newController) external override onlyOwner {
require(controller != _newController, "!old");
controller = _newController;
}
/// @notice Usual setter with check if param is new
/// @param _newWant New value
function setWant(address _newWant) external override onlyOwner {
require(_want != _newWant, "!old");
_want = _newWant;
}
/// @notice Usual getter (inherited from IStrategy)
/// @return 'want' token (In this case EURxb)
function want() external view override returns (address) {
return _want;
}
/// @notice must exclude any tokens used in the yield
/// @dev Controller role - withdraw should return to Controller
function withdraw(address _token) external virtual override onlyController {
require(address(_token) != address(_want), "!want");
uint256 balance = IERC20(_token).balanceOf(address(this));
IERC20(_token).safeTransfer(controller, balance);
emit Withdrawn(_token, balance, controller);
}
/// @notice Withdraw partial funds, normally used with a vault withdrawal
/// @dev Controller | Vault role - withdraw should always return to Vault
function withdraw(uint256 _amount)
public
virtual
override
onlyControllerOrVault
{
uint256 _balance = IERC20(_want).balanceOf(address(this));
if (_balance < _amount) {
_amount = _withdrawSome(_amount.sub(_balance));
_amount = _amount.add(_balance);
}
address _vault = IController(controller).vaults(_want);
IERC20(_want).safeTransfer(_vault, _amount);
emit Withdrawn(_want, _amount, _vault);
}
/// @notice balance of this address in "want" tokens
function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
function _withdrawSome(uint256 _amount) internal virtual returns (uint256);
} | balanceOf | function balanceOf() public view virtual override returns (uint256) {
return IERC20(_want).balanceOf(address(this));
}
| /// @notice balance of this address in "want" tokens | NatSpecSingleLine | v0.6.6+commit.6c089d02 | {
"func_code_index": [
3500,
3637
]
} | 338 |
||||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | /**
* Default Interfaces for accepting ETH
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
1286,
1343
]
} | 339 |
||||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | withdrawalAll | function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
| /**
* Withrawal Function for Admins
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
1457,
1580
]
} | 340 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | withdrawalAllNfts | function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
| /**
* Withrawal NFTs Function for Admins
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
1640,
2317
]
} | 341 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | deposit | function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
| /**
* take eth and distribute NFT
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
2370,
3518
]
} | 342 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | transferNft | function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
| /**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
3639,
4071
]
} | 343 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | onERC1155Received | function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
| /**
* ERC1155 Receiver Methods
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
4142,
4919
]
} | 344 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | getAvailableTokensByTokenId | function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
| /**
* Helper Function to get Available Token by Token Id
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
5976,
6301
]
} | 345 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | randomAvailableTokenIndex | function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
| /**
* Get a random Token Index based on array length
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
6373,
6674
]
} | 346 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | addToWhitelist | function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
| /**
* Whitelist
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
6812,
6964
]
} | 347 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | setAdmin | function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
| /**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
7649,
7805
]
} | 348 |
||
MultipleDropsSale | /contracts/MultipleDropsSale.sol | 0xcaa57c4038fce04185898466fb454e33d5b27029 | Solidity | MultipleDropsSale | contract MultipleDropsSale is Ownable, IERC1155Receiver {
using Address for address;
using SafeMath for uint256;
address public nftContractAddress;
mapping(address => bool) private _admins;
mapping(address => bool) private _buyers;
mapping(address => bool) private _whitelisted;
struct AvailableToken {
uint256 id; // short id (up to 32 bytes)
uint256 amount; // number of available tokens
}
AvailableToken[] public _availableTokens;
event AdminAccessSet(address _admin, bool _enabled);
event NftTransfered(uint256 _nftId, address _buyer, uint256 _timestamp);
event AddedMultipleToWhitelist(address[] account);
event AddedToWhitelist(address indexed account);
event RemovedFromWhitelist(address indexed account);
constructor(address _nftContractAddress) {
require(
_nftContractAddress.isContract(),
"_nftContractAddress must be a NFT contract"
);
nftContractAddress = _nftContractAddress;
_admins[msg.sender] = true;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165) returns (bool) {
return false;
}
// Transaction Functions
/**
* Default Interfaces for accepting ETH
*/
receive() external payable {
deposit();
}
fallback() external payable {
deposit();
}
/**
* Withrawal Function for Admins
*/
function withdrawalAll() external onlyAdmin() {
require(payable(msg.sender).send(address(this).balance));
}
/**
* Withrawal NFTs Function for Admins
*/
function withdrawalAllNfts() external onlyAdmin() {
for (uint p = 0; p < _availableTokens.length; p++) {
require(
ERC1155(nftContractAddress).balanceOf(address(this), _availableTokens[p].id) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
msg.sender,
_availableTokens[p].id,
_availableTokens[p].amount,
'0x0'
);
delete _availableTokens[p];
emit NftTransfered(_availableTokens[p].id, msg.sender, block.timestamp);
}
}
/**
* take eth and distribute NFT
*/
function deposit() public payable {
require(msg.value == 0.25 ether, "Please transfer 0.25 ether");
require(
_buyers[msg.sender] == false,
"Only 1 purchase per wallet allowed"
);
require(
_whitelisted[msg.sender] == true,
"You need to be whitelisted to purchase"
);
require(
_availableTokens.length > 0,
"Currently no NFT available. Please try again later"
);
uint256 randomIndex = randomAvailableTokenIndex();
uint256 randomTokenId = _availableTokens[randomIndex].id;
require(
_availableTokens[randomIndex].amount > 0,
"No Amount available for this token"
);
transferNft(randomTokenId, msg.sender);
_buyers[msg.sender] = true;
if (_availableTokens[randomIndex].amount > 1) {
_availableTokens[randomIndex] = AvailableToken({
id: randomTokenId,
amount: _availableTokens[randomIndex].amount - 1
});
} else {
delete _availableTokens[randomIndex];
}
}
/**
*
* @param nftId - nftId of the artwork
* @param to - address of the artwork recipient
*/
function transferNft(uint256 nftId, address to) private {
require(
ERC1155(nftContractAddress).balanceOf(address(this), nftId) > 0,
"NFT is owned by this contract"
);
ERC1155(nftContractAddress).safeTransferFrom(
address(this),
to,
nftId,
1,
'0x0'
);
emit NftTransfered(nftId, to, block.timestamp);
}
// Admin Functions
/**
* ERC1155 Receiver Methods
*/
function onERC1155Received(
address _operator,
address _from,
uint256 _id,
uint256 _amount,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
int selectedIdx = getAvailableTokensByTokenId(_id);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _id,
amount: _availableTokens[tokenIdx].amount + _amount
});
} else {
_availableTokens.push(AvailableToken({id: _id, amount: _amount}));
}
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address _operator,
address _from,
uint256[] memory _ids,
uint256[] memory _amounts,
bytes memory
) public virtual returns (bytes4) {
require(
_admins[_from] || _from == owner(),
"Only Admins can send NFTs"
);
for (uint256 i = 0; i < _ids.length; i++) {
int selectedIdx = getAvailableTokensByTokenId(_ids[i]);
if (selectedIdx > 0) {
uint256 tokenIdx = uint256(selectedIdx);
_availableTokens[tokenIdx] = AvailableToken({
id: _ids[i],
amount: _availableTokens[tokenIdx].amount + _amounts[i]
});
} else {
_availableTokens.push(
AvailableToken({id: _ids[i], amount: _amounts[i]})
);
}
}
return this.onERC1155BatchReceived.selector;
}
// Utils
/**
* Helper Function to get Available Token by Token Id
*/
function getAvailableTokensByTokenId(uint256 id)
public
view
returns (int)
{
int index = -1;
for (uint p = 0; p < _availableTokens.length; p++) {
if (_availableTokens[p].id == id) {
index = int(p);
}
}
return index;
}
/**
* Get a random Token Index based on array length
*/
function randomAvailableTokenIndex() private view returns (uint8) {
uint256 max_amount = _availableTokens.length;
return
uint8(
uint256(keccak256(abi.encodePacked(block.timestamp, block.difficulty))) %
max_amount
);
}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
/**
* Whitelist
*/
function addToWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = true;
emit AddedToWhitelist(_address);
}
function addMultipleToWhitelist(address[] memory addrs) public onlyAdmin() {
for (uint p = 0; p < addrs.length; p++) {
_whitelisted[addrs[p]] = true;
}
emit AddedMultipleToWhitelist(addrs);
}
function removeFromWhitelist(address _address) public onlyAdmin() {
_whitelisted[_address] = false;
emit RemovedFromWhitelist(_address);
}
function isWhitelisted(address _address) public view returns(bool) {
return _whitelisted[_address];
}
// Admin Functions
/**
* Set Admin Access
*
* @param admin - Address of Minter
* @param enabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool enabled) external onlyOwner {
_admins[admin] = enabled;
emit AdminAccessSet(admin, enabled);
}
/**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/
function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
/**
* Throws if called by any account other than the Admin.
*/
modifier onlyAdmin() {
require(
_admins[msg.sender] || msg.sender == owner(),
"Caller does not have Admin Access"
);
_;
}
} | // The Drops Multiple Public Sale | LineComment | isAdmin | function isAdmin(address admin) public view returns (bool) {
return _admins[admin];
}
| /**
* Check Admin Access
*
* @param admin - Address of Admin
* @return whether minter has access
*/ | NatSpecMultiLine | v0.8.9+commit.e5eed63a | {
"func_code_index": [
7936,
8037
]
} | 349 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | // receive eth from uniswap swap | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
3079,
3114
]
} | 350 |
||||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | lockLiquidity | function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
| // few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100! | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
3320,
5137
]
} | 351 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | rewardLiquidityProviders | function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
| // external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
5300,
5459
]
} | 352 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | lockableSupply | function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
| // returns token amount | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
7265,
7384
]
} | 353 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | lockedSupply | function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
| // returns token amount | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
7416,
7870
]
} | 354 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | burnedSupply | function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
| // returns token amount | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
7902,
8356
]
} | 355 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | burnableLiquidity | function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
| // returns LP amount, not token amount | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
8403,
8538
]
} | 356 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | burnedLiquidity | function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
| // returns LP amount, not token amount | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
8585,
8715
]
} | 357 |
||
TMC | contracts\ERC20TransferLiquidityLock.sol | 0xe13559cf6edf84bd04bf679e251f285000b9305e | Solidity | ERC20TransferLiquidityLock | abstract contract ERC20TransferLiquidityLock is ERC20, Ownable {
using SafeMath for uint256;
event AddLiquidity(uint256 tokenAmount, uint256 ethAmount);
event BurnedLiquidity(uint256 balance);
event RewardLiquidityProviders(uint256 tokenAmount);
event BurnTokens(uint256 amt);
event FromWhiteListed(address indexed a, bool whitelist);
event ToWhiteListed(address indexed a, bool whitelist);
mapping (address => bool) fromWhitelistAddresses;
mapping (address => bool) toWhitelistAddresses;
address public uniswapV2Router;
address public uniswapV2Pair;
// the amount of tokens to lock for liquidity during every transfer, i.e. 100 = 1%, 50 = 2%, 40 = 2.5%
uint256 public liquidityLockDivisor = 25;
uint256 public devDivisor = 4;
uint256 public poolDivisor = 4;
uint256 public lpRewardDivisor = 4;
// few things to do here. out of the 4% collected per transfer:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
address public liquidLockDevAddress;
function setUniswapV2Router(address _uniswapV2Router) public onlyOwner {
uniswapV2Router = _uniswapV2Router;
}
function setUniswapV2Pair(address _uniswapV2Pair) public onlyOwner {
uniswapV2Pair = _uniswapV2Pair;
}
function setLiquidLockDevAddress(address a) internal virtual onlyOwner {
liquidLockDevAddress = a;
}
function setLiquidityLockDivisor(uint256 _liquidityLockDivisor) public onlyOwner {
liquidityLockDivisor = _liquidityLockDivisor;
}
function setDevDivisor(uint256 _devDivisor) public onlyOwner {
devDivisor = _devDivisor;
}
function setPoolDivisor(uint256 _poolDivisor) public onlyOwner {
poolDivisor = _poolDivisor;
}
function setLpRewardDivisor(uint256 _lpRewardDivisor) public onlyOwner {
lpRewardDivisor = _lpRewardDivisor;
}
function setToWhitelistAddress(address a, bool whitelist) public onlyOwner {
toWhitelistAddresses[a] = whitelist;
emit ToWhiteListed(a,whitelist);
}
function setFromWhitelistAddress(address a, bool whitelist) public onlyOwner {
fromWhitelistAddresses[a] = whitelist;
emit FromWhiteListed(a,whitelist);
}
function _transfer(address from, address to, uint256 amount) internal virtual override{
// calculate liquidity lock amount
// dont transfer burn from this contract
// or can never lock full lockable amount
if (liquidityLockDivisor != 0 && from != address(this) && !fromWhitelistAddresses[from] && !toWhitelistAddresses[to]) {
uint256 liquidityLockAmount = amount.div(liquidityLockDivisor);
super._transfer(from, address(this), liquidityLockAmount); //4% goes to contract
super._transfer(from, to, amount.sub(liquidityLockAmount));
}
else {
super._transfer(from, to, amount);
}
}
// receive eth from uniswap swap
receive () external payable {}
// few things to do here. out of the 4% collected:
// 1% to dev
// 1% burn
// 1% to uniswap pool
// 1% to LP holders
// make sure all 3 added up postdivisor is < 100!
function lockLiquidity(uint256 _lockableSupply) public {
// lockable supply is the token balance of this contract
require(_lockableSupply <= super.balanceOf(address(this)), "ERC20TransferLiquidityLock::lockLiquidity: lock amount higher than lockable balance");
require(_lockableSupply != 0, "ERC20TransferLiquidityLock::lockLiquidity: lock amount cannot be 0");
uint256 initialLockableSupply = _lockableSupply;
if (devDivisor != 0){
uint256 devAmt = initialLockableSupply.div(devDivisor);
_lockableSupply = _lockableSupply.sub(devAmt);
super._transfer(address(this), liquidLockDevAddress, devAmt);
}
if (poolDivisor != 0){
uint256 poolAmt = initialLockableSupply.div(poolDivisor);
_lockableSupply = _lockableSupply.sub(poolAmt);
uint256 amountToSwapForEth = poolAmt.div(2);
uint256 amountToAddLiquidity = poolAmt.sub(amountToSwapForEth);
// needed in case contract already owns eth
uint256 ethBalanceBeforeSwap = address(this).balance;
swapTokensForEth(amountToSwapForEth);
uint256 ethReceived = address(this).balance.sub(ethBalanceBeforeSwap);
addLiquidity(amountToAddLiquidity, ethReceived);
emit AddLiquidity(amountToAddLiquidity, ethReceived);
burnLiquidity();
}
if (lpRewardDivisor != 0){
uint256 lpRewardAmt = initialLockableSupply.div(lpRewardDivisor);
_lockableSupply = _lockableSupply.sub(lpRewardAmt);
_rewardLiquidityProviders(lpRewardAmt);
}
// remaining is burnt.
_burn(address(this), _lockableSupply);
emit BurnTokens(_lockableSupply);
}
// external util so anyone can easily distribute rewards
// must call lockLiquidity first which automatically
// calls _rewardLiquidityProviders
function rewardLiquidityProviders() external {
// lock everything that is lockable
lockLiquidity(super.balanceOf(address(this)));
}
function _rewardLiquidityProviders(uint256 liquidityRewards) private {
require(uniswapV2Pair != address(0), "uniswapV2Pair not set!");
// avoid burn by calling super._transfer directly
super._transfer(address(this), uniswapV2Pair, liquidityRewards);
IUniswapV2Pair(uniswapV2Pair).sync();
emit RewardLiquidityProviders(liquidityRewards);
}
function burnLiquidity() internal {
uint256 balance = ERC20(uniswapV2Pair).balanceOf(address(this));
require(balance != 0, "ERC20TransferLiquidityLock::burnLiquidity: burn amount cannot be 0");
ERC20(uniswapV2Pair).transfer(address(0), balance);
emit BurnedLiquidity(balance);
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory uniswapPairPath = new address[](2);
uniswapPairPath[0] = address(this);
uniswapPairPath[1] = IUniswapV2Router02(uniswapV2Router).WETH();
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
uniswapPairPath,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
super._approve(address(this), uniswapV2Router, tokenAmount);
IUniswapV2Router02(uniswapV2Router)
.addLiquidityETH{value: ethAmount}
(
address(this),
tokenAmount,
0,
0,
address(this),
block.timestamp
);
}
// returns token amount
function lockableSupply() external view returns (uint256) {
return super.balanceOf(address(this));
}
// returns token amount
function lockedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = lockedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _lockedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _lockedSupply;
}
// returns token amount
function burnedSupply() external view returns (uint256) {
uint256 lpTotalSupply = ERC20(uniswapV2Pair).totalSupply();
uint256 lpBalance = burnedLiquidity();
uint256 percentOfLpTotalSupply = lpBalance.mul(1e12).div(lpTotalSupply);
uint256 uniswapBalance = super.balanceOf(uniswapV2Pair);
uint256 _burnedSupply = uniswapBalance.mul(percentOfLpTotalSupply).div(1e12);
return _burnedSupply;
}
// returns LP amount, not token amount
function burnableLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(this));
}
// returns LP amount, not token amount
function burnedLiquidity() public view returns (uint256) {
return ERC20(uniswapV2Pair).balanceOf(address(0));
}
// returns LP amount, not token amount
function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
} | lockedLiquidity | function lockedLiquidity() public view returns (uint256) {
return burnableLiquidity().add(burnedLiquidity());
}
| // returns LP amount, not token amount | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f969306797bf890d2262b1bdc989f84d358e814b1d35dd9ae2010e6f1c5c9201 | {
"func_code_index": [
8762,
8892
]
} | 358 |
||
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | Owned | contract Owned {
address public owner;
event OwnershipTransferred(address indexed _from, address indexed _to);
constructor() public {
owner = 0x8d84F107D0eBC8A7b1c56E6676040863F9311f6F;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
// transfer Ownership to other address
function transferOwnership(address _newOwner) public onlyOwner {
require(_newOwner != address(0x0));
emit OwnershipTransferred(owner,_newOwner);
owner = _newOwner;
}
} | // ----------------------------------------------------------------------------
// Ownership contract
// ---------------------------------------------------------------------------- | LineComment | transferOwnership | function transferOwnership(address _newOwner) public onlyOwner {
require(_newOwner != address(0x0));
emit OwnershipTransferred(owner,_newOwner);
owner = _newOwner;
}
| // transfer Ownership to other address | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
356,
558
]
} | 359 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | function() public payable {
getTokens();
}
| // ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ---------------------------------------------------------------------------- | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
1341,
1402
]
} | 360 |
|
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | getTokens | function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
| // ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ---------------------------------------------------------------------------- | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
1701,
2122
]
} | 361 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | totalSupply | function totalSupply() public view returns (uint) {
return _totalSupply;
}
| // ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
2308,
2401
]
} | 362 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | balanceOf | function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
| // ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
2621,
2746
]
} | 363 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | transfer | function transfer(address to, uint tokens) public returns (bool success) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
3092,
3482
]
} | 364 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | approve | function approve(address spender, uint tokens) public returns (bool success) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
3993,
4279
]
} | 365 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
4777,
5330
]
} | 366 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | allowance | function allowance(address tokenOwner, address spender) public view 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.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
5613,
5765
]
} | 367 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | increaseApproval | function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| // ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
6343,
6672
]
} | 368 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | decreaseApproval | function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| // ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
7255,
7754
]
} | 369 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | changeRate | function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
| // ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
7955,
8106
]
} | 370 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | mint | function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
| // ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
8478,
8913
]
} | 371 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | stopICO | function stopICO() onlyOwner public {
isStopped = true;
}
| // ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
9113,
9189
]
} | 372 |
KUNTokens | KUNTokens.sol | 0xfc09986798267ff95c804a755240da9b18d677c3 | Solidity | KUNTokens | contract KUNTokens is ERC20Interface, Owned {
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public RATE;
uint public DENOMINATOR;
bool public isStopped = false;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed to, uint256 amount);
event ChangeRate(uint256 amount);
modifier onlyWhenRunning {
require(!isStopped);
_;
}
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "KUN";
name = "Kun Coin";
decimals = 18;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
RATE = 2000000000; // 200k tokens per 1 ether
DENOMINATOR = 10000;
emit Transfer(address(0), owner, _totalSupply);
}
// ----------------------------------------------------------------------------
// It invokes when someone sends ETH to this contract address
// ----------------------------------------------------------------------------
function() public payable {
getTokens();
}
// ----------------------------------------------------------------------------
// Low level token purchase function
// tokens are transferred to user
// ETH are transferred to current owner
// ----------------------------------------------------------------------------
function getTokens() onlyWhenRunning public payable {
require(msg.value > 0);
uint tokens = msg.value.mul(RATE).div(DENOMINATOR);
require(balances[owner] >= tokens);
balances[msg.sender] = balances[msg.sender].add(tokens);
balances[owner] = balances[owner].sub(tokens);
emit Transfer(owner, msg.sender, tokens);
owner.transfer(msg.value);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public view returns (uint) {
return _totalSupply;
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public view 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) {
require(to != address(0));
require(tokens > 0);
require(balances[msg.sender] >= tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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-token-standard.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) {
require(spender != address(0));
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit 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
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
require(from != address(0));
require(to != address(0));
require(tokens > 0);
require(balances[from] >= tokens);
require(allowed[from][msg.sender] >= tokens);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit 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 view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Increase the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To increment
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _addedValue The amount of tokens to increase the allowance by.
// ------------------------------------------------------------------------
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
require(_spender != address(0));
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Decrease the amount of tokens that an owner allowed to a spender.
//
// approve should be called when allowed[_spender] == 0. To decrement
// allowed value is better to use this function to avoid 2 calls (and wait until
// the first transaction is mined)
// _spender The address which will spend the funds.
// _subtractedValue The amount of tokens to decrease the allowance by.
// ------------------------------------------------------------------------
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
require(_spender != address(0));
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
// ------------------------------------------------------------------------
// Change the ETH to IO rate
// ------------------------------------------------------------------------
function changeRate(uint256 _rate) public onlyOwner {
require(_rate > 0);
RATE =_rate;
emit ChangeRate(_rate);
}
// ------------------------------------------------------------------------
// Function to mint tokens
// _to The address that will receive the minted tokens.
// _amount The amount of tokens to mint.
// A boolean that indicates if the operation was successful.
// ------------------------------------------------------------------------
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
require(_to != address(0));
require(_amount > 0);
uint newamount = _amount * 10**uint(decimals);
_totalSupply = _totalSupply.add(newamount);
balances[_to] = balances[_to].add(newamount);
emit Mint(_to, newamount);
emit Transfer(address(0), _to, newamount);
return true;
}
// ------------------------------------------------------------------------
// function to stop the ICO
// ------------------------------------------------------------------------
function stopICO() onlyOwner public {
isStopped = true;
}
// ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------
function resumeICO() onlyOwner public {
isStopped = false;
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | resumeICO | function resumeICO() onlyOwner public {
isStopped = false;
}
| // ------------------------------------------------------------------------
// function to resume ICO
// ------------------------------------------------------------------------ | LineComment | v0.4.26+commit.4563c3fc | MIT | bzzr://a9aa2812f680342d8f830d65f8e49570c2d44c9187930120b0644cef1f087fcd | {
"func_code_index": [
9387,
9466
]
} | 373 |
RingMusic | RingMusic.sol | 0x82c5e2dd3d4652701c1da91d364a383edbaa0686 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
| /**
* @dev Multiplies two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://cd81418324899a202110c36cf740450630e8098745e9134b02521ea17ee3d4fc | {
"func_code_index": [
95,
302
]
} | 374 |
|
RingMusic | RingMusic.sol | 0x82c5e2dd3d4652701c1da91d364a383edbaa0686 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
| /**
* @dev Integer division of two numbers, truncating the quotient.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://cd81418324899a202110c36cf740450630e8098745e9134b02521ea17ee3d4fc | {
"func_code_index": [
392,
692
]
} | 375 |
|
RingMusic | RingMusic.sol | 0x82c5e2dd3d4652701c1da91d364a383edbaa0686 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
| /**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://cd81418324899a202110c36cf740450630e8098745e9134b02521ea17ee3d4fc | {
"func_code_index": [
812,
940
]
} | 376 |
|
RingMusic | RingMusic.sol | 0x82c5e2dd3d4652701c1da91d364a383edbaa0686 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
| /**
* @dev Adds two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://cd81418324899a202110c36cf740450630e8098745e9134b02521ea17ee3d4fc | {
"func_code_index": [
1010,
1156
]
} | 377 |
|
Creature | contracts/Creature.sol | 0xda396a2fc5f0e3a87a874757f1317102f49da5b0 | Solidity | Creature | contract Creature is TradeableERC721Token {
string public metadata;
constructor(address _proxyRegistryAddress, string memory _metadata, string memory _name) TradeableERC721Token(_name, "RELAX", _proxyRegistryAddress) public {
metadata = _metadata;
}
function updatemetadata(string memory _metadata) public onlyOwner{
metadata = _metadata;
}
function baseTokenURI() public view returns (string memory) {
return metadata;
}
// The only token contract owner can burn the token.
function burn(uint256 _tokenId) public onlyOwner {
_burn(msg.sender, _tokenId);
}
} | /**
* @title Creature
* Creature - a contract for my non-fungible creatures.
*/ | NatSpecMultiLine | burn | function burn(uint256 _tokenId) public onlyOwner {
_burn(msg.sender, _tokenId);
}
| // The only token contract owner can burn the token. | LineComment | v0.5.12+commit.7709ece9 | None | bzzr://f67c4a3b52bfc13e940ea61d0409c8ac3aedf1b9704cc9b99e361d7fc7a469e2 | {
"func_code_index": [
521,
613
]
} | 378 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
| /**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
421,
534
]
} | 379 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
| /**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
951,
1370
]
} | 380 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
| /**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
1867,
2436
]
} | 381 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | approve | function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
| /**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
2764,
2974
]
} | 382 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | AbstractToken | contract AbstractToken is Token, SafeMath {
/**
* Create new Abstract Token contract.
*/
constructor () public {
// Do nothing
}
/**
* Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return accounts [_owner];
}
/**
* Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
if (accounts [msg.sender] < _value) return false;
if (_value > 0 && msg.sender != _to) {
accounts [msg.sender] = safeSub (accounts [msg.sender], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer (msg.sender, _to, _value);
return true;
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
* accounts [_to] + _value > accounts [_to] for overflow check
* which is already in safeMath
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(_to != address(0));
if (allowances [_from][msg.sender] < _value) return false;
if (accounts [_from] < _value) return false;
if (_value > 0 && _from != _to) {
allowances [_from][msg.sender] = safeSub (allowances [_from][msg.sender], _value);
accounts [_from] = safeSub (accounts [_from], _value);
accounts [_to] = safeAdd (accounts [_to], _value);
}
emit Transfer(_from, _to, _value);
return true;
}
/**
* Allow given spender to transfer given number of tokens from message sender.
* @param _spender address to allow the owner of to transfer tokens from message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public returns (bool success) {
allowances [msg.sender][_spender] = _value;
emit Approval (msg.sender, _spender, _value);
return true;
}
/**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
/**
* Mapping from addresses of token holders to the numbers of tokens belonging
* to these token holders.
*/
mapping (address => uint256) accounts;
/**
* Mapping from addresses of token holders to the mapping of addresses of
* spenders to the allowances set by these token holders to these spenders.
*/
mapping (address => mapping (address => uint256)) private allowances;
} | /**
* Abstract Token Smart Contract that could be used as a base contract for
* ERC-20 token contracts.
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view
returns (uint256 remaining) {
return allowances [_owner][_spender];
}
| /**
* Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
3422,
3570
]
} | 383 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
| /**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
932,
1025
]
} | 384 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
f (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
| /**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
1478,
1689
]
} | 385 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
equire(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
| /**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
2085,
2326
]
} | 386 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | approve | function approve (address _spender, uint256 _value) public
returns (bool success) {
equire(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
| /**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
3012,
3227
]
} | 387 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | createTokens | function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
| /**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
3493,
4011
]
} | 388 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | setOwner | function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
| /**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
4198,
4313
]
} | 389 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | freezeTransfers | function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
| /**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
4414,
4568
]
} | 390 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | unfreezeTransfers | function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
| /**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
4671,
4829
]
} | 391 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | refundTokens | function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
| /*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/ | Comment | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
5248,
5547
]
} | 392 |
WFT | WFT.sol | 0x8b9f1a6f9ad81aceed5760e21744e8e6e4d9510c | Solidity | WFT | contract WFT is AbstractToken {
/**
* Maximum allowed number of tokens in circulation.
* tokenSupply = tokensIActuallyWant * (10 ^ decimals)
*/
uint256 constant MAX_TOKEN_COUNT = 170000000 * (10**6);
/**
* Address of the owner of this smart contract.
*/
address private owner;
/**
* Frozen account list holder
*/
mapping (address => bool) private frozenAccount;
/**
* Current number of tokens in circulation.
*/
uint256 tokenCount = 0;
/**
* True if tokens transfers are currently frozen, false otherwise.
*/
bool frozen = false;
/**
* Create new token smart contract and make msg.sender the
* owner of this smart contract.
*/
constructor () public {
owner = msg.sender;
}
/**
* Get total number of tokens in circulation.
*
* @return total number of tokens in circulation
*/
function totalSupply() public view returns (uint256 supply) {
return tokenCount;
}
string constant public name = "world Financial token";
string constant public symbol = "WFT";
uint8 constant public decimals = 6;
/**
* Transfer given number of tokens from message sender to given recipient.
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer(address _to, uint256 _value) public returns (bool success) {
require(!frozenAccount[msg.sender]);
if (frozen) return false;
else return AbstractToken.transfer (_to, _value);
}
/**
* Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom(address _from, address _to, uint256 _value) public
returns (bool success) {
require(!frozenAccount[_from]);
if (frozen) return false;
else return AbstractToken.transferFrom (_from, _to, _value);
}
/**
* Change how many tokens given spender is allowed to transfer from message
* spender. In order to prevent double spending of allowance,
* To change the approve amount you first have to reduce the addresses`
* allowance to zero by calling `approve(_spender, 0)` if it is not
* already 0 to mitigate the race condition described here:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) public
returns (bool success) {
require(allowance (msg.sender, _spender) == 0 || _value == 0);
return AbstractToken.approve (_spender, _value);
}
/**
* Create _value new tokens and give new created tokens to msg.sender.
* May only be called by smart contract owner.
*
* @param _value number of tokens to create
* @return true if tokens were created successfully, false otherwise
*/
function createTokens(uint256 _value) public
returns (bool success) {
require (msg.sender == owner);
if (_value > 0) {
if (_value > safeSub (MAX_TOKEN_COUNT, tokenCount)) return false;
accounts [msg.sender] = safeAdd (accounts [msg.sender], _value);
tokenCount = safeAdd (tokenCount, _value);
// adding transfer event and _from address as null address
emit Transfer(address(0), msg.sender, _value);
return true;
}
return false;
}
/**
* Set new owner for the smart contract.
* May only be called by smart contract owner.
*
* @param _newOwner address of new owner of the smart contract
*/
function setOwner(address _newOwner) public {
require (msg.sender == owner);
owner = _newOwner;
}
/**
* Freeze ALL token transfers.
* May only be called by smart contract owner.
*/
function freezeTransfers () public {
require (msg.sender == owner);
if (!frozen) {
frozen = true;
emit Freeze ();
}
}
/**
* Unfreeze ALL token transfers.
* May only be called by smart contract owner.
*/
function unfreezeTransfers () public {
require (msg.sender == owner);
if (frozen) {
frozen = false;
emit Unfreeze ();
}
}
/*A user is able to unintentionally send tokens to a contract
* and if the contract is not prepared to refund them they will get stuck in the contract.
* The same issue used to happen for Ether too but new Solidity versions added the payable modifier to
* prevent unintended Ether transfers. However, there’s no such mechanism for token transfers.
* so the below function is created
*/
function refundTokens(address _token, address _refund, uint256 _value) public {
require (msg.sender == owner);
require(_token != address(this));
AbstractToken token = AbstractToken(_token);
token.transfer(_refund, _value);
emit RefundTokens(_token, _refund, _value);
}
/**
* Freeze specific account
* May only be called by smart contract owner.
*/
function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
}
/**
* Logged when token transfers were frozen.
*/
event Freeze ();
/**
* Logged when token transfers were unfrozen.
*/
event Unfreeze ();
/**
* Logged when a particular account is frozen.
*/
event FrozenFunds(address target, bool frozen);
/**
* when accidentally send other tokens are refunded
*/
event RefundTokens(address _token, address _refund, uint256 _value);
} | /**
* world Financial token smart contract.
*/ | NatSpecMultiLine | freezeAccount | function freezeAccount(address _target, bool freeze) public {
require (msg.sender == owner);
require (msg.sender != _target);
frozenAccount[_target] = freeze;
emit FrozenFunds(_target, freeze);
| /**
* Freeze specific account
* May only be called by smart contract owner.
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://78a9700485b4b2907d51c2174b1cdc7420bcea4f5af2fd8a69d8592c01900e0b | {
"func_code_index": [
5646,
5871
]
} | 393 |
XSwapProxyV1 | contracts/lib/Address.sol | 0x82484b7e77e4b80de6d78bdf9014e44cc715f66a | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash =
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/
function toPayable(address account)
internal
pure
returns (address payable)
{
return address(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount).gas(9100)("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | isContract | function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash =
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}
| /**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | None | bzzr://316a544e1f11cd7e0e41ffde4e03125d20f67cb26ff89413baa1890feb4e765a | {
"func_code_index": [
606,
1265
]
} | 394 |
XSwapProxyV1 | contracts/lib/Address.sol | 0x82484b7e77e4b80de6d78bdf9014e44cc715f66a | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash =
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/
function toPayable(address account)
internal
pure
returns (address payable)
{
return address(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount).gas(9100)("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | toPayable | function toPayable(address account)
internal
pure
returns (address payable)
{
return address(uint160(account));
}
| /**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | None | bzzr://316a544e1f11cd7e0e41ffde4e03125d20f67cb26ff89413baa1890feb4e765a | {
"func_code_index": [
1477,
1641
]
} | 395 |
XSwapProxyV1 | contracts/lib/Address.sol | 0x82484b7e77e4b80de6d78bdf9014e44cc715f66a | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash =
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/
function toPayable(address account)
internal
pure
returns (address payable)
{
return address(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount).gas(9100)("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | sendValue | function sendValue(address payable recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount).gas(9100)("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
| /**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | None | bzzr://316a544e1f11cd7e0e41ffde4e03125d20f67cb26ff89413baa1890feb4e765a | {
"func_code_index": [
2613,
3073
]
} | 396 |
GoldBitCoin | GoldBitCoin.sol | 0x2cdf36dd45444c2949fffaa9044ce99ba4cdadb8 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken, owned {
mapping (address => mapping (address => uint256)) internal allowed;
mapping (address => bool) public frozenAccount;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
require(!frozenAccount[_from]);
require(!frozenAccount[_to]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function burn(uint256 _value) public returns (bool success) {
require(balances[msg.sender] >= _value); // Check if the sender has enough
//balances[msg.sender] -= _value; // Subtract from the sender
balances[msg.sender] = balances[msg.sender].sub(_value);
//totalSupply -= _value; // Updates totalSupply
totalSupply = totalSupply.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
function burnFrom(address _from, uint256 _value) onlyOwner public returns (bool success) {
require(balances[_from] >= _value); // Check if the targeted balance is enough
require(_value <= allowed[_from][msg.sender]); // Check allowance
//balances[_from] -= _value; // Subtract from the targeted balance
balances[_from] = balances[_from].sub(_value);
//allowed[_from][msg.sender] -= _value; // Subtract from the sender's allowance
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
//totalSupply -= _value; // Update totalSupply
totalSupply = totalSupply.sub(_value);
emit Burn(_from, _value);
return true;
}
function mintToken(address target, uint256 initialSupply) onlyOwner public returns (bool success) {
//balances[target] += initialSupply;
balances[target] = balances[target].add(initialSupply);
//totalSupply += initialSupply;
totalSupply = totalSupply.add(initialSupply);
emit Transfer(address(0), address(this), initialSupply);
emit Transfer(address(this), target, initialSupply);
return true;
}
function freezeAccount(address target, bool freeze) onlyOwner public returns (bool success) {
frozenAccount[target] = freeze;
emit FrozenFunds(target, freeze);
return true;
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
require(!frozenAccount[_from]);
require(!frozenAccount[_to]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | GNU GPLv2 | bzzr://cbcac90a4f93136a0f2f4c9857b47e3e7df0714f550d9fd1461351412f5dec7c | {
"func_code_index": [
461,
996
]
} | 397 |
||
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Fallback | abstract contract Fallback {
/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
fallback() external payable {
_fallback();
}
/**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/
receive() external payable {
_fallback();
}
/**
* @return The Address of the implementation.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/
function _willFallback() internal virtual {}
/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
} | /**
* @title Fallback
* @dev Implements delegation of calls to other contracts, with proper
* forwarding of return values and bubbling of failures.
* It defines a fallback function that delegates all calls to the address
* returned by the abstract _implementation() internal function.
*/ | NatSpecMultiLine | /**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
125,
188
]
} | 398 |
||
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Fallback | abstract contract Fallback {
/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
fallback() external payable {
_fallback();
}
/**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/
receive() external payable {
_fallback();
}
/**
* @return The Address of the implementation.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/
function _willFallback() internal virtual {}
/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
} | /**
* @title Fallback
* @dev Implements delegation of calls to other contracts, with proper
* forwarding of return values and bubbling of failures.
* It defines a fallback function that delegates all calls to the address
* returned by the abstract _implementation() internal function.
*/ | NatSpecMultiLine | /**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
285,
347
]
} | 399 |
||
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Fallback | abstract contract Fallback {
/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
fallback() external payable {
_fallback();
}
/**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/
receive() external payable {
_fallback();
}
/**
* @return The Address of the implementation.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/
function _willFallback() internal virtual {}
/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
} | /**
* @title Fallback
* @dev Implements delegation of calls to other contracts, with proper
* forwarding of return values and bubbling of failures.
* It defines a fallback function that delegates all calls to the address
* returned by the abstract _implementation() internal function.
*/ | NatSpecMultiLine | _implementation | function _implementation() internal view virtual returns (address);
| /**
* @return The Address of the implementation.
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
419,
491
]
} | 400 |
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Fallback | abstract contract Fallback {
/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
fallback() external payable {
_fallback();
}
/**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/
receive() external payable {
_fallback();
}
/**
* @return The Address of the implementation.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/
function _willFallback() internal virtual {}
/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
} | /**
* @title Fallback
* @dev Implements delegation of calls to other contracts, with proper
* forwarding of return values and bubbling of failures.
* It defines a fallback function that delegates all calls to the address
* returned by the abstract _implementation() internal function.
*/ | NatSpecMultiLine | _delegate | function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
| /**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
794,
1737
]
} | 401 |
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Fallback | abstract contract Fallback {
/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
fallback() external payable {
_fallback();
}
/**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/
receive() external payable {
_fallback();
}
/**
* @return The Address of the implementation.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/
function _willFallback() internal virtual {}
/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
} | /**
* @title Fallback
* @dev Implements delegation of calls to other contracts, with proper
* forwarding of return values and bubbling of failures.
* It defines a fallback function that delegates all calls to the address
* returned by the abstract _implementation() internal function.
*/ | NatSpecMultiLine | _willFallback | function _willFallback() internal virtual {}
| /**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
1960,
2009
]
} | 402 |
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Fallback | abstract contract Fallback {
/**
* @dev Fallback function.
* Implemented entirely in `_fallback`.
*/
fallback() external payable {
_fallback();
}
/**
* @dev Receive function.
* Implemented entirely in `_fallback`.
*/
receive() external payable {
_fallback();
}
/**
* @return The Address of the implementation.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates execution to an implementation contract.
* This is a low level function that doesn't return to its internal call site.
* It will return to the external caller whatever the implementation returns.
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev Function that is run as the first thing in the fallback function.
* Can be redefined in derived contracts to add functionality.
* Redefinitions must call super._willFallback().
*/
function _willFallback() internal virtual {}
/**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/
function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
} | /**
* @title Fallback
* @dev Implements delegation of calls to other contracts, with proper
* forwarding of return values and bubbling of failures.
* It defines a fallback function that delegates all calls to the address
* returned by the abstract _implementation() internal function.
*/ | NatSpecMultiLine | _fallback | function _fallback() internal {
_willFallback();
_delegate(_implementation());
}
| /**
* @dev fallback implementation.
* Extracted to enable manual triggering.
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
2115,
2223
]
} | 403 |
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
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 Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(
address target,
bytes memory data,
uint256 weiValue,
string memory errorMessage
) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{value: weiValue}(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @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.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
606,
1055
]
} | 404 |
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
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 Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(
address target,
bytes memory data,
uint256 weiValue,
string memory errorMessage
) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{value: weiValue}(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | sendValue | function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
| /**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
1985,
2385
]
} | 405 |
VaultRouter | VaultRouter.sol | 0x9e9f4b105e10a66b27c771811ce4defbd44567d2 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
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 Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(
address target,
bytes memory data,
uint256 weiValue,
string memory errorMessage
) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{value: weiValue}(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | /**
* @dev Collection of functions related to the address type
*/ | NatSpecMultiLine | functionCall | function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
| /**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.8.4+commit.c7e474f2 | MIT | ipfs://38ce5c6af5f119df33d6c128c761796ed6341eb5d78756f5cf54835a34958588 | {
"func_code_index": [
3141,
3321
]
} | 406 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.