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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AiamasksNFT | AiamasksNFT.sol | 0x4922787c7f068706eec5c764d9b5166554b90de5 | Solidity | ERC721Enumerable | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC721)
returns (bool)
{
return
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
} | /**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
| /**
* @dev See {IERC721Enumerable-totalSupply}.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | None | ipfs://605c47d7ced8e9458e951312d3496a40737c3b1ac458c49169186b5926129533 | {
"func_code_index": [
1408,
1526
]
} | 4,100 |
AiamasksNFT | AiamasksNFT.sol | 0x4922787c7f068706eec5c764d9b5166554b90de5 | Solidity | ERC721Enumerable | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC721)
returns (bool)
{
return
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
} | /**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/ | NatSpecMultiLine | tokenByIndex | function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
| /**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | None | ipfs://605c47d7ced8e9458e951312d3496a40737c3b1ac458c49169186b5926129533 | {
"func_code_index": [
1598,
1923
]
} | 4,101 |
AiamasksNFT | AiamasksNFT.sol | 0x4922787c7f068706eec5c764d9b5166554b90de5 | Solidity | ERC721Enumerable | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC721)
returns (bool)
{
return
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
} | /**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/ | NatSpecMultiLine | _beforeTokenTransfer | function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
| /**
* @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.8.0+commit.c7dfd78e | None | ipfs://605c47d7ced8e9458e951312d3496a40737c3b1ac458c49169186b5926129533 | {
"func_code_index": [
2531,
3125
]
} | 4,102 |
AiamasksNFT | AiamasksNFT.sol | 0x4922787c7f068706eec5c764d9b5166554b90de5 | Solidity | ERC721Enumerable | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC721)
returns (bool)
{
return
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
} | /**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/ | NatSpecMultiLine | _addTokenToOwnerEnumeration | function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
| /**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | None | ipfs://605c47d7ced8e9458e951312d3496a40737c3b1ac458c49169186b5926129533 | {
"func_code_index": [
3421,
3647
]
} | 4,103 |
AiamasksNFT | AiamasksNFT.sol | 0x4922787c7f068706eec5c764d9b5166554b90de5 | Solidity | ERC721Enumerable | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC721)
returns (bool)
{
return
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
} | /**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/ | NatSpecMultiLine | _addTokenToAllTokensEnumeration | function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
| /**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | None | ipfs://605c47d7ced8e9458e951312d3496a40737c3b1ac458c49169186b5926129533 | {
"func_code_index": [
3843,
4012
]
} | 4,104 |
AiamasksNFT | AiamasksNFT.sol | 0x4922787c7f068706eec5c764d9b5166554b90de5 | Solidity | ERC721Enumerable | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC721)
returns (bool)
{
return
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
} | /**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/ | NatSpecMultiLine | _removeTokenFromOwnerEnumeration | function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
| /**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | None | ipfs://605c47d7ced8e9458e951312d3496a40737c3b1ac458c49169186b5926129533 | {
"func_code_index": [
4634,
5641
]
} | 4,105 |
AiamasksNFT | AiamasksNFT.sol | 0x4922787c7f068706eec5c764d9b5166554b90de5 | Solidity | ERC721Enumerable | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC721)
returns (bool)
{
return
interfaceId == type(IERC721Enumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721.balanceOf(owner),
"ERC721Enumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index)
public
view
virtual
override
returns (uint256)
{
require(
index < ERC721Enumerable.totalSupply(),
"ERC721Enumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @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 override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId)
private
{
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
} | /**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/ | NatSpecMultiLine | _removeTokenFromAllTokensEnumeration | function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
| /**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/ | NatSpecMultiLine | v0.8.0+commit.c7dfd78e | None | ipfs://605c47d7ced8e9458e951312d3496a40737c3b1ac458c49169186b5926129533 | {
"func_code_index": [
5931,
7015
]
} | 4,106 |
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
259,
445
]
} | 4,107 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
723,
864
]
} | 4,108 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
1162,
1359
]
} | 4,109 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
1613,
2089
]
} | 4,110 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
2560,
2697
]
} | 4,111 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
3188,
3471
]
} | 4,112 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
3931,
4066
]
} | 4,113 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
4546,
4717
]
} | 4,114 |
||
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | Ownable | abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | owner | function owner() public view returns (address) {
return _owner;
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
506,
590
]
} | 4,115 |
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | Ownable | abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | renounceOwnership | function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
| /**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
1148,
1301
]
} | 4,116 |
Controller | Controller.sol | 0x05aa257ef5e57bd692e5ba00f5e510328b977725 | Solidity | Ownable | abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://45c33cce26b227f47c802b42b971215ec18998881f700535f53a08eb7e56c87c | {
"func_code_index": [
1451,
1700
]
} | 4,117 |
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
88,
146
]
} | 4,118 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | decimals | function decimals() external view returns (uint8);
| /**
* @dev Returns the token decimals.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
202,
255
]
} | 4,119 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | symbol | function symbol() external view returns (string memory);
| /**
* @dev Returns the token symbol.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
309,
368
]
} | 4,120 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | name | function name() external view returns (string memory);
| /**
* @dev Returns the token name.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
418,
475
]
} | 4,121 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | getOwner | function getOwner() external view returns (address);
| /**
* @dev Returns the bep token owner.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
532,
587
]
} | 4,122 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
664,
735
]
} | 4,123 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
945,
1025
]
} | 4,124 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | allowance | function allowance(address _owner, address spender) external view returns (uint256);
| /**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
1290,
1377
]
} | 4,125 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
2013,
2090
]
} | 4,126 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the token decimals.
*/
function decimals() external view returns (uint8);
/**
* @dev Returns the token symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the token name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the bep token owner.
*/
function getOwner() external view returns (address);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address _owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
2385,
2485
]
} | 4,127 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | TuffyInu | contract TuffyInu is Context, IERC20 {
// Ownership moved to in-contract for customizability.
address private _owner;
mapping (address => uint256) private _tOwned;
mapping (address => bool) lpPairs;
uint256 private timeSinceLastPair = 0;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFees;
mapping (address => bool) private _isExcludedFromLimits;
mapping (address => bool) private _liquidityHolders;
mapping (address => uint256) private firstBuy;
uint256 constant private startingSupply = 1_000_000_000_000;
string constant private _name = "Tuffy Inu";
string constant private _symbol = "TFI";
uint8 constant private _decimals = 9;
uint256 constant private _tTotal = startingSupply * 10**_decimals;
struct Fees {
uint16 buyFee;
uint16 sellFee;
uint16 transferFee;
uint16 antiDump;
}
struct Ratios {
uint16 liquidity;
uint16 marketing;
uint16 total;
}
Fees public _taxRates = Fees({
buyFee: 1750,
sellFee: 2400,
transferFee: 0,
antiDump: 3000
});
Ratios public _ratios = Ratios({
liquidity: 35,
marketing: 380,
total: 35+380
});
uint256 constant public maxBuyTaxes = 2500;
uint256 constant public maxSellTaxes = 2500;
uint256 constant public maxTransferTaxes = 2500;
uint256 constant masterTaxDivisor = 10000;
IRouter02 public dexRouter;
address public lpPair;
address constant public DEAD = 0x000000000000000000000000000000000000dEaD;
struct TaxWallets {
address payable marketing;
address liquidity;
}
TaxWallets public _taxWallets = TaxWallets({
marketing: payable(0xeA283E387E2C67c67608b04f6BF7C7Ad318D5186),
liquidity: 0x1cd7e2284F111876759690823a8cf50a3910b9d6
});
bool inSwap;
bool public contractSwapEnabled = false;
uint256 public contractSwapTimer = 10 seconds;
uint256 private lastSwap;
uint256 public swapThreshold = (_tTotal * 5) / 10000;
uint256 public swapAmount = (_tTotal * 20) / 10000;
uint256 private _maxTxAmount = (_tTotal * 5) / 1000;
uint256 private _maxWalletSize = (_tTotal * 8) / 1000;
bool public tradingEnabled = false;
bool public _hasLiqBeenAdded = false;
AntiSnipe antiSnipe;
bool public antiDumpEnabled = true;
uint256 antiDumpTime = 10 minutes;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event ContractSwapEnabledUpdated(bool enabled);
event AutoLiquify(uint256 amountCurrency, uint256 amountTokens);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Caller =/= owner.");
_;
}
constructor () payable {
_tOwned[msg.sender] = _tTotal;
// Set the owner.
_owner = msg.sender;
if (block.chainid == 56) {
dexRouter = IRouter02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
contractSwapTimer = 3 seconds;
} else if (block.chainid == 97) {
dexRouter = IRouter02(0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3);
contractSwapTimer = 3 seconds;
} else if (block.chainid == 1 || block.chainid == 4) {
dexRouter = IRouter02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
contractSwapTimer = 10 seconds;
} else {
revert();
}
lpPair = IFactoryV2(dexRouter.factory()).createPair(dexRouter.WETH(), address(this));
lpPairs[lpPair] = true;
_approve(msg.sender, address(dexRouter), type(uint256).max);
_approve(address(this), address(dexRouter), type(uint256).max);
_isExcludedFromFees[owner()] = true;
_isExcludedFromFees[address(this)] = true;
_isExcludedFromFees[DEAD] = true;
_liquidityHolders[owner()] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
receive() external payable {}
//===============================================================================================================
//===============================================================================================================
//===============================================================================================================
// Ownable removed as a lib and added here to allow for custom transfers and renouncements.
// This allows for removal of ownership privileges from the owner once renounced or transferred.
function owner() public view returns (address) {
return _owner;
}
function transferOwner(address newOwner) external onlyOwner() {
require(newOwner != address(0), "Call renounceOwnership to transfer owner to the zero address.");
require(newOwner != DEAD, "Call renounceOwnership to transfer owner to the zero address.");
setExcludedFromFees(_owner, false);
setExcludedFromFees(newOwner, true);
if(balanceOf(_owner) > 0) {
_transfer(_owner, newOwner, balanceOf(_owner));
}
_owner = newOwner;
emit OwnershipTransferred(_owner, newOwner);
}
function renounceOwnership() public virtual onlyOwner() {
setExcludedFromFees(_owner, false);
_owner = address(0);
emit OwnershipTransferred(_owner, address(0));
}
//===============================================================================================================
//===============================================================================================================
//===============================================================================================================
function totalSupply() external pure override returns (uint256) { if (_tTotal == 0) { revert(); } return _tTotal; }
function decimals() external pure override returns (uint8) { return _decimals; }
function symbol() external pure override returns (string memory) { return _symbol; }
function name() external pure override returns (string memory) { return _name; }
function getOwner() external view override returns (address) { return owner(); }
function allowance(address holder, address spender) external view override returns (uint256) { return _allowances[holder][spender]; }
function balanceOf(address account) public view override returns (uint256) {
return _tOwned[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function _approve(address sender, address spender, uint256 amount) private {
require(sender != address(0), "ERC20: Zero Address");
require(spender != address(0), "ERC20: Zero Address");
_allowances[sender][spender] = amount;
emit Approval(sender, spender, amount);
}
function approveContractContingency() public onlyOwner returns (bool) {
_approve(address(this), address(dexRouter), type(uint256).max);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
if (_allowances[sender][msg.sender] != type(uint256).max) {
_allowances[sender][msg.sender] -= amount;
}
return _transfer(sender, recipient, amount);
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] - subtractedValue);
return true;
}
function setNewRouter(address newRouter) public onlyOwner() {
IRouter02 _newRouter = IRouter02(newRouter);
address get_pair = IFactoryV2(_newRouter.factory()).getPair(address(this), _newRouter.WETH());
if (get_pair == address(0)) {
lpPair = IFactoryV2(_newRouter.factory()).createPair(address(this), _newRouter.WETH());
}
else {
lpPair = get_pair;
}
dexRouter = _newRouter;
_approve(address(this), address(dexRouter), type(uint256).max);
}
function setLpPair(address pair, bool enabled) external onlyOwner {
if (enabled == false) {
lpPairs[pair] = false;
antiSnipe.setLpPair(pair, false);
} else {
if (timeSinceLastPair != 0) {
require(block.timestamp - timeSinceLastPair > 3 days, "3 Day cooldown.!");
}
lpPairs[pair] = true;
timeSinceLastPair = block.timestamp;
antiSnipe.setLpPair(pair, true);
}
}
function setInitializer(address initializer) external onlyOwner {
require(!_hasLiqBeenAdded, "Liquidity is already in.");
require(initializer != address(this), "Can't be self.");
antiSnipe = AntiSnipe(initializer);
}
function setBlacklistEnabled(address account, bool enabled) external onlyOwner {
antiSnipe.setBlacklistEnabled(account, enabled);
}
function setBlacklistEnabledMultiple(address[] memory accounts, bool enabled) external onlyOwner {
antiSnipe.setBlacklistEnabledMultiple(accounts, enabled);
}
function isBlacklisted(address account) public view returns (bool) {
return antiSnipe.isBlacklisted(account);
}
function getSniperAmt() public view returns (uint256) {
return antiSnipe.getSniperAmt();
}
function removeSniper(address account) external onlyOwner {
antiSnipe.removeSniper(account);
}
function setProtectionSettings(bool _antiSnipe, bool _antiBlock, bool _algo) external onlyOwner {
antiSnipe.setProtections(_antiSnipe, _antiBlock, _algo);
}
function setTaxes(uint16 buyFee, uint16 sellFee, uint16 transferFee) external onlyOwner {
require(buyFee <= maxBuyTaxes
&& sellFee <= maxSellTaxes
&& transferFee <= maxTransferTaxes,
"Cannot exceed maximums.");
_taxRates.buyFee = buyFee;
_taxRates.sellFee = sellFee;
_taxRates.transferFee = transferFee;
}
function setRatios(uint16 liquidity, uint16 marketing) external onlyOwner {
_ratios.liquidity = liquidity;
_ratios.marketing = marketing;
_ratios.total = liquidity + marketing;
}
function setMaxTxPercent(uint256 percent, uint256 divisor) external onlyOwner {
require((_tTotal * percent) / divisor >= (_tTotal / 1000), "Max Transaction amt must be above 0.1% of total supply.");
_maxTxAmount = (_tTotal * percent) / divisor;
}
function setMaxWalletSize(uint256 percent, uint256 divisor) external onlyOwner {
require((_tTotal * percent) / divisor >= (_tTotal / 1000), "Max Wallet amt must be above 0.1% of total supply.");
_maxWalletSize = (_tTotal * percent) / divisor;
}
function setExcludedFromLimits(address account, bool enabled) external onlyOwner {
_isExcludedFromLimits[account] = enabled;
}
function isExcludedFromLimits(address account) public view returns (bool) {
return _isExcludedFromLimits[account];
}
function isExcludedFromFees(address account) public view returns(bool) {
return _isExcludedFromFees[account];
}
function setExcludedFromFees(address account, bool enabled) public onlyOwner {
_isExcludedFromFees[account] = enabled;
}
function getMaxTX() public view returns (uint256) {
return _maxTxAmount / (10**_decimals);
}
function getMaxWallet() public view returns (uint256) {
return _maxWalletSize / (10**_decimals);
}
function setSwapSettings(uint256 thresholdPercent, uint256 thresholdDivisor, uint256 amountPercent, uint256 amountDivisor, uint256 time) external onlyOwner {
swapThreshold = (_tTotal * thresholdPercent) / thresholdDivisor;
swapAmount = (_tTotal * amountPercent) / amountDivisor;
contractSwapTimer = time;
}
function setWallets(address payable marketing) external onlyOwner {
_taxWallets.marketing = payable(marketing);
}
function setLiquidityReceiver(address account) external onlyOwner {
if (_taxWallets.liquidity == address(0) || _taxWallets.liquidity == DEAD) {
revert("Auto Liq renounced.");
}
_taxWallets.liquidity = account;
}
function setContractSwapEnabled(bool enabled) external onlyOwner {
contractSwapEnabled = enabled;
emit ContractSwapEnabledUpdated(enabled);
}
function checkFirstBuy(address account) external view returns (uint256) {
return firstBuy[account];
}
function setAntiDumpEnabled(bool enabled) external onlyOwner {
antiDumpEnabled = enabled;
}
function setAntiDumpSettings(uint256 time, uint16 tax) external onlyOwner {
require(time <= 20 minutes, "Can't set above 20min.");
require(tax <= 3000, "Can't set above 30%.");
antiDumpTime = time;
_taxRates.antiDump = tax;
}
function removeLimits() external onlyOwner {
_maxTxAmount = _tTotal;
_maxWalletSize = _tTotal;
}
function _hasLimits(address from, address to) private view returns (bool) {
return from != owner()
&& to != owner()
&& tx.origin != owner()
&& !_liquidityHolders[to]
&& !_liquidityHolders[from]
&& to != DEAD
&& to != address(0)
&& from != address(this);
}
function _transfer(address from, address to, uint256 amount) internal returns (bool) {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(_hasLimits(from, to)) {
if(!tradingEnabled) {
revert("Trading not yet enabled!");
}
if(lpPairs[from] || lpPairs[to]){
if (!_isExcludedFromLimits[from] && !_isExcludedFromLimits[to]) {
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
}
}
if(to != address(dexRouter) && !lpPairs[to]) {
if (!_isExcludedFromLimits[to]) {
require(balanceOf(to) + amount <= _maxWalletSize, "Transfer amount exceeds the maxWalletSize.");
}
}
}
if (firstBuy[to] == 0) {
firstBuy[to] = block.timestamp;
}
bool takeFee = true;
if(_isExcludedFromFees[from] || _isExcludedFromFees[to]){
takeFee = false;
}
if (lpPairs[to]) {
if (!inSwap
&& contractSwapEnabled
) {
if (lastSwap + contractSwapTimer < block.timestamp) {
uint256 contractTokenBalance = balanceOf(address(this));
if (contractTokenBalance >= swapThreshold) {
if(contractTokenBalance >= swapAmount) { contractTokenBalance = swapAmount; }
contractSwap(contractTokenBalance);
lastSwap = block.timestamp;
}
}
}
}
return _finalizeTransfer(from, to, amount, takeFee);
}
function contractSwap(uint256 contractTokenBalance) private lockTheSwap {
Ratios memory ratios = _ratios;
if (ratios.total == 0) {
return;
}
if(_allowances[address(this)][address(dexRouter)] != type(uint256).max) {
_allowances[address(this)][address(dexRouter)] = type(uint256).max;
}
uint256 toLiquify = ((contractTokenBalance * ratios.liquidity) / ratios.total) / 2;
uint256 swapAmt = contractTokenBalance - toLiquify;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = dexRouter.WETH();
dexRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
swapAmt,
0,
path,
address(this),
block.timestamp
);
uint256 amtBalance = address(this).balance;
uint256 liquidityBalance = (amtBalance * toLiquify) / swapAmt;
if (toLiquify > 0) {
dexRouter.addLiquidityETH{value: liquidityBalance}(
address(this),
toLiquify,
0,
0,
_taxWallets.liquidity,
block.timestamp
);
emit AutoLiquify(liquidityBalance, toLiquify);
}
amtBalance -= liquidityBalance;
ratios.total -= ratios.liquidity;
uint256 marketingBalance = amtBalance;
if (ratios.marketing > 0) {
_taxWallets.marketing.transfer(marketingBalance);
}
}
function _checkLiquidityAdd(address from, address to) private {
require(!_hasLiqBeenAdded, "Liquidity already added and marked.");
if (!_hasLimits(from, to) && to == lpPair) {
_liquidityHolders[from] = true;
_hasLiqBeenAdded = true;
if(address(antiSnipe) == address(0)){
antiSnipe = AntiSnipe(address(this));
}
contractSwapEnabled = true;
emit ContractSwapEnabledUpdated(true);
}
}
function enableTrading() public onlyOwner {
require(!tradingEnabled, "Trading already enabled!");
require(_hasLiqBeenAdded, "Liquidity must be added.");
if(address(antiSnipe) == address(0)){
antiSnipe = AntiSnipe(address(this));
}
try antiSnipe.setLaunch(lpPair, uint32(block.number), uint64(block.timestamp), _decimals) {} catch {}
tradingEnabled = true;
}
function sweepContingency() external onlyOwner {
require(!_hasLiqBeenAdded, "Cannot call after liquidity.");
payable(owner()).transfer(address(this).balance);
}
function multiSendTokens(address[] memory accounts, uint256[] memory amounts) external {
require(accounts.length == amounts.length, "Lengths do not match.");
for (uint8 i = 0; i < accounts.length; i++) {
require(balanceOf(msg.sender) >= amounts[i]);
_transfer(msg.sender, accounts[i], amounts[i]*10**_decimals);
}
}
function multiSendPercents(address[] memory accounts, uint256[] memory percents, uint256[] memory divisors) external {
require(accounts.length == percents.length && percents.length == divisors.length, "Lengths do not match.");
for (uint8 i = 0; i < accounts.length; i++) {
require(balanceOf(msg.sender) >= (_tTotal * percents[i]) / divisors[i]);
_transfer(msg.sender, accounts[i], (_tTotal * percents[i]) / divisors[i]);
}
}
function _finalizeTransfer(address from, address to, uint256 amount, bool takeFee) private returns (bool) {
if (!_hasLiqBeenAdded) {
_checkLiquidityAdd(from, to);
if (!_hasLiqBeenAdded && _hasLimits(from, to)) {
revert("Only owner can transfer at this time.");
}
}
if (_hasLimits(from, to)) {
bool checked;
try antiSnipe.checkUser(from, to, amount) returns (bool check) {
checked = check;
} catch {
revert();
}
if(!checked) {
revert();
}
}
_tOwned[from] -= amount;
uint256 amountReceived = (takeFee) ? takeTaxes(from, to, amount) : amount;
_tOwned[to] += amountReceived;
emit Transfer(from, to, amountReceived);
return true;
}
function takeTaxes(address from, address to, uint256 amount) internal returns (uint256) {
uint256 currentFee;
if (lpPairs[from]) {
currentFee = _taxRates.buyFee;
} else if (lpPairs[to]) {
if (firstBuy[from] == 0) {
firstBuy[from] = block.timestamp;
}
if (firstBuy[from] + antiDumpTime > block.timestamp && antiDumpEnabled) {
currentFee = _taxRates.antiDump;
} else {
currentFee = _taxRates.sellFee;
}
} else {
currentFee = _taxRates.transferFee;
}
uint256 feeAmount = amount * currentFee / masterTaxDivisor;
_tOwned[address(this)] += feeAmount;
emit Transfer(from, address(this), feeAmount);
return amount - feeAmount;
}
} | owner | function owner() public view returns (address) {
return _owner;
}
| //===============================================================================================================
//===============================================================================================================
//===============================================================================================================
// Ownable removed as a lib and added here to allow for custom transfers and renouncements.
// This allows for removal of ownership privileges from the owner once renounced or transferred. | LineComment | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
4845,
4929
]
} | 4,128 |
||
TuffyInu | TuffyInu.sol | 0xf4f80510130e6d2e900846b06b576cf30e63eda9 | Solidity | TuffyInu | contract TuffyInu is Context, IERC20 {
// Ownership moved to in-contract for customizability.
address private _owner;
mapping (address => uint256) private _tOwned;
mapping (address => bool) lpPairs;
uint256 private timeSinceLastPair = 0;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFees;
mapping (address => bool) private _isExcludedFromLimits;
mapping (address => bool) private _liquidityHolders;
mapping (address => uint256) private firstBuy;
uint256 constant private startingSupply = 1_000_000_000_000;
string constant private _name = "Tuffy Inu";
string constant private _symbol = "TFI";
uint8 constant private _decimals = 9;
uint256 constant private _tTotal = startingSupply * 10**_decimals;
struct Fees {
uint16 buyFee;
uint16 sellFee;
uint16 transferFee;
uint16 antiDump;
}
struct Ratios {
uint16 liquidity;
uint16 marketing;
uint16 total;
}
Fees public _taxRates = Fees({
buyFee: 1750,
sellFee: 2400,
transferFee: 0,
antiDump: 3000
});
Ratios public _ratios = Ratios({
liquidity: 35,
marketing: 380,
total: 35+380
});
uint256 constant public maxBuyTaxes = 2500;
uint256 constant public maxSellTaxes = 2500;
uint256 constant public maxTransferTaxes = 2500;
uint256 constant masterTaxDivisor = 10000;
IRouter02 public dexRouter;
address public lpPair;
address constant public DEAD = 0x000000000000000000000000000000000000dEaD;
struct TaxWallets {
address payable marketing;
address liquidity;
}
TaxWallets public _taxWallets = TaxWallets({
marketing: payable(0xeA283E387E2C67c67608b04f6BF7C7Ad318D5186),
liquidity: 0x1cd7e2284F111876759690823a8cf50a3910b9d6
});
bool inSwap;
bool public contractSwapEnabled = false;
uint256 public contractSwapTimer = 10 seconds;
uint256 private lastSwap;
uint256 public swapThreshold = (_tTotal * 5) / 10000;
uint256 public swapAmount = (_tTotal * 20) / 10000;
uint256 private _maxTxAmount = (_tTotal * 5) / 1000;
uint256 private _maxWalletSize = (_tTotal * 8) / 1000;
bool public tradingEnabled = false;
bool public _hasLiqBeenAdded = false;
AntiSnipe antiSnipe;
bool public antiDumpEnabled = true;
uint256 antiDumpTime = 10 minutes;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event ContractSwapEnabledUpdated(bool enabled);
event AutoLiquify(uint256 amountCurrency, uint256 amountTokens);
modifier lockTheSwap {
inSwap = true;
_;
inSwap = false;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Caller =/= owner.");
_;
}
constructor () payable {
_tOwned[msg.sender] = _tTotal;
// Set the owner.
_owner = msg.sender;
if (block.chainid == 56) {
dexRouter = IRouter02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
contractSwapTimer = 3 seconds;
} else if (block.chainid == 97) {
dexRouter = IRouter02(0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3);
contractSwapTimer = 3 seconds;
} else if (block.chainid == 1 || block.chainid == 4) {
dexRouter = IRouter02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
contractSwapTimer = 10 seconds;
} else {
revert();
}
lpPair = IFactoryV2(dexRouter.factory()).createPair(dexRouter.WETH(), address(this));
lpPairs[lpPair] = true;
_approve(msg.sender, address(dexRouter), type(uint256).max);
_approve(address(this), address(dexRouter), type(uint256).max);
_isExcludedFromFees[owner()] = true;
_isExcludedFromFees[address(this)] = true;
_isExcludedFromFees[DEAD] = true;
_liquidityHolders[owner()] = true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
receive() external payable {}
//===============================================================================================================
//===============================================================================================================
//===============================================================================================================
// Ownable removed as a lib and added here to allow for custom transfers and renouncements.
// This allows for removal of ownership privileges from the owner once renounced or transferred.
function owner() public view returns (address) {
return _owner;
}
function transferOwner(address newOwner) external onlyOwner() {
require(newOwner != address(0), "Call renounceOwnership to transfer owner to the zero address.");
require(newOwner != DEAD, "Call renounceOwnership to transfer owner to the zero address.");
setExcludedFromFees(_owner, false);
setExcludedFromFees(newOwner, true);
if(balanceOf(_owner) > 0) {
_transfer(_owner, newOwner, balanceOf(_owner));
}
_owner = newOwner;
emit OwnershipTransferred(_owner, newOwner);
}
function renounceOwnership() public virtual onlyOwner() {
setExcludedFromFees(_owner, false);
_owner = address(0);
emit OwnershipTransferred(_owner, address(0));
}
//===============================================================================================================
//===============================================================================================================
//===============================================================================================================
function totalSupply() external pure override returns (uint256) { if (_tTotal == 0) { revert(); } return _tTotal; }
function decimals() external pure override returns (uint8) { return _decimals; }
function symbol() external pure override returns (string memory) { return _symbol; }
function name() external pure override returns (string memory) { return _name; }
function getOwner() external view override returns (address) { return owner(); }
function allowance(address holder, address spender) external view override returns (uint256) { return _allowances[holder][spender]; }
function balanceOf(address account) public view override returns (uint256) {
return _tOwned[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function _approve(address sender, address spender, uint256 amount) private {
require(sender != address(0), "ERC20: Zero Address");
require(spender != address(0), "ERC20: Zero Address");
_allowances[sender][spender] = amount;
emit Approval(sender, spender, amount);
}
function approveContractContingency() public onlyOwner returns (bool) {
_approve(address(this), address(dexRouter), type(uint256).max);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
if (_allowances[sender][msg.sender] != type(uint256).max) {
_allowances[sender][msg.sender] -= amount;
}
return _transfer(sender, recipient, amount);
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] - subtractedValue);
return true;
}
function setNewRouter(address newRouter) public onlyOwner() {
IRouter02 _newRouter = IRouter02(newRouter);
address get_pair = IFactoryV2(_newRouter.factory()).getPair(address(this), _newRouter.WETH());
if (get_pair == address(0)) {
lpPair = IFactoryV2(_newRouter.factory()).createPair(address(this), _newRouter.WETH());
}
else {
lpPair = get_pair;
}
dexRouter = _newRouter;
_approve(address(this), address(dexRouter), type(uint256).max);
}
function setLpPair(address pair, bool enabled) external onlyOwner {
if (enabled == false) {
lpPairs[pair] = false;
antiSnipe.setLpPair(pair, false);
} else {
if (timeSinceLastPair != 0) {
require(block.timestamp - timeSinceLastPair > 3 days, "3 Day cooldown.!");
}
lpPairs[pair] = true;
timeSinceLastPair = block.timestamp;
antiSnipe.setLpPair(pair, true);
}
}
function setInitializer(address initializer) external onlyOwner {
require(!_hasLiqBeenAdded, "Liquidity is already in.");
require(initializer != address(this), "Can't be self.");
antiSnipe = AntiSnipe(initializer);
}
function setBlacklistEnabled(address account, bool enabled) external onlyOwner {
antiSnipe.setBlacklistEnabled(account, enabled);
}
function setBlacklistEnabledMultiple(address[] memory accounts, bool enabled) external onlyOwner {
antiSnipe.setBlacklistEnabledMultiple(accounts, enabled);
}
function isBlacklisted(address account) public view returns (bool) {
return antiSnipe.isBlacklisted(account);
}
function getSniperAmt() public view returns (uint256) {
return antiSnipe.getSniperAmt();
}
function removeSniper(address account) external onlyOwner {
antiSnipe.removeSniper(account);
}
function setProtectionSettings(bool _antiSnipe, bool _antiBlock, bool _algo) external onlyOwner {
antiSnipe.setProtections(_antiSnipe, _antiBlock, _algo);
}
function setTaxes(uint16 buyFee, uint16 sellFee, uint16 transferFee) external onlyOwner {
require(buyFee <= maxBuyTaxes
&& sellFee <= maxSellTaxes
&& transferFee <= maxTransferTaxes,
"Cannot exceed maximums.");
_taxRates.buyFee = buyFee;
_taxRates.sellFee = sellFee;
_taxRates.transferFee = transferFee;
}
function setRatios(uint16 liquidity, uint16 marketing) external onlyOwner {
_ratios.liquidity = liquidity;
_ratios.marketing = marketing;
_ratios.total = liquidity + marketing;
}
function setMaxTxPercent(uint256 percent, uint256 divisor) external onlyOwner {
require((_tTotal * percent) / divisor >= (_tTotal / 1000), "Max Transaction amt must be above 0.1% of total supply.");
_maxTxAmount = (_tTotal * percent) / divisor;
}
function setMaxWalletSize(uint256 percent, uint256 divisor) external onlyOwner {
require((_tTotal * percent) / divisor >= (_tTotal / 1000), "Max Wallet amt must be above 0.1% of total supply.");
_maxWalletSize = (_tTotal * percent) / divisor;
}
function setExcludedFromLimits(address account, bool enabled) external onlyOwner {
_isExcludedFromLimits[account] = enabled;
}
function isExcludedFromLimits(address account) public view returns (bool) {
return _isExcludedFromLimits[account];
}
function isExcludedFromFees(address account) public view returns(bool) {
return _isExcludedFromFees[account];
}
function setExcludedFromFees(address account, bool enabled) public onlyOwner {
_isExcludedFromFees[account] = enabled;
}
function getMaxTX() public view returns (uint256) {
return _maxTxAmount / (10**_decimals);
}
function getMaxWallet() public view returns (uint256) {
return _maxWalletSize / (10**_decimals);
}
function setSwapSettings(uint256 thresholdPercent, uint256 thresholdDivisor, uint256 amountPercent, uint256 amountDivisor, uint256 time) external onlyOwner {
swapThreshold = (_tTotal * thresholdPercent) / thresholdDivisor;
swapAmount = (_tTotal * amountPercent) / amountDivisor;
contractSwapTimer = time;
}
function setWallets(address payable marketing) external onlyOwner {
_taxWallets.marketing = payable(marketing);
}
function setLiquidityReceiver(address account) external onlyOwner {
if (_taxWallets.liquidity == address(0) || _taxWallets.liquidity == DEAD) {
revert("Auto Liq renounced.");
}
_taxWallets.liquidity = account;
}
function setContractSwapEnabled(bool enabled) external onlyOwner {
contractSwapEnabled = enabled;
emit ContractSwapEnabledUpdated(enabled);
}
function checkFirstBuy(address account) external view returns (uint256) {
return firstBuy[account];
}
function setAntiDumpEnabled(bool enabled) external onlyOwner {
antiDumpEnabled = enabled;
}
function setAntiDumpSettings(uint256 time, uint16 tax) external onlyOwner {
require(time <= 20 minutes, "Can't set above 20min.");
require(tax <= 3000, "Can't set above 30%.");
antiDumpTime = time;
_taxRates.antiDump = tax;
}
function removeLimits() external onlyOwner {
_maxTxAmount = _tTotal;
_maxWalletSize = _tTotal;
}
function _hasLimits(address from, address to) private view returns (bool) {
return from != owner()
&& to != owner()
&& tx.origin != owner()
&& !_liquidityHolders[to]
&& !_liquidityHolders[from]
&& to != DEAD
&& to != address(0)
&& from != address(this);
}
function _transfer(address from, address to, uint256 amount) internal returns (bool) {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(_hasLimits(from, to)) {
if(!tradingEnabled) {
revert("Trading not yet enabled!");
}
if(lpPairs[from] || lpPairs[to]){
if (!_isExcludedFromLimits[from] && !_isExcludedFromLimits[to]) {
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
}
}
if(to != address(dexRouter) && !lpPairs[to]) {
if (!_isExcludedFromLimits[to]) {
require(balanceOf(to) + amount <= _maxWalletSize, "Transfer amount exceeds the maxWalletSize.");
}
}
}
if (firstBuy[to] == 0) {
firstBuy[to] = block.timestamp;
}
bool takeFee = true;
if(_isExcludedFromFees[from] || _isExcludedFromFees[to]){
takeFee = false;
}
if (lpPairs[to]) {
if (!inSwap
&& contractSwapEnabled
) {
if (lastSwap + contractSwapTimer < block.timestamp) {
uint256 contractTokenBalance = balanceOf(address(this));
if (contractTokenBalance >= swapThreshold) {
if(contractTokenBalance >= swapAmount) { contractTokenBalance = swapAmount; }
contractSwap(contractTokenBalance);
lastSwap = block.timestamp;
}
}
}
}
return _finalizeTransfer(from, to, amount, takeFee);
}
function contractSwap(uint256 contractTokenBalance) private lockTheSwap {
Ratios memory ratios = _ratios;
if (ratios.total == 0) {
return;
}
if(_allowances[address(this)][address(dexRouter)] != type(uint256).max) {
_allowances[address(this)][address(dexRouter)] = type(uint256).max;
}
uint256 toLiquify = ((contractTokenBalance * ratios.liquidity) / ratios.total) / 2;
uint256 swapAmt = contractTokenBalance - toLiquify;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = dexRouter.WETH();
dexRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
swapAmt,
0,
path,
address(this),
block.timestamp
);
uint256 amtBalance = address(this).balance;
uint256 liquidityBalance = (amtBalance * toLiquify) / swapAmt;
if (toLiquify > 0) {
dexRouter.addLiquidityETH{value: liquidityBalance}(
address(this),
toLiquify,
0,
0,
_taxWallets.liquidity,
block.timestamp
);
emit AutoLiquify(liquidityBalance, toLiquify);
}
amtBalance -= liquidityBalance;
ratios.total -= ratios.liquidity;
uint256 marketingBalance = amtBalance;
if (ratios.marketing > 0) {
_taxWallets.marketing.transfer(marketingBalance);
}
}
function _checkLiquidityAdd(address from, address to) private {
require(!_hasLiqBeenAdded, "Liquidity already added and marked.");
if (!_hasLimits(from, to) && to == lpPair) {
_liquidityHolders[from] = true;
_hasLiqBeenAdded = true;
if(address(antiSnipe) == address(0)){
antiSnipe = AntiSnipe(address(this));
}
contractSwapEnabled = true;
emit ContractSwapEnabledUpdated(true);
}
}
function enableTrading() public onlyOwner {
require(!tradingEnabled, "Trading already enabled!");
require(_hasLiqBeenAdded, "Liquidity must be added.");
if(address(antiSnipe) == address(0)){
antiSnipe = AntiSnipe(address(this));
}
try antiSnipe.setLaunch(lpPair, uint32(block.number), uint64(block.timestamp), _decimals) {} catch {}
tradingEnabled = true;
}
function sweepContingency() external onlyOwner {
require(!_hasLiqBeenAdded, "Cannot call after liquidity.");
payable(owner()).transfer(address(this).balance);
}
function multiSendTokens(address[] memory accounts, uint256[] memory amounts) external {
require(accounts.length == amounts.length, "Lengths do not match.");
for (uint8 i = 0; i < accounts.length; i++) {
require(balanceOf(msg.sender) >= amounts[i]);
_transfer(msg.sender, accounts[i], amounts[i]*10**_decimals);
}
}
function multiSendPercents(address[] memory accounts, uint256[] memory percents, uint256[] memory divisors) external {
require(accounts.length == percents.length && percents.length == divisors.length, "Lengths do not match.");
for (uint8 i = 0; i < accounts.length; i++) {
require(balanceOf(msg.sender) >= (_tTotal * percents[i]) / divisors[i]);
_transfer(msg.sender, accounts[i], (_tTotal * percents[i]) / divisors[i]);
}
}
function _finalizeTransfer(address from, address to, uint256 amount, bool takeFee) private returns (bool) {
if (!_hasLiqBeenAdded) {
_checkLiquidityAdd(from, to);
if (!_hasLiqBeenAdded && _hasLimits(from, to)) {
revert("Only owner can transfer at this time.");
}
}
if (_hasLimits(from, to)) {
bool checked;
try antiSnipe.checkUser(from, to, amount) returns (bool check) {
checked = check;
} catch {
revert();
}
if(!checked) {
revert();
}
}
_tOwned[from] -= amount;
uint256 amountReceived = (takeFee) ? takeTaxes(from, to, amount) : amount;
_tOwned[to] += amountReceived;
emit Transfer(from, to, amountReceived);
return true;
}
function takeTaxes(address from, address to, uint256 amount) internal returns (uint256) {
uint256 currentFee;
if (lpPairs[from]) {
currentFee = _taxRates.buyFee;
} else if (lpPairs[to]) {
if (firstBuy[from] == 0) {
firstBuy[from] = block.timestamp;
}
if (firstBuy[from] + antiDumpTime > block.timestamp && antiDumpEnabled) {
currentFee = _taxRates.antiDump;
} else {
currentFee = _taxRates.sellFee;
}
} else {
currentFee = _taxRates.transferFee;
}
uint256 feeAmount = amount * currentFee / masterTaxDivisor;
_tOwned[address(this)] += feeAmount;
emit Transfer(from, address(this), feeAmount);
return amount - feeAmount;
}
} | totalSupply | function totalSupply() external pure override returns (uint256) { if (_tTotal == 0) { revert(); } return _tTotal; }
| //===============================================================================================================
//===============================================================================================================
//=============================================================================================================== | LineComment | v0.8.11+commit.d7f03943 | MIT | ipfs://76d8b652679ff388179784d2e586fac21eda2bd340223e1a016eb4204ef46263 | {
"func_code_index": [
6078,
6198
]
} | 4,129 |
||
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | SafeMath | library SafeMath {
function mul(uint a, uint b) internal returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint a, uint b) internal returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint a, uint b) internal returns (uint) {
assert(b <= a);
return a - b;
}
function add(uint a, uint b) internal returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
return a >= b ? a : b;
}
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
return a < b ? a : b;
}
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
return a >= b ? a : b;
}
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
return a < b ? a : b;
}
/**
* Based on http://www.codecodex.com/wiki/Calculate_an_integer_square_root
*/
function sqrt(uint num) internal returns (uint) {
if (0 == num) { // Avoid zero divide
return 0;
}
uint n = (num / 2) + 1; // Initial estimate, never low
uint n1 = (n + (num / n)) / 2;
while (n1 < n) {
n = n1;
n1 = (n + (num / n)) / 2;
}
return n;
}
function assert(bool assertion) internal {
if (!assertion) {
throw;
}
}
} | /**
* Math operations with safety checks
*/ | NatSpecMultiLine | sqrt | function sqrt(uint num) internal returns (uint) {
if (0 == num) { // Avoid zero divide
return 0;
}
uint n = (num / 2) + 1; // Initial estimate, never low
uint n1 = (n + (num / n)) / 2;
while (n1 < n) {
n = n1;
n1 = (n + (num / n)) / 2;
}
return n;
}
| /**
* Based on http://www.codecodex.com/wiki/Calculate_an_integer_square_root
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
1182,
1517
]
} | 4,130 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint;
mapping(address => uint) balances;
/**
* @dev Fix for the ERC20 short address attack.
*/
modifier onlyPayloadSize(uint size) {
if(msg.data.length < size + 4) {
throw;
}
_;
}
/**
* @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, uint _value) onlyPayloadSize(2 * 32) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint representing the amount owned by the passed address.
*/
function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
446,
673
]
} | 4,131 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint;
mapping(address => uint) balances;
/**
* @dev Fix for the ERC20 short address attack.
*/
modifier onlyPayloadSize(uint size) {
if(msg.data.length < size + 4) {
throw;
}
_;
}
/**
* @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, uint _value) onlyPayloadSize(2 * 32) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint representing the amount owned by the passed address.
*/
function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
877,
983
]
} | 4,132 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | StandardToken | contract StandardToken is BasicToken, ERC20 {
mapping (address => mapping (address => uint)) 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 uint the amout of tokens to be transfered
*/
function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// if (_value > _allowance) throw;
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on beahlf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint _value) {
// 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
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
}
/**
* @dev Function to check the amount of tokens than 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 uint specifing the amount of tokens still avaible for the spender.
*/
function allowance(address _owner, address _spender) constant returns (uint remaining) {
return allowed[_owner][_spender];
}
} | /**
* @title Standard ERC20 token
*
* @dev Implemantation of the basic standart 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, uint _value) onlyPayloadSize(3 * 32) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// if (_value > _allowance) throw;
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
}
| /**
* @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 uint the amout of tokens to be transfered
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
382,
873
]
} | 4,133 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | StandardToken | contract StandardToken is BasicToken, ERC20 {
mapping (address => mapping (address => uint)) 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 uint the amout of tokens to be transfered
*/
function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// if (_value > _allowance) throw;
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on beahlf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint _value) {
// 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
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
}
/**
* @dev Function to check the amount of tokens than 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 uint specifing the amount of tokens still avaible for the spender.
*/
function allowance(address _owner, address _spender) constant returns (uint remaining) {
return allowed[_owner][_spender];
}
} | /**
* @title Standard ERC20 token
*
* @dev Implemantation of the basic standart 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, uint _value) {
// 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
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
}
| /**
* @dev Aprove the passed address to spend the specified amount of tokens on beahlf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
1108,
1622
]
} | 4,134 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | StandardToken | contract StandardToken is BasicToken, ERC20 {
mapping (address => mapping (address => uint)) 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 uint the amout of tokens to be transfered
*/
function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(3 * 32) {
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// if (_value > _allowance) throw;
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on beahlf of msg.sender.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint _value) {
// 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
if ((_value != 0) && (allowed[msg.sender][_spender] != 0)) throw;
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
}
/**
* @dev Function to check the amount of tokens than 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 uint specifing the amount of tokens still avaible for the spender.
*/
function allowance(address _owner, address _spender) constant returns (uint remaining) {
return allowed[_owner][_spender];
}
} | /**
* @title Standard ERC20 token
*
* @dev Implemantation of the basic standart 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) constant returns (uint remaining) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens than 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 uint specifing the amount of tokens still avaible for the spender.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
1940,
2075
]
} | 4,135 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | AdsharesToken | function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
| // constructor | LineComment | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
2020,
2301
]
} | 4,136 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | getLockedBalance | function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
| /**
* Returns not yet unlocked balance
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
2367,
2507
]
} | 4,137 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | getBuyPrice | function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
| /**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
2693,
4713
]
} | 4,138 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | getSellPrice | function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
| /**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
4875,
5892
]
} | 4,139 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
| /**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
6043,
6181
]
} | 4,140 |
||
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | buy | function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
| /**
* @dev Buy tokens without price limit
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
6250,
6400
]
} | 4,141 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | buyLimit | function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
| /**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
6552,
8146
]
} | 4,142 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | sell | function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
| /**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
8282,
8386
]
} | 4,143 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | sellLimit | function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
| /**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
8615,
9603
]
} | 4,144 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | unlockFunds | function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
| /**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
9702,
10102
]
} | 4,145 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | withdrawFunds | function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
| /**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
10194,
10548
]
} | 4,146 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | declareCrowdsaleEnd | function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
| /**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
10709,
10972
]
} | 4,147 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | confirmCrowdsaleEnd | function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
| /**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
11125,
11401
]
} | 4,148 |
|
AdsharesToken | AdsharesToken.sol | 0x422866a8f0b032c5cf1dfbdef31a20f4509562b0 | Solidity | AdsharesToken | contract AdsharesToken is StandardToken {
using SafeMath for uint;
// metadata
string public constant name = "Adshares Token";
string public constant symbol = "ADST";
uint public constant decimals = 0;
// crowdsale parameters
uint public constant tokenCreationMin = 10000000;
uint public constant tokenPriceMin = 0.0004 ether;
uint public constant tradeSpreadInvert = 50; // 2%
uint public constant crowdsaleEndLockTime = 1 weeks;
uint public constant fundingUnlockPeriod = 1 weeks;
uint public constant fundingUnlockFractionInvert = 100; // 1 %
// contructor parameters
uint public crowdsaleStartBlock;
address public owner1;
address public owner2;
address public withdrawAddress; // multi-sig wallet that will receive ether
// contract state
bool public minFundingReached;
uint public crowdsaleEndDeclarationTime = 0;
uint public fundingUnlockTime = 0;
uint public unlockedBalance = 0;
uint public withdrawnBalance = 0;
bool public isHalted = false;
// events
event LogBuy(address indexed who, uint tokens, uint purchaseValue, uint supplyAfter);
event LogSell(address indexed who, uint tokens, uint saleValue, uint supplyAfter);
event LogWithdraw(uint amount);
event LogCrowdsaleEnd(bool completed);
/**
* @dev Checks if funding is active
*/
modifier fundingActive() {
// Not yet started
if (block.number < crowdsaleStartBlock) {
throw;
}
// Already ended
if (crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime) {
throw;
}
_;
}
/**
* @dev Throws if called by any account other than one of the owners.
*/
modifier onlyOwner() {
if (msg.sender != owner1 && msg.sender != owner2) {
throw;
}
_;
}
// constructor
function AdsharesToken (address _owner1, address _owner2, address _withdrawAddress, uint _crowdsaleStartBlock)
{
owner1 = _owner1;
owner2 = _owner2;
withdrawAddress = _withdrawAddress;
crowdsaleStartBlock = _crowdsaleStartBlock;
}
/**
* Returns not yet unlocked balance
*/
function getLockedBalance() private constant returns (uint lockedBalance) {
return this.balance.sub(unlockedBalance);
}
/**
* @dev Calculates how many tokens one can buy for specified value
* @return Amount of tokens one will receive and purchase value without remainder.
*/
function getBuyPrice(uint _bidValue) constant returns (uint tokenCount, uint purchaseValue) {
// Token price formula is twofold. We have flat pricing below tokenCreationMin,
// and above that price linarly increases with supply.
uint flatTokenCount;
uint startSupply;
uint linearBidValue;
if(totalSupply < tokenCreationMin) {
uint maxFlatTokenCount = _bidValue.div(tokenPriceMin);
// entire purchase in flat pricing
if(totalSupply.add(maxFlatTokenCount) <= tokenCreationMin) {
return (maxFlatTokenCount, maxFlatTokenCount.mul(tokenPriceMin));
}
flatTokenCount = tokenCreationMin.sub(totalSupply);
linearBidValue = _bidValue.sub(flatTokenCount.mul(tokenPriceMin));
startSupply = tokenCreationMin;
} else {
flatTokenCount = 0;
linearBidValue = _bidValue;
startSupply = totalSupply;
}
// Solves quadratic equation to calculate maximum token count that can be purchased
uint currentPrice = tokenPriceMin.mul(startSupply).div(tokenCreationMin);
uint delta = (2 * startSupply).mul(2 * startSupply).add(linearBidValue.mul(4 * 1 * 2 * startSupply).div(currentPrice));
uint linearTokenCount = delta.sqrt().sub(2 * startSupply).div(2);
uint linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
// double check to eliminate rounding errors
linearTokenCount = linearBidValue / linearAvgPrice;
linearAvgPrice = currentPrice.add((startSupply+linearTokenCount+1).mul(tokenPriceMin).div(tokenCreationMin)).div(2);
purchaseValue = linearTokenCount.mul(linearAvgPrice).add(flatTokenCount.mul(tokenPriceMin));
return (
flatTokenCount + linearTokenCount,
purchaseValue
);
}
/**
* @dev Calculates average token price for sale of specified token count
* @return Total value received for given sale size.
*/
function getSellPrice(uint _askSizeTokens) constant returns (uint saleValue) {
uint flatTokenCount;
uint linearTokenMin;
if(totalSupply <= tokenCreationMin) {
return tokenPriceMin * _askSizeTokens;
}
if(totalSupply.sub(_askSizeTokens) < tokenCreationMin) {
flatTokenCount = tokenCreationMin - totalSupply.sub(_askSizeTokens);
linearTokenMin = tokenCreationMin;
} else {
flatTokenCount = 0;
linearTokenMin = totalSupply.sub(_askSizeTokens);
}
uint linearTokenCount = _askSizeTokens - flatTokenCount;
uint minPrice = (linearTokenMin).mul(tokenPriceMin).div(tokenCreationMin);
uint maxPrice = (totalSupply+1).mul(tokenPriceMin).div(tokenCreationMin);
uint linearAveragePrice = minPrice.add(maxPrice).div(2);
return linearAveragePrice.mul(linearTokenCount).add(flatTokenCount.mul(tokenPriceMin));
}
/**
* Default function called by sending Ether to this address with no arguments.
* @dev Buy tokens with market order
*/
function() payable fundingActive
{
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens without price limit
*/
function buy() payable external fundingActive {
buyLimit(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
}
/**
* @dev Buy tokens with limit maximum average price
* @param _maxPrice Maximum price user want to pay for one token
*/
function buyLimit(uint _maxPrice) payable public fundingActive {
require(msg.value >= tokenPriceMin);
assert(!isHalted);
uint boughtTokens;
uint averagePrice;
uint purchaseValue;
(boughtTokens, purchaseValue) = getBuyPrice(msg.value);
if(boughtTokens == 0) {
// bid to small, return ether and abort
msg.sender.transfer(msg.value);
return;
}
averagePrice = purchaseValue.div(boughtTokens);
if(averagePrice > _maxPrice) {
// price too high, return ether and abort
msg.sender.transfer(msg.value);
return;
}
assert(averagePrice >= tokenPriceMin);
assert(purchaseValue <= msg.value);
totalSupply = totalSupply.add(boughtTokens);
balances[msg.sender] = balances[msg.sender].add(boughtTokens);
if(!minFundingReached && totalSupply >= tokenCreationMin) {
minFundingReached = true;
fundingUnlockTime = block.timestamp;
// this.balance contains ether sent in this message
unlockedBalance += this.balance.sub(msg.value).div(tradeSpreadInvert);
}
if(minFundingReached) {
unlockedBalance += purchaseValue.div(tradeSpreadInvert);
}
LogBuy(msg.sender, boughtTokens, purchaseValue, totalSupply);
if(msg.value > purchaseValue) {
msg.sender.transfer(msg.value.sub(purchaseValue));
}
}
/**
* @dev Sell tokens without limit on price
* @param _tokenCount Amount of tokens user wants to sell
*/
function sell(uint _tokenCount) external fundingActive {
sellLimit(_tokenCount, 0);
}
/**
* @dev Sell tokens with limit on minimum average priceprice
* @param _tokenCount Amount of tokens user wants to sell
* @param _minPrice Minimum price user wants to receive for one token
*/
function sellLimit(uint _tokenCount, uint _minPrice) public fundingActive {
require(_tokenCount > 0);
assert(balances[msg.sender] >= _tokenCount);
uint saleValue = getSellPrice(_tokenCount);
uint averagePrice = saleValue.div(_tokenCount);
assert(averagePrice >= tokenPriceMin);
if(minFundingReached) {
averagePrice -= averagePrice.div(tradeSpreadInvert);
saleValue -= saleValue.div(tradeSpreadInvert);
}
if(averagePrice < _minPrice) {
// price too high, abort
return;
}
// not enough ether for buyback
assert(saleValue <= this.balance);
totalSupply = totalSupply.sub(_tokenCount);
balances[msg.sender] = balances[msg.sender].sub(_tokenCount);
LogSell(msg.sender, _tokenCount, saleValue, totalSupply);
msg.sender.transfer(saleValue);
}
/**
* @dev Unlock funds for withdrawal. Only 1% can be unlocked weekly.
*/
function unlockFunds() external onlyOwner fundingActive {
assert(minFundingReached);
assert(block.timestamp >= fundingUnlockTime);
uint unlockedAmount = getLockedBalance().div(fundingUnlockFractionInvert);
unlockedBalance += unlockedAmount;
assert(getLockedBalance() > 0);
fundingUnlockTime += fundingUnlockPeriod;
}
/**
* @dev Withdraw funds. Only unlocked funds can be withdrawn.
*/
function withdrawFunds(uint _value) external onlyOwner fundingActive onlyPayloadSize(32) {
require(_value <= unlockedBalance);
assert(minFundingReached);
unlockedBalance -= _value;
withdrawnBalance += _value;
LogWithdraw(_value);
withdrawAddress.transfer(_value);
}
/**
* @dev Declares that crowdsale is about to end. Users have one week to decide if the want to keep token or sell them to contract.
*/
function declareCrowdsaleEnd() external onlyOwner fundingActive {
assert(minFundingReached);
assert(crowdsaleEndDeclarationTime == 0);
crowdsaleEndDeclarationTime = block.timestamp;
LogCrowdsaleEnd(false);
}
/**
* @dev Can be called one week after initial declaration. Withdraws ether and stops trading. Tokens remain in circulation.
*/
function confirmCrowdsaleEnd() external onlyOwner {
assert(crowdsaleEndDeclarationTime > 0 && block.timestamp > crowdsaleEndDeclarationTime + crowdsaleEndLockTime);
LogCrowdsaleEnd(true);
withdrawAddress.transfer(this.balance);
}
/**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/
function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
} | /**
* @title Adshares ICO token
*
* see https://github.com/adshares/ico
*
*/ | NatSpecMultiLine | haltCrowdsale | function haltCrowdsale() external onlyOwner fundingActive {
assert(!minFundingReached);
isHalted = !isHalted;
}
| /**
* @dev Halts crowdsale. Can only be called before minimumFunding is reached.
* @dev When contract is halted no one can buy new tokens, but can sell them back to contract.
* @dev Function will be called if minimum funding target isn't reached for extended period of time
*/ | NatSpecMultiLine | v0.4.11+commit.68ef5810 | bzzr://af9623b560cc5be9532279843d39a290d62fb8422ed5d6f9eba3d7a8909bc8bf | {
"func_code_index": [
11715,
11854
]
} | 4,149 |
|
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | totalSupply | function totalSupply() constant returns (uint256 supply) {}
| /// @return total amount of tokens | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
60,
124
]
} | 4,150 |
||
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | balanceOf | function balanceOf(address _owner) constant returns (uint256 balance) {}
| /// @param _owner The address from which the balance will be retrieved
/// @return The balance | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
232,
309
]
} | 4,151 |
||
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | transfer | function transfer(address _to, uint256 _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
546,
623
]
} | 4,152 |
||
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
946,
1042
]
} | 4,153 |
||
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | approve | function approve(address _spender, uint256 _value) returns (bool success) {}
| /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
1326,
1407
]
} | 4,154 |
||
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | allowance | function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
| /// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent | NatSpecSingleLine | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
1615,
1712
]
} | 4,155 |
||
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | DSW | contract DSW is StandardToken {
function () {
//if ether is sent to this address, send it back.
throw;
}
string public canxaxnazka;
string public canxa1xnazka;
string public canxax5nazka;
string public canxaxn32azka;
string public canxaxnaz7ka;
string public canxaxnazk4a;
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H1.0'; //human 0.1 standard. Just an arbitrary versioning scheme.
//
// CHANGE THESE VALUES FOR YOUR TOKEN
//
//make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token
function DSW(
) {
balances[msg.sender] = 33000000 * (10 ** 18) ;
totalSupply = 33000000 * (10 ** 18) ; // Update total supply (100000 for example)
name = "swerve.fi"; // Set the name for display purposes
decimals = 0; // Amount of decimals for display purposes
symbol = "SWRV"; // Set the symbol for display purposes
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | //name this contract whatever you'd like | LineComment | DSW | function DSW(
) {
balances[msg.sender] = 33000000 * (10 ** 18) ;
totalSupply = 33000000 * (10 ** 18) ; // Update total supply (100000 for example)
name = "swerve.fi"; // Set the name for display purposes
decimals = 0; // Amount of decimals for display purposes
symbol = "SWRV"; // Set the symbol for display purposes
}
| //human 0.1 standard. Just an arbitrary versioning scheme.
//
// CHANGE THESE VALUES FOR YOUR TOKEN
//
//make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token | LineComment | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
1370,
1819
]
} | 4,156 |
DSW | DSW.sol | 0x2e795dd7751812e282fa99c67ba0c07351ec7440 | Solidity | DSW | contract DSW is StandardToken {
function () {
//if ether is sent to this address, send it back.
throw;
}
string public canxaxnazka;
string public canxa1xnazka;
string public canxax5nazka;
string public canxaxn32azka;
string public canxaxnaz7ka;
string public canxaxnazk4a;
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = 'H1.0'; //human 0.1 standard. Just an arbitrary versioning scheme.
//
// CHANGE THESE VALUES FOR YOUR TOKEN
//
//make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token
function DSW(
) {
balances[msg.sender] = 33000000 * (10 ** 18) ;
totalSupply = 33000000 * (10 ** 18) ; // Update total supply (100000 for example)
name = "swerve.fi"; // Set the name for display purposes
decimals = 0; // Amount of decimals for display purposes
symbol = "SWRV"; // Set the symbol for display purposes
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | //name this contract whatever you'd like | LineComment | approveAndCall | function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
| /* Approves and then calls the receiving contract */ | Comment | v0.4.26+commit.4563c3fc | None | bzzr://42115a9f1fbdb12d8aea64c6adaa6a57b97bed3ccb82b6bee52010c0080ec089 | {
"func_code_index": [
1880,
2685
]
} | 4,157 |
MassVestingSender | MassVestingSender.sol | 0xcbc66115e9d8655709c3408d0e320410aef1161a | 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.
*/
constructor() 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));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | transferOwnership | function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit 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.24+commit.e67f0147 | bzzr://2e613c75f05bd90dcf1e5ff7bbb8699e94418b70b387b7f0bf07394816f6c805 | {
"func_code_index": [
609,
784
]
} | 4,158 |
|||
MassVestingSender | MassVestingSender.sol | 0xcbc66115e9d8655709c3408d0e320410aef1161a | Solidity | TokenTimelock | contract TokenTimelock {
// ERC20 basic token contract being held
ERC20 private _token;
// beneficiary of tokens after they are released
address private _beneficiary;
// timestamp when token release is enabled
uint256 private _releaseTime;
constructor (ERC20 token, address beneficiary, uint256 releaseTime) public {
// solium-disable-next-line security/no-block-members
require(releaseTime > block.timestamp);
_token = token;
_beneficiary = beneficiary;
_releaseTime = releaseTime;
}
/**
* @return the token being held.
*/
function token() public view returns (ERC20) {
return _token;
}
/**
* @return the beneficiary of the tokens.
*/
function beneficiary() public view returns (address) {
return _beneficiary;
}
/**
* @return the time when the tokens are released.
*/
function releaseTime() public view returns (uint256) {
return _releaseTime;
}
/**
* @notice Transfers tokens held by timelock to beneficiary.
*/
function release() public {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= _releaseTime);
uint256 amount = _token.balanceOf(address(this));
require(amount > 0);
_token.transfer(_beneficiary, amount);
}
} | /**
* @title TokenTimelock
* @dev TokenTimelock is a token holder contract that will allow a
* beneficiary to extract the tokens after a given release time
*/ | NatSpecMultiLine | token | function token() public view returns (ERC20) {
return _token;
}
| /**
* @return the token being held.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://2e613c75f05bd90dcf1e5ff7bbb8699e94418b70b387b7f0bf07394816f6c805 | {
"func_code_index": [
572,
642
]
} | 4,159 |
|
MassVestingSender | MassVestingSender.sol | 0xcbc66115e9d8655709c3408d0e320410aef1161a | Solidity | TokenTimelock | contract TokenTimelock {
// ERC20 basic token contract being held
ERC20 private _token;
// beneficiary of tokens after they are released
address private _beneficiary;
// timestamp when token release is enabled
uint256 private _releaseTime;
constructor (ERC20 token, address beneficiary, uint256 releaseTime) public {
// solium-disable-next-line security/no-block-members
require(releaseTime > block.timestamp);
_token = token;
_beneficiary = beneficiary;
_releaseTime = releaseTime;
}
/**
* @return the token being held.
*/
function token() public view returns (ERC20) {
return _token;
}
/**
* @return the beneficiary of the tokens.
*/
function beneficiary() public view returns (address) {
return _beneficiary;
}
/**
* @return the time when the tokens are released.
*/
function releaseTime() public view returns (uint256) {
return _releaseTime;
}
/**
* @notice Transfers tokens held by timelock to beneficiary.
*/
function release() public {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= _releaseTime);
uint256 amount = _token.balanceOf(address(this));
require(amount > 0);
_token.transfer(_beneficiary, amount);
}
} | /**
* @title TokenTimelock
* @dev TokenTimelock is a token holder contract that will allow a
* beneficiary to extract the tokens after a given release time
*/ | NatSpecMultiLine | beneficiary | function beneficiary() public view returns (address) {
return _beneficiary;
}
| /**
* @return the beneficiary of the tokens.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://2e613c75f05bd90dcf1e5ff7bbb8699e94418b70b387b7f0bf07394816f6c805 | {
"func_code_index": [
701,
785
]
} | 4,160 |
|
MassVestingSender | MassVestingSender.sol | 0xcbc66115e9d8655709c3408d0e320410aef1161a | Solidity | TokenTimelock | contract TokenTimelock {
// ERC20 basic token contract being held
ERC20 private _token;
// beneficiary of tokens after they are released
address private _beneficiary;
// timestamp when token release is enabled
uint256 private _releaseTime;
constructor (ERC20 token, address beneficiary, uint256 releaseTime) public {
// solium-disable-next-line security/no-block-members
require(releaseTime > block.timestamp);
_token = token;
_beneficiary = beneficiary;
_releaseTime = releaseTime;
}
/**
* @return the token being held.
*/
function token() public view returns (ERC20) {
return _token;
}
/**
* @return the beneficiary of the tokens.
*/
function beneficiary() public view returns (address) {
return _beneficiary;
}
/**
* @return the time when the tokens are released.
*/
function releaseTime() public view returns (uint256) {
return _releaseTime;
}
/**
* @notice Transfers tokens held by timelock to beneficiary.
*/
function release() public {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= _releaseTime);
uint256 amount = _token.balanceOf(address(this));
require(amount > 0);
_token.transfer(_beneficiary, amount);
}
} | /**
* @title TokenTimelock
* @dev TokenTimelock is a token holder contract that will allow a
* beneficiary to extract the tokens after a given release time
*/ | NatSpecMultiLine | releaseTime | function releaseTime() public view returns (uint256) {
return _releaseTime;
}
| /**
* @return the time when the tokens are released.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://2e613c75f05bd90dcf1e5ff7bbb8699e94418b70b387b7f0bf07394816f6c805 | {
"func_code_index": [
852,
936
]
} | 4,161 |
|
MassVestingSender | MassVestingSender.sol | 0xcbc66115e9d8655709c3408d0e320410aef1161a | Solidity | TokenTimelock | contract TokenTimelock {
// ERC20 basic token contract being held
ERC20 private _token;
// beneficiary of tokens after they are released
address private _beneficiary;
// timestamp when token release is enabled
uint256 private _releaseTime;
constructor (ERC20 token, address beneficiary, uint256 releaseTime) public {
// solium-disable-next-line security/no-block-members
require(releaseTime > block.timestamp);
_token = token;
_beneficiary = beneficiary;
_releaseTime = releaseTime;
}
/**
* @return the token being held.
*/
function token() public view returns (ERC20) {
return _token;
}
/**
* @return the beneficiary of the tokens.
*/
function beneficiary() public view returns (address) {
return _beneficiary;
}
/**
* @return the time when the tokens are released.
*/
function releaseTime() public view returns (uint256) {
return _releaseTime;
}
/**
* @notice Transfers tokens held by timelock to beneficiary.
*/
function release() public {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= _releaseTime);
uint256 amount = _token.balanceOf(address(this));
require(amount > 0);
_token.transfer(_beneficiary, amount);
}
} | /**
* @title TokenTimelock
* @dev TokenTimelock is a token holder contract that will allow a
* beneficiary to extract the tokens after a given release time
*/ | NatSpecMultiLine | release | function release() public {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= _releaseTime);
uint256 amount = _token.balanceOf(address(this));
require(amount > 0);
_token.transfer(_beneficiary, amount);
}
| /**
* @notice Transfers tokens held by timelock to beneficiary.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://2e613c75f05bd90dcf1e5ff7bbb8699e94418b70b387b7f0bf07394816f6c805 | {
"func_code_index": [
1014,
1272
]
} | 4,162 |
|
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | owner | function owner() public view returns (address) {
return _owner;
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
497,
581
]
} | 4,163 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | renounceOwnership | function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
| /**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
1139,
1292
]
} | 4,164 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
1442,
1691
]
} | 4,165 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | MGToken | contract MGToken is ERC20("Magallane", "MG"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
/// @dev A record of each accounts delegate
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "MG::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "MG::delegateBySig: invalid nonce");
require(now <= expiry, "MG::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "MG::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying MGs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_balances[delegator] = _balances[delegator].sub(delegatorBalance);
_balances[delegatee] = _balances[delegatee].add(delegatorBalance);
emit Transfer(delegator, delegatee, delegatorBalance);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "MG::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | // MGToken with Governance. | LineComment | mint | function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
| /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef). | NatSpecSingleLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
155,
322
]
} | 4,166 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | MGToken | contract MGToken is ERC20("Magallane", "MG"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
/// @dev A record of each accounts delegate
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "MG::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "MG::delegateBySig: invalid nonce");
require(now <= expiry, "MG::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "MG::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying MGs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_balances[delegator] = _balances[delegator].sub(delegatorBalance);
_balances[delegatee] = _balances[delegatee].add(delegatorBalance);
emit Transfer(delegator, delegatee, delegatorBalance);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "MG::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | // MGToken with Governance. | LineComment | delegates | function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
| /**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
2315,
2469
]
} | 4,167 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | MGToken | contract MGToken is ERC20("Magallane", "MG"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
/// @dev A record of each accounts delegate
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "MG::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "MG::delegateBySig: invalid nonce");
require(now <= expiry, "MG::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "MG::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying MGs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_balances[delegator] = _balances[delegator].sub(delegatorBalance);
_balances[delegatee] = _balances[delegatee].add(delegatorBalance);
emit Transfer(delegator, delegatee, delegatorBalance);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "MG::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | // MGToken with Governance. | LineComment | delegate | function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
| /**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
2608,
2717
]
} | 4,168 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | MGToken | contract MGToken is ERC20("Magallane", "MG"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
/// @dev A record of each accounts delegate
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "MG::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "MG::delegateBySig: invalid nonce");
require(now <= expiry, "MG::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "MG::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying MGs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_balances[delegator] = _balances[delegator].sub(delegatorBalance);
_balances[delegatee] = _balances[delegatee].add(delegatorBalance);
emit Transfer(delegator, delegatee, delegatorBalance);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "MG::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | // MGToken with Governance. | LineComment | delegateBySig | function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "MG::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "MG::delegateBySig: invalid nonce");
require(now <= expiry, "MG::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
| /**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
3146,
4323
]
} | 4,169 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | MGToken | contract MGToken is ERC20("Magallane", "MG"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
/// @dev A record of each accounts delegate
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "MG::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "MG::delegateBySig: invalid nonce");
require(now <= expiry, "MG::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "MG::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying MGs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_balances[delegator] = _balances[delegator].sub(delegatorBalance);
_balances[delegatee] = _balances[delegatee].add(delegatorBalance);
emit Transfer(delegator, delegatee, delegatorBalance);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "MG::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | // MGToken with Governance. | LineComment | getCurrentVotes | function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
| /**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
4519,
4779
]
} | 4,170 |
||
MGToken | @openzeppelin/contracts/access/Ownable.sol | 0xedc518f5fba01d4a4e5d51a1555a718bec74d683 | Solidity | MGToken | contract MGToken is ERC20("Magallane", "MG"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
_moveDelegates(address(0), _delegates[_to], _amount);
}
// Copied and modified from YAM code:
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol
// https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol
// Which is copied and modified from COMPOUND:
// https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol
/// @dev A record of each accounts delegate
mapping (address => address) internal _delegates;
/// @notice A checkpoint for marking number of votes from a given block
struct Checkpoint {
uint32 fromBlock;
uint256 votes;
}
/// @notice A record of votes checkpoints for each account, by index
mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
/// @notice The number of checkpoints for each account
mapping (address => uint32) public numCheckpoints;
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
/// @notice The EIP-712 typehash for the delegation struct used by the contract
bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/// @notice A record of states for signing / validating signatures
mapping (address => uint) public nonces;
/// @notice An event thats emitted when an account changes its delegate
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
/// @notice An event thats emitted when a delegate account's vote balance changes
event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegator The address to get delegatee for
*/
function delegates(address delegator)
external
view
returns (address)
{
return _delegates[delegator];
}
/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
*/
function delegate(address delegatee) external {
return _delegate(msg.sender, delegatee);
}
/**
* @notice Delegates votes from signatory to `delegatee`
* @param delegatee The address to delegate votes to
* @param nonce The contract state required to match the signature
* @param expiry The time at which to expire the signature
* @param v The recovery byte of the signature
* @param r Half of the ECDSA signature pair
* @param s Half of the ECDSA signature pair
*/
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
)
external
{
bytes32 domainSeparator = keccak256(
abi.encode(
DOMAIN_TYPEHASH,
keccak256(bytes(name())),
getChainId(),
address(this)
)
);
bytes32 structHash = keccak256(
abi.encode(
DELEGATION_TYPEHASH,
delegatee,
nonce,
expiry
)
);
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
domainSeparator,
structHash
)
);
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), "MG::delegateBySig: invalid signature");
require(nonce == nonces[signatory]++, "MG::delegateBySig: invalid nonce");
require(now <= expiry, "MG::delegateBySig: signature expired");
return _delegate(signatory, delegatee);
}
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account)
external
view
returns (uint256)
{
uint32 nCheckpoints = numCheckpoints[account];
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
}
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "MG::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
function _delegate(address delegator, address delegatee)
internal
{
address currentDelegate = _delegates[delegator];
uint256 delegatorBalance = balanceOf(delegator); // balance of underlying MGs (not scaled);
_delegates[delegator] = delegatee;
emit DelegateChanged(delegator, currentDelegate, delegatee);
_balances[delegator] = _balances[delegator].sub(delegatorBalance);
_balances[delegatee] = _balances[delegatee].add(delegatorBalance);
emit Transfer(delegator, delegatee, delegatorBalance);
_moveDelegates(currentDelegate, delegatee, delegatorBalance);
}
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {
if (srcRep != dstRep && amount > 0) {
if (srcRep != address(0)) {
// decrease old representative
uint32 srcRepNum = numCheckpoints[srcRep];
uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
uint256 srcRepNew = srcRepOld.sub(amount);
_writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
}
if (dstRep != address(0)) {
// increase new representative
uint32 dstRepNum = numCheckpoints[dstRep];
uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
uint256 dstRepNew = dstRepOld.add(amount);
_writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
}
}
}
function _writeCheckpoint(
address delegatee,
uint32 nCheckpoints,
uint256 oldVotes,
uint256 newVotes
)
internal
{
uint32 blockNumber = safe32(block.number, "MG::_writeCheckpoint: block number exceeds 32 bits");
if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
} else {
checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
numCheckpoints[delegatee] = nCheckpoints + 1;
}
emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
}
function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {
require(n < 2**32, errorMessage);
return uint32(n);
}
function getChainId() internal pure returns (uint) {
uint256 chainId;
assembly { chainId := chainid() }
return chainId;
}
} | // MGToken with Governance. | LineComment | getPriorVotes | function getPriorVotes(address account, uint blockNumber)
external
view
returns (uint256)
{
require(blockNumber < block.number, "MG::getPriorVotes: not yet determined");
uint32 nCheckpoints = numCheckpoints[account];
if (nCheckpoints == 0) {
return 0;
}
// First check most recent balance
if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) {
return checkpoints[account][nCheckpoints - 1].votes;
}
// Next check implicit zero balance
if (checkpoints[account][0].fromBlock > blockNumber) {
return 0;
}
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow
Checkpoint memory cp = checkpoints[account][center];
if (cp.fromBlock == blockNumber) {
return cp.votes;
} else if (cp.fromBlock < blockNumber) {
lower = center;
} else {
upper = center - 1;
}
}
return checkpoints[account][lower].votes;
}
| /**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
5205,
6461
]
} | 4,171 |
||
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | Context | abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
/**
* @dev Function _msgData() defines messaging standards of ERC20 tokens as defined in the EIP.
*/
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
} | /**
* @dev Contract Context of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | _msgData | function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
| /**
* @dev Function _msgData() defines messaging standards of ERC20 tokens as defined in the EIP.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
263,
501
]
} | 4,172 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
94,
154
]
} | 4,173 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
237,
310
]
} | 4,174 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
534,
616
]
} | 4,175 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) external view returns (uint256);
| /**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
895,
983
]
} | 4,176 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
1647,
1726
]
} | 4,177 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
2039,
2141
]
} | 4,178 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
259,
445
]
} | 4,179 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
723,
864
]
} | 4,180 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
1162,
1359
]
} | 4,181 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
1613,
2089
]
} | 4,182 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
2560,
2697
]
} | 4,183 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
3188,
3471
]
} | 4,184 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
3931,
4066
]
} | 4,185 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
4546,
4717
]
} | 4,186 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | 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 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) {
// 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.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
606,
1230
]
} | 4,187 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | 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 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.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
2160,
2562
]
} | 4,188 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | 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 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.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
3318,
3496
]
} | 4,189 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | 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 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, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
3721,
3922
]
} | 4,190 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | 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 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 | functionCallWithValue | 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-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._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
4292,
4523
]
} | 4,191 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | 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 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 | functionCallWithValue | 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);
}
| /**
* @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._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
4774,
5095
]
} | 4,192 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | owner | function owner() public view returns (address) {
return _owner;
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
497,
581
]
} | 4,193 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | renounceOwnership | function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
| /**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
1139,
1292
]
} | 4,194 |
RefractFin | RefractFin.sol | 0x1de8c93d2a4187b7ac51676a0c8fe121a06684b0 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://a226205be2a9ac5c949f9067547aae08af696fffe58268ad67fd468ba5192af3 | {
"func_code_index": [
1442,
1691
]
} | 4,195 |
HonoraryBears | contracts/nft_on_chain_whitelist.sol | 0x4f0915a980fd5c9033d4ba5b297d2a5f149231f1 | Solidity | HonoraryBears | contract HonoraryBears is ERC721, Ownable {
using Strings for uint256;
uint256 public constant MAX_TOKENS = 250;
uint256 private constant TOKENS_RESERVED = 100;
uint256 public price = 300000000000000000;
uint256 public constant MAX_MINT_PER_TX = 2;
bool public isSaleActive;
bool public isAllowListActive = false;
uint256 public totalSupply;
mapping(address => uint256) private mintedPerWallet;
mapping(address => bool) private _allowList;
string public baseUri;
string public baseExtension = ".json";
constructor() ERC721("Honorary Bears", "HONOR") {
baseUri = "ipfs://QmcZikhPN3mATtZphDbLMDzq9Zen5e4ivrUUQnLsyzUzYy/";
for (uint256 i = 1; i <= TOKENS_RESERVED; ++i) {
_safeMint(msg.sender, i);
}
totalSupply = TOKENS_RESERVED;
}
// PUBLIC FUNCTIONS
function whitelistMint(uint256 _numTokens) external payable {
require(isAllowListActive, "Whitelist is not active.");
require(_allowList[msg.sender] == true, "Not whitelisted.");
require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
uint256 curTotalSupply = totalSupply;
require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
require(_numTokens * price <= msg.value, "Incorrect ETH value.");
for (uint256 i = 1; i <= _numTokens; ++i) {
_safeMint(msg.sender, curTotalSupply + i);
}
mintedPerWallet[msg.sender] += _numTokens;
totalSupply += _numTokens;
}
function publicMint(uint256 _numTokens) external payable {
require(isSaleActive, "Sale is not active.");
require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
uint256 curTotalSupply = totalSupply;
require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
require(_numTokens * price <= msg.value, "Incorrect ETH value.");
for (uint256 i = 1; i <= _numTokens; ++i) {
_safeMint(msg.sender, curTotalSupply + i);
}
mintedPerWallet[msg.sender] += _numTokens;
totalSupply += _numTokens;
}
// OWNER ONLY FUNCTIONS
function flipSaleState() external onlyOwner {
isSaleActive = !isSaleActive;
}
function setIsAllowListActive() external onlyOwner {
isAllowListActive = !isAllowListActive;
}
function setAllowList(address[] calldata addresses, bool isAllowed) external onlyOwner {
for (uint256 i = 0; i < addresses.length; i++) {
_allowList[addresses[i]] = isAllowed;
}
}
function setBaseURI(string memory _baseUri) external onlyOwner {
baseUri = _baseUri;
}
function setPrice(uint256 _price) external onlyOwner {
price = _price;
}
function withdrawAll() external payable onlyOwner {
uint256 balance = address(this).balance;
uint256 balanceOne = balance * 100 / 100;
(bool transferOne, ) = payable(0xA477c13E0f86170F855d06EFDE32858ad9f18941).call{value: balanceOne}("");
require(transferOne, "Transfer failed.");
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
// INTERNAL FUNCTIONS
function _baseURI() internal view virtual override returns (string memory) {
return baseUri;
}
} | // @title: BallerBears.sol | LineComment | whitelistMint | function whitelistMint(uint256 _numTokens) external payable {
require(isAllowListActive, "Whitelist is not active.");
require(_allowList[msg.sender] == true, "Not whitelisted.");
require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
uint256 curTotalSupply = totalSupply;
require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
require(_numTokens * price <= msg.value, "Incorrect ETH value.");
for (uint256 i = 1; i <= _numTokens; ++i) {
_safeMint(msg.sender, curTotalSupply + i);
}
mintedPerWallet[msg.sender] += _numTokens;
totalSupply += _numTokens;
}
| // PUBLIC FUNCTIONS | LineComment | v0.8.9+commit.e5eed63a | MIT | ipfs://24f9fb75db078997a30a296c8be7ce934429051f801723b15f09232b344d7e25 | {
"func_code_index": [
890,
1719
]
} | 4,196 |
HonoraryBears | contracts/nft_on_chain_whitelist.sol | 0x4f0915a980fd5c9033d4ba5b297d2a5f149231f1 | Solidity | HonoraryBears | contract HonoraryBears is ERC721, Ownable {
using Strings for uint256;
uint256 public constant MAX_TOKENS = 250;
uint256 private constant TOKENS_RESERVED = 100;
uint256 public price = 300000000000000000;
uint256 public constant MAX_MINT_PER_TX = 2;
bool public isSaleActive;
bool public isAllowListActive = false;
uint256 public totalSupply;
mapping(address => uint256) private mintedPerWallet;
mapping(address => bool) private _allowList;
string public baseUri;
string public baseExtension = ".json";
constructor() ERC721("Honorary Bears", "HONOR") {
baseUri = "ipfs://QmcZikhPN3mATtZphDbLMDzq9Zen5e4ivrUUQnLsyzUzYy/";
for (uint256 i = 1; i <= TOKENS_RESERVED; ++i) {
_safeMint(msg.sender, i);
}
totalSupply = TOKENS_RESERVED;
}
// PUBLIC FUNCTIONS
function whitelistMint(uint256 _numTokens) external payable {
require(isAllowListActive, "Whitelist is not active.");
require(_allowList[msg.sender] == true, "Not whitelisted.");
require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
uint256 curTotalSupply = totalSupply;
require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
require(_numTokens * price <= msg.value, "Incorrect ETH value.");
for (uint256 i = 1; i <= _numTokens; ++i) {
_safeMint(msg.sender, curTotalSupply + i);
}
mintedPerWallet[msg.sender] += _numTokens;
totalSupply += _numTokens;
}
function publicMint(uint256 _numTokens) external payable {
require(isSaleActive, "Sale is not active.");
require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
uint256 curTotalSupply = totalSupply;
require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
require(_numTokens * price <= msg.value, "Incorrect ETH value.");
for (uint256 i = 1; i <= _numTokens; ++i) {
_safeMint(msg.sender, curTotalSupply + i);
}
mintedPerWallet[msg.sender] += _numTokens;
totalSupply += _numTokens;
}
// OWNER ONLY FUNCTIONS
function flipSaleState() external onlyOwner {
isSaleActive = !isSaleActive;
}
function setIsAllowListActive() external onlyOwner {
isAllowListActive = !isAllowListActive;
}
function setAllowList(address[] calldata addresses, bool isAllowed) external onlyOwner {
for (uint256 i = 0; i < addresses.length; i++) {
_allowList[addresses[i]] = isAllowed;
}
}
function setBaseURI(string memory _baseUri) external onlyOwner {
baseUri = _baseUri;
}
function setPrice(uint256 _price) external onlyOwner {
price = _price;
}
function withdrawAll() external payable onlyOwner {
uint256 balance = address(this).balance;
uint256 balanceOne = balance * 100 / 100;
(bool transferOne, ) = payable(0xA477c13E0f86170F855d06EFDE32858ad9f18941).call{value: balanceOne}("");
require(transferOne, "Transfer failed.");
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
// INTERNAL FUNCTIONS
function _baseURI() internal view virtual override returns (string memory) {
return baseUri;
}
} | // @title: BallerBears.sol | LineComment | flipSaleState | function flipSaleState() external onlyOwner {
isSaleActive = !isSaleActive;
}
| // OWNER ONLY FUNCTIONS | LineComment | v0.8.9+commit.e5eed63a | MIT | ipfs://24f9fb75db078997a30a296c8be7ce934429051f801723b15f09232b344d7e25 | {
"func_code_index": [
2501,
2597
]
} | 4,197 |
HonoraryBears | contracts/nft_on_chain_whitelist.sol | 0x4f0915a980fd5c9033d4ba5b297d2a5f149231f1 | Solidity | HonoraryBears | contract HonoraryBears is ERC721, Ownable {
using Strings for uint256;
uint256 public constant MAX_TOKENS = 250;
uint256 private constant TOKENS_RESERVED = 100;
uint256 public price = 300000000000000000;
uint256 public constant MAX_MINT_PER_TX = 2;
bool public isSaleActive;
bool public isAllowListActive = false;
uint256 public totalSupply;
mapping(address => uint256) private mintedPerWallet;
mapping(address => bool) private _allowList;
string public baseUri;
string public baseExtension = ".json";
constructor() ERC721("Honorary Bears", "HONOR") {
baseUri = "ipfs://QmcZikhPN3mATtZphDbLMDzq9Zen5e4ivrUUQnLsyzUzYy/";
for (uint256 i = 1; i <= TOKENS_RESERVED; ++i) {
_safeMint(msg.sender, i);
}
totalSupply = TOKENS_RESERVED;
}
// PUBLIC FUNCTIONS
function whitelistMint(uint256 _numTokens) external payable {
require(isAllowListActive, "Whitelist is not active.");
require(_allowList[msg.sender] == true, "Not whitelisted.");
require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
uint256 curTotalSupply = totalSupply;
require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
require(_numTokens * price <= msg.value, "Incorrect ETH value.");
for (uint256 i = 1; i <= _numTokens; ++i) {
_safeMint(msg.sender, curTotalSupply + i);
}
mintedPerWallet[msg.sender] += _numTokens;
totalSupply += _numTokens;
}
function publicMint(uint256 _numTokens) external payable {
require(isSaleActive, "Sale is not active.");
require(_numTokens <= MAX_MINT_PER_TX, "You can only mint a maximum of 2 per transaction.");
require(mintedPerWallet[msg.sender] + _numTokens <= 2, "You can only mint 2 per wallet.");
uint256 curTotalSupply = totalSupply;
require(curTotalSupply + _numTokens <= MAX_TOKENS, "Exceeds `MAX_TOKENS`.");
require(_numTokens * price <= msg.value, "Incorrect ETH value.");
for (uint256 i = 1; i <= _numTokens; ++i) {
_safeMint(msg.sender, curTotalSupply + i);
}
mintedPerWallet[msg.sender] += _numTokens;
totalSupply += _numTokens;
}
// OWNER ONLY FUNCTIONS
function flipSaleState() external onlyOwner {
isSaleActive = !isSaleActive;
}
function setIsAllowListActive() external onlyOwner {
isAllowListActive = !isAllowListActive;
}
function setAllowList(address[] calldata addresses, bool isAllowed) external onlyOwner {
for (uint256 i = 0; i < addresses.length; i++) {
_allowList[addresses[i]] = isAllowed;
}
}
function setBaseURI(string memory _baseUri) external onlyOwner {
baseUri = _baseUri;
}
function setPrice(uint256 _price) external onlyOwner {
price = _price;
}
function withdrawAll() external payable onlyOwner {
uint256 balance = address(this).balance;
uint256 balanceOne = balance * 100 / 100;
(bool transferOne, ) = payable(0xA477c13E0f86170F855d06EFDE32858ad9f18941).call{value: balanceOne}("");
require(transferOne, "Transfer failed.");
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
// INTERNAL FUNCTIONS
function _baseURI() internal view virtual override returns (string memory) {
return baseUri;
}
} | // @title: BallerBears.sol | LineComment | _baseURI | function _baseURI() internal view virtual override returns (string memory) {
return baseUri;
}
| // INTERNAL FUNCTIONS | LineComment | v0.8.9+commit.e5eed63a | MIT | ipfs://24f9fb75db078997a30a296c8be7ce934429051f801723b15f09232b344d7e25 | {
"func_code_index": [
3910,
4023
]
} | 4,198 |
ELTPLUS | ELTPLUS.sol | 0xe883bd2f6b311b96342ecd8046952b614f717ced | Solidity | ELTPLUS | contract ELTPLUS is ERC20 {
using SafeMath for uint256;
string internal _name;
string internal _symbol;
uint8 internal _decimals;
uint256 internal _totalSupply;
address internal _admin;
mapping (address => uint256) internal balances;
mapping (address => mapping (address => uint256)) internal allowed;
constructor() public {
_admin = msg.sender;
_symbol = "ELT";
_name = "ELTPLUS";
_decimals = 18;
_totalSupply = 100000000000* 10**uint(_decimals);
balances[msg.sender]=_totalSupply;
}
modifier ownership() {
require(msg.sender == _admin);
_;
}
function name() public view returns (string memory)
{
return _name;
}
function symbol() public view returns (string memory)
{
return _symbol;
}
function decimals() public view returns (uint8)
{
return _decimals;
}
function totalSupply() public view returns (uint256)
{
return _totalSupply;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = (balances[_to]).add( _value);
emit ERC20.Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
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);
emit ERC20.Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit ERC20.Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
function mint(uint256 _amount) public ownership returns (bool) {
_totalSupply = (_totalSupply).add(_amount);
balances[_admin] +=_amount;
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
_totalSupply -= _value; // Updates totalSupply
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*/
function burnFrom(address _from, uint256 _value) 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
allowed[_from][msg.sender] -= _value; // Subtract from the sender's allowance
_totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
//Admin can transfer his ownership to new address
function transferownership(address _newaddress) public returns(bool){
require(msg.sender==_admin);
_admin=_newaddress;
return true;
}
} | burnFrom | function burnFrom(address _from, uint256 _value) 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
allowed[_from][msg.sender] -= _value; // Subtract from the sender's allowance
_totalSupply -= _value; // Update totalSupply
emit Burn(_from, _value);
return true;
}
| /**
* Destroy tokens from other account
*/ | NatSpecMultiLine | v0.5.11+commit.c082d0b4 | None | bzzr://6db144f5bbe040fde6c58953976ce0348fd390ca4a8b4d42ba3503d55becb435 | {
"func_code_index": [
3041,
3652
]
} | 4,199 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.