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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
TickerRegistry | TickerRegistry.sol | 0xc31714e6759a1ee26db1d06af1ed276340cd4233 | Solidity | TickerRegistry | contract TickerRegistry is ITickerRegistry, Util, Pausable, RegistryUpdater, ReclaimTokens {
using SafeMath for uint256;
// constant variable to check the validity to use the symbol
// For now it's value is 15 days;
uint256 public expiryLimit = 15 * 1 days;
// Details of the symbol that get registered with the polymath platform
struct SymbolDetails {
address owner;
uint256 timestamp;
string tokenName;
bytes32 swarmHash;
bool status;
}
// Storage of symbols correspond to their details.
mapping(string => SymbolDetails) registeredSymbols;
// Emit after the symbol registration
event LogRegisterTicker(address indexed _owner, string _symbol, string _name, bytes32 _swarmHash, uint256 indexed _timestamp);
// Emit when the token symbol expiry get changed
event LogChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
// Registration fee in POLY base 18 decimals
uint256 public registrationFee;
// Emit when changePolyRegisterationFee is called
event LogChangePolyRegisterationFee(uint256 _oldFee, uint256 _newFee);
constructor (address _polymathRegistry, uint256 _registrationFee) public
RegistryUpdater(_polymathRegistry)
{
registrationFee = _registrationFee;
}
/**
* @notice Register the token symbol for its particular owner
* @notice Once the token symbol is registered to its owner then no other issuer can claim
* @notice its ownership. If the symbol expires and its issuer hasn't used it, then someone else can take it.
* @param _symbol token symbol
* @param _tokenName Name of the token
* @param _owner Address of the owner of the token
* @param _swarmHash Off-chain details of the issuer and token
*/
function registerTicker(address _owner, string _symbol, string _tokenName, bytes32 _swarmHash) public whenNotPaused {
require(_owner != address(0), "Owner should not be 0x");
require(bytes(_symbol).length > 0 && bytes(_symbol).length <= 10, "Ticker length should always between 0 & 10");
if(registrationFee > 0)
require(ERC20(polyToken).transferFrom(msg.sender, this, registrationFee), "Failed transferFrom because of sufficent Allowance is not provided");
string memory symbol = upper(_symbol);
require(expiryCheck(symbol), "Ticker is already reserved");
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, false);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
}
/**
* @notice Change the expiry time for the token symbol
* @param _newExpiry new time period for token symbol expiry
*/
function changeExpiryLimit(uint256 _newExpiry) public onlyOwner {
require(_newExpiry >= 1 days, "Expiry should greater than or equal to 1 day");
uint256 _oldExpiry = expiryLimit;
expiryLimit = _newExpiry;
emit LogChangeExpiryLimit(_oldExpiry, _newExpiry);
}
/**
* @notice Check the validity of the symbol
* @param _symbol token symbol
* @param _owner address of the owner
* @param _tokenName Name of the token
* @return bool
*/
function checkValidity(string _symbol, address _owner, string _tokenName) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
require(registeredSymbols[symbol].status != true, "Symbol status should not equal to true");
require(registeredSymbols[symbol].owner == _owner, "Owner of the symbol should matched with the requested issuer address");
require(registeredSymbols[symbol].timestamp.add(expiryLimit) >= now, "Ticker should not be expired");
registeredSymbols[symbol].tokenName = _tokenName;
registeredSymbols[symbol].status = true;
return true;
}
/**
* @notice Check the symbol is reserved or not
* @param _symbol Symbol of the token
* @param _owner Owner of the token
* @param _tokenName Name of the token
* @param _swarmHash off-chain hash
* @return bool
*/
function isReserved(string _symbol, address _owner, string _tokenName, bytes32 _swarmHash) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
if (registeredSymbols[symbol].owner == _owner && !expiryCheck(_symbol)) {
registeredSymbols[symbol].status = true;
return false;
}
else if (registeredSymbols[symbol].owner == address(0) || expiryCheck(symbol)) {
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, true);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
return false;
} else
return true;
}
/**
* @notice Returns the owner and timestamp for a given symbol
* @param _symbol symbol
* @return address
* @return uint256
* @return string
* @return bytes32
* @return bool
*/
function getDetails(string _symbol) public view returns (address, uint256, string, bytes32, bool) {
string memory symbol = upper(_symbol);
if (registeredSymbols[symbol].status == true||registeredSymbols[symbol].timestamp.add(expiryLimit) > now) {
return
(
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].swarmHash,
registeredSymbols[symbol].status
);
}else
return (address(0), uint256(0), "", bytes32(0), false);
}
/**
* @notice To re-initialize the token symbol details if symbol validity expires
* @param _symbol token symbol
* @return bool
*/
function expiryCheck(string _symbol) internal returns(bool) {
if (registeredSymbols[_symbol].owner != address(0)) {
if (now > registeredSymbols[_symbol].timestamp.add(expiryLimit) && registeredSymbols[_symbol].status != true) {
registeredSymbols[_symbol] = SymbolDetails(address(0), uint256(0), "", bytes32(0), false);
return true;
}else
return false;
}
return true;
}
/**
* @notice set the ticker registration fee in POLY tokens
* @param _registrationFee registration fee in POLY tokens (base 18 decimals)
*/
function changePolyRegisterationFee(uint256 _registrationFee) public onlyOwner {
require(registrationFee != _registrationFee);
emit LogChangePolyRegisterationFee(registrationFee, _registrationFee);
registrationFee = _registrationFee;
}
/**
* @notice pause registration function
*/
function unpause() public onlyOwner {
_unpause();
}
/**
* @notice unpause registration function
*/
function pause() public onlyOwner {
_pause();
}
} | /**
* @title Registry contract for issuers to reserve their security token symbols
* @notice Allows issuers to reserve their token symbols ahead of actually generating their security token.
* @dev SecurityTokenRegistry would reference this contract and ensure that a token symbol exists here and only its owner can deploy the token with that symbol.
*/ | NatSpecMultiLine | isReserved | function isReserved(string _symbol, address _owner, string _tokenName, bytes32 _swarmHash) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
if (registeredSymbols[symbol].owner == _owner && !expiryCheck(_symbol)) {
registeredSymbols[symbol].status = true;
return false;
}
else if (registeredSymbols[symbol].owner == address(0) || expiryCheck(symbol)) {
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, true);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
return false;
} else
return true;
}
| /**
* @notice Check the symbol is reserved or not
* @param _symbol Symbol of the token
* @param _owner Owner of the token
* @param _tokenName Name of the token
* @param _swarmHash off-chain hash
* @return bool
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1c3fd67e0e5dae16f4d5818e4def156aa71b9a6925640af36a76c616a54e724c | {
"func_code_index": [
4314,
5115
]
} | 5,800 |
|
TickerRegistry | TickerRegistry.sol | 0xc31714e6759a1ee26db1d06af1ed276340cd4233 | Solidity | TickerRegistry | contract TickerRegistry is ITickerRegistry, Util, Pausable, RegistryUpdater, ReclaimTokens {
using SafeMath for uint256;
// constant variable to check the validity to use the symbol
// For now it's value is 15 days;
uint256 public expiryLimit = 15 * 1 days;
// Details of the symbol that get registered with the polymath platform
struct SymbolDetails {
address owner;
uint256 timestamp;
string tokenName;
bytes32 swarmHash;
bool status;
}
// Storage of symbols correspond to their details.
mapping(string => SymbolDetails) registeredSymbols;
// Emit after the symbol registration
event LogRegisterTicker(address indexed _owner, string _symbol, string _name, bytes32 _swarmHash, uint256 indexed _timestamp);
// Emit when the token symbol expiry get changed
event LogChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
// Registration fee in POLY base 18 decimals
uint256 public registrationFee;
// Emit when changePolyRegisterationFee is called
event LogChangePolyRegisterationFee(uint256 _oldFee, uint256 _newFee);
constructor (address _polymathRegistry, uint256 _registrationFee) public
RegistryUpdater(_polymathRegistry)
{
registrationFee = _registrationFee;
}
/**
* @notice Register the token symbol for its particular owner
* @notice Once the token symbol is registered to its owner then no other issuer can claim
* @notice its ownership. If the symbol expires and its issuer hasn't used it, then someone else can take it.
* @param _symbol token symbol
* @param _tokenName Name of the token
* @param _owner Address of the owner of the token
* @param _swarmHash Off-chain details of the issuer and token
*/
function registerTicker(address _owner, string _symbol, string _tokenName, bytes32 _swarmHash) public whenNotPaused {
require(_owner != address(0), "Owner should not be 0x");
require(bytes(_symbol).length > 0 && bytes(_symbol).length <= 10, "Ticker length should always between 0 & 10");
if(registrationFee > 0)
require(ERC20(polyToken).transferFrom(msg.sender, this, registrationFee), "Failed transferFrom because of sufficent Allowance is not provided");
string memory symbol = upper(_symbol);
require(expiryCheck(symbol), "Ticker is already reserved");
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, false);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
}
/**
* @notice Change the expiry time for the token symbol
* @param _newExpiry new time period for token symbol expiry
*/
function changeExpiryLimit(uint256 _newExpiry) public onlyOwner {
require(_newExpiry >= 1 days, "Expiry should greater than or equal to 1 day");
uint256 _oldExpiry = expiryLimit;
expiryLimit = _newExpiry;
emit LogChangeExpiryLimit(_oldExpiry, _newExpiry);
}
/**
* @notice Check the validity of the symbol
* @param _symbol token symbol
* @param _owner address of the owner
* @param _tokenName Name of the token
* @return bool
*/
function checkValidity(string _symbol, address _owner, string _tokenName) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
require(registeredSymbols[symbol].status != true, "Symbol status should not equal to true");
require(registeredSymbols[symbol].owner == _owner, "Owner of the symbol should matched with the requested issuer address");
require(registeredSymbols[symbol].timestamp.add(expiryLimit) >= now, "Ticker should not be expired");
registeredSymbols[symbol].tokenName = _tokenName;
registeredSymbols[symbol].status = true;
return true;
}
/**
* @notice Check the symbol is reserved or not
* @param _symbol Symbol of the token
* @param _owner Owner of the token
* @param _tokenName Name of the token
* @param _swarmHash off-chain hash
* @return bool
*/
function isReserved(string _symbol, address _owner, string _tokenName, bytes32 _swarmHash) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
if (registeredSymbols[symbol].owner == _owner && !expiryCheck(_symbol)) {
registeredSymbols[symbol].status = true;
return false;
}
else if (registeredSymbols[symbol].owner == address(0) || expiryCheck(symbol)) {
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, true);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
return false;
} else
return true;
}
/**
* @notice Returns the owner and timestamp for a given symbol
* @param _symbol symbol
* @return address
* @return uint256
* @return string
* @return bytes32
* @return bool
*/
function getDetails(string _symbol) public view returns (address, uint256, string, bytes32, bool) {
string memory symbol = upper(_symbol);
if (registeredSymbols[symbol].status == true||registeredSymbols[symbol].timestamp.add(expiryLimit) > now) {
return
(
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].swarmHash,
registeredSymbols[symbol].status
);
}else
return (address(0), uint256(0), "", bytes32(0), false);
}
/**
* @notice To re-initialize the token symbol details if symbol validity expires
* @param _symbol token symbol
* @return bool
*/
function expiryCheck(string _symbol) internal returns(bool) {
if (registeredSymbols[_symbol].owner != address(0)) {
if (now > registeredSymbols[_symbol].timestamp.add(expiryLimit) && registeredSymbols[_symbol].status != true) {
registeredSymbols[_symbol] = SymbolDetails(address(0), uint256(0), "", bytes32(0), false);
return true;
}else
return false;
}
return true;
}
/**
* @notice set the ticker registration fee in POLY tokens
* @param _registrationFee registration fee in POLY tokens (base 18 decimals)
*/
function changePolyRegisterationFee(uint256 _registrationFee) public onlyOwner {
require(registrationFee != _registrationFee);
emit LogChangePolyRegisterationFee(registrationFee, _registrationFee);
registrationFee = _registrationFee;
}
/**
* @notice pause registration function
*/
function unpause() public onlyOwner {
_unpause();
}
/**
* @notice unpause registration function
*/
function pause() public onlyOwner {
_pause();
}
} | /**
* @title Registry contract for issuers to reserve their security token symbols
* @notice Allows issuers to reserve their token symbols ahead of actually generating their security token.
* @dev SecurityTokenRegistry would reference this contract and ensure that a token symbol exists here and only its owner can deploy the token with that symbol.
*/ | NatSpecMultiLine | getDetails | function getDetails(string _symbol) public view returns (address, uint256, string, bytes32, bool) {
string memory symbol = upper(_symbol);
if (registeredSymbols[symbol].status == true||registeredSymbols[symbol].timestamp.add(expiryLimit) > now) {
return
(
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].swarmHash,
registeredSymbols[symbol].status
);
}else
return (address(0), uint256(0), "", bytes32(0), false);
}
| /**
* @notice Returns the owner and timestamp for a given symbol
* @param _symbol symbol
* @return address
* @return uint256
* @return string
* @return bytes32
* @return bool
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1c3fd67e0e5dae16f4d5818e4def156aa71b9a6925640af36a76c616a54e724c | {
"func_code_index": [
5349,
6022
]
} | 5,801 |
|
TickerRegistry | TickerRegistry.sol | 0xc31714e6759a1ee26db1d06af1ed276340cd4233 | Solidity | TickerRegistry | contract TickerRegistry is ITickerRegistry, Util, Pausable, RegistryUpdater, ReclaimTokens {
using SafeMath for uint256;
// constant variable to check the validity to use the symbol
// For now it's value is 15 days;
uint256 public expiryLimit = 15 * 1 days;
// Details of the symbol that get registered with the polymath platform
struct SymbolDetails {
address owner;
uint256 timestamp;
string tokenName;
bytes32 swarmHash;
bool status;
}
// Storage of symbols correspond to their details.
mapping(string => SymbolDetails) registeredSymbols;
// Emit after the symbol registration
event LogRegisterTicker(address indexed _owner, string _symbol, string _name, bytes32 _swarmHash, uint256 indexed _timestamp);
// Emit when the token symbol expiry get changed
event LogChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
// Registration fee in POLY base 18 decimals
uint256 public registrationFee;
// Emit when changePolyRegisterationFee is called
event LogChangePolyRegisterationFee(uint256 _oldFee, uint256 _newFee);
constructor (address _polymathRegistry, uint256 _registrationFee) public
RegistryUpdater(_polymathRegistry)
{
registrationFee = _registrationFee;
}
/**
* @notice Register the token symbol for its particular owner
* @notice Once the token symbol is registered to its owner then no other issuer can claim
* @notice its ownership. If the symbol expires and its issuer hasn't used it, then someone else can take it.
* @param _symbol token symbol
* @param _tokenName Name of the token
* @param _owner Address of the owner of the token
* @param _swarmHash Off-chain details of the issuer and token
*/
function registerTicker(address _owner, string _symbol, string _tokenName, bytes32 _swarmHash) public whenNotPaused {
require(_owner != address(0), "Owner should not be 0x");
require(bytes(_symbol).length > 0 && bytes(_symbol).length <= 10, "Ticker length should always between 0 & 10");
if(registrationFee > 0)
require(ERC20(polyToken).transferFrom(msg.sender, this, registrationFee), "Failed transferFrom because of sufficent Allowance is not provided");
string memory symbol = upper(_symbol);
require(expiryCheck(symbol), "Ticker is already reserved");
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, false);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
}
/**
* @notice Change the expiry time for the token symbol
* @param _newExpiry new time period for token symbol expiry
*/
function changeExpiryLimit(uint256 _newExpiry) public onlyOwner {
require(_newExpiry >= 1 days, "Expiry should greater than or equal to 1 day");
uint256 _oldExpiry = expiryLimit;
expiryLimit = _newExpiry;
emit LogChangeExpiryLimit(_oldExpiry, _newExpiry);
}
/**
* @notice Check the validity of the symbol
* @param _symbol token symbol
* @param _owner address of the owner
* @param _tokenName Name of the token
* @return bool
*/
function checkValidity(string _symbol, address _owner, string _tokenName) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
require(registeredSymbols[symbol].status != true, "Symbol status should not equal to true");
require(registeredSymbols[symbol].owner == _owner, "Owner of the symbol should matched with the requested issuer address");
require(registeredSymbols[symbol].timestamp.add(expiryLimit) >= now, "Ticker should not be expired");
registeredSymbols[symbol].tokenName = _tokenName;
registeredSymbols[symbol].status = true;
return true;
}
/**
* @notice Check the symbol is reserved or not
* @param _symbol Symbol of the token
* @param _owner Owner of the token
* @param _tokenName Name of the token
* @param _swarmHash off-chain hash
* @return bool
*/
function isReserved(string _symbol, address _owner, string _tokenName, bytes32 _swarmHash) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
if (registeredSymbols[symbol].owner == _owner && !expiryCheck(_symbol)) {
registeredSymbols[symbol].status = true;
return false;
}
else if (registeredSymbols[symbol].owner == address(0) || expiryCheck(symbol)) {
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, true);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
return false;
} else
return true;
}
/**
* @notice Returns the owner and timestamp for a given symbol
* @param _symbol symbol
* @return address
* @return uint256
* @return string
* @return bytes32
* @return bool
*/
function getDetails(string _symbol) public view returns (address, uint256, string, bytes32, bool) {
string memory symbol = upper(_symbol);
if (registeredSymbols[symbol].status == true||registeredSymbols[symbol].timestamp.add(expiryLimit) > now) {
return
(
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].swarmHash,
registeredSymbols[symbol].status
);
}else
return (address(0), uint256(0), "", bytes32(0), false);
}
/**
* @notice To re-initialize the token symbol details if symbol validity expires
* @param _symbol token symbol
* @return bool
*/
function expiryCheck(string _symbol) internal returns(bool) {
if (registeredSymbols[_symbol].owner != address(0)) {
if (now > registeredSymbols[_symbol].timestamp.add(expiryLimit) && registeredSymbols[_symbol].status != true) {
registeredSymbols[_symbol] = SymbolDetails(address(0), uint256(0), "", bytes32(0), false);
return true;
}else
return false;
}
return true;
}
/**
* @notice set the ticker registration fee in POLY tokens
* @param _registrationFee registration fee in POLY tokens (base 18 decimals)
*/
function changePolyRegisterationFee(uint256 _registrationFee) public onlyOwner {
require(registrationFee != _registrationFee);
emit LogChangePolyRegisterationFee(registrationFee, _registrationFee);
registrationFee = _registrationFee;
}
/**
* @notice pause registration function
*/
function unpause() public onlyOwner {
_unpause();
}
/**
* @notice unpause registration function
*/
function pause() public onlyOwner {
_pause();
}
} | /**
* @title Registry contract for issuers to reserve their security token symbols
* @notice Allows issuers to reserve their token symbols ahead of actually generating their security token.
* @dev SecurityTokenRegistry would reference this contract and ensure that a token symbol exists here and only its owner can deploy the token with that symbol.
*/ | NatSpecMultiLine | expiryCheck | function expiryCheck(string _symbol) internal returns(bool) {
if (registeredSymbols[_symbol].owner != address(0)) {
if (now > registeredSymbols[_symbol].timestamp.add(expiryLimit) && registeredSymbols[_symbol].status != true) {
registeredSymbols[_symbol] = SymbolDetails(address(0), uint256(0), "", bytes32(0), false);
return true;
}else
return false;
}
return true;
}
| /**
* @notice To re-initialize the token symbol details if symbol validity expires
* @param _symbol token symbol
* @return bool
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1c3fd67e0e5dae16f4d5818e4def156aa71b9a6925640af36a76c616a54e724c | {
"func_code_index": [
6185,
6667
]
} | 5,802 |
|
TickerRegistry | TickerRegistry.sol | 0xc31714e6759a1ee26db1d06af1ed276340cd4233 | Solidity | TickerRegistry | contract TickerRegistry is ITickerRegistry, Util, Pausable, RegistryUpdater, ReclaimTokens {
using SafeMath for uint256;
// constant variable to check the validity to use the symbol
// For now it's value is 15 days;
uint256 public expiryLimit = 15 * 1 days;
// Details of the symbol that get registered with the polymath platform
struct SymbolDetails {
address owner;
uint256 timestamp;
string tokenName;
bytes32 swarmHash;
bool status;
}
// Storage of symbols correspond to their details.
mapping(string => SymbolDetails) registeredSymbols;
// Emit after the symbol registration
event LogRegisterTicker(address indexed _owner, string _symbol, string _name, bytes32 _swarmHash, uint256 indexed _timestamp);
// Emit when the token symbol expiry get changed
event LogChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
// Registration fee in POLY base 18 decimals
uint256 public registrationFee;
// Emit when changePolyRegisterationFee is called
event LogChangePolyRegisterationFee(uint256 _oldFee, uint256 _newFee);
constructor (address _polymathRegistry, uint256 _registrationFee) public
RegistryUpdater(_polymathRegistry)
{
registrationFee = _registrationFee;
}
/**
* @notice Register the token symbol for its particular owner
* @notice Once the token symbol is registered to its owner then no other issuer can claim
* @notice its ownership. If the symbol expires and its issuer hasn't used it, then someone else can take it.
* @param _symbol token symbol
* @param _tokenName Name of the token
* @param _owner Address of the owner of the token
* @param _swarmHash Off-chain details of the issuer and token
*/
function registerTicker(address _owner, string _symbol, string _tokenName, bytes32 _swarmHash) public whenNotPaused {
require(_owner != address(0), "Owner should not be 0x");
require(bytes(_symbol).length > 0 && bytes(_symbol).length <= 10, "Ticker length should always between 0 & 10");
if(registrationFee > 0)
require(ERC20(polyToken).transferFrom(msg.sender, this, registrationFee), "Failed transferFrom because of sufficent Allowance is not provided");
string memory symbol = upper(_symbol);
require(expiryCheck(symbol), "Ticker is already reserved");
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, false);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
}
/**
* @notice Change the expiry time for the token symbol
* @param _newExpiry new time period for token symbol expiry
*/
function changeExpiryLimit(uint256 _newExpiry) public onlyOwner {
require(_newExpiry >= 1 days, "Expiry should greater than or equal to 1 day");
uint256 _oldExpiry = expiryLimit;
expiryLimit = _newExpiry;
emit LogChangeExpiryLimit(_oldExpiry, _newExpiry);
}
/**
* @notice Check the validity of the symbol
* @param _symbol token symbol
* @param _owner address of the owner
* @param _tokenName Name of the token
* @return bool
*/
function checkValidity(string _symbol, address _owner, string _tokenName) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
require(registeredSymbols[symbol].status != true, "Symbol status should not equal to true");
require(registeredSymbols[symbol].owner == _owner, "Owner of the symbol should matched with the requested issuer address");
require(registeredSymbols[symbol].timestamp.add(expiryLimit) >= now, "Ticker should not be expired");
registeredSymbols[symbol].tokenName = _tokenName;
registeredSymbols[symbol].status = true;
return true;
}
/**
* @notice Check the symbol is reserved or not
* @param _symbol Symbol of the token
* @param _owner Owner of the token
* @param _tokenName Name of the token
* @param _swarmHash off-chain hash
* @return bool
*/
function isReserved(string _symbol, address _owner, string _tokenName, bytes32 _swarmHash) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
if (registeredSymbols[symbol].owner == _owner && !expiryCheck(_symbol)) {
registeredSymbols[symbol].status = true;
return false;
}
else if (registeredSymbols[symbol].owner == address(0) || expiryCheck(symbol)) {
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, true);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
return false;
} else
return true;
}
/**
* @notice Returns the owner and timestamp for a given symbol
* @param _symbol symbol
* @return address
* @return uint256
* @return string
* @return bytes32
* @return bool
*/
function getDetails(string _symbol) public view returns (address, uint256, string, bytes32, bool) {
string memory symbol = upper(_symbol);
if (registeredSymbols[symbol].status == true||registeredSymbols[symbol].timestamp.add(expiryLimit) > now) {
return
(
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].swarmHash,
registeredSymbols[symbol].status
);
}else
return (address(0), uint256(0), "", bytes32(0), false);
}
/**
* @notice To re-initialize the token symbol details if symbol validity expires
* @param _symbol token symbol
* @return bool
*/
function expiryCheck(string _symbol) internal returns(bool) {
if (registeredSymbols[_symbol].owner != address(0)) {
if (now > registeredSymbols[_symbol].timestamp.add(expiryLimit) && registeredSymbols[_symbol].status != true) {
registeredSymbols[_symbol] = SymbolDetails(address(0), uint256(0), "", bytes32(0), false);
return true;
}else
return false;
}
return true;
}
/**
* @notice set the ticker registration fee in POLY tokens
* @param _registrationFee registration fee in POLY tokens (base 18 decimals)
*/
function changePolyRegisterationFee(uint256 _registrationFee) public onlyOwner {
require(registrationFee != _registrationFee);
emit LogChangePolyRegisterationFee(registrationFee, _registrationFee);
registrationFee = _registrationFee;
}
/**
* @notice pause registration function
*/
function unpause() public onlyOwner {
_unpause();
}
/**
* @notice unpause registration function
*/
function pause() public onlyOwner {
_pause();
}
} | /**
* @title Registry contract for issuers to reserve their security token symbols
* @notice Allows issuers to reserve their token symbols ahead of actually generating their security token.
* @dev SecurityTokenRegistry would reference this contract and ensure that a token symbol exists here and only its owner can deploy the token with that symbol.
*/ | NatSpecMultiLine | changePolyRegisterationFee | function changePolyRegisterationFee(uint256 _registrationFee) public onlyOwner {
require(registrationFee != _registrationFee);
emit LogChangePolyRegisterationFee(registrationFee, _registrationFee);
registrationFee = _registrationFee;
}
| /**
* @notice set the ticker registration fee in POLY tokens
* @param _registrationFee registration fee in POLY tokens (base 18 decimals)
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1c3fd67e0e5dae16f4d5818e4def156aa71b9a6925640af36a76c616a54e724c | {
"func_code_index": [
6834,
7106
]
} | 5,803 |
|
TickerRegistry | TickerRegistry.sol | 0xc31714e6759a1ee26db1d06af1ed276340cd4233 | Solidity | TickerRegistry | contract TickerRegistry is ITickerRegistry, Util, Pausable, RegistryUpdater, ReclaimTokens {
using SafeMath for uint256;
// constant variable to check the validity to use the symbol
// For now it's value is 15 days;
uint256 public expiryLimit = 15 * 1 days;
// Details of the symbol that get registered with the polymath platform
struct SymbolDetails {
address owner;
uint256 timestamp;
string tokenName;
bytes32 swarmHash;
bool status;
}
// Storage of symbols correspond to their details.
mapping(string => SymbolDetails) registeredSymbols;
// Emit after the symbol registration
event LogRegisterTicker(address indexed _owner, string _symbol, string _name, bytes32 _swarmHash, uint256 indexed _timestamp);
// Emit when the token symbol expiry get changed
event LogChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
// Registration fee in POLY base 18 decimals
uint256 public registrationFee;
// Emit when changePolyRegisterationFee is called
event LogChangePolyRegisterationFee(uint256 _oldFee, uint256 _newFee);
constructor (address _polymathRegistry, uint256 _registrationFee) public
RegistryUpdater(_polymathRegistry)
{
registrationFee = _registrationFee;
}
/**
* @notice Register the token symbol for its particular owner
* @notice Once the token symbol is registered to its owner then no other issuer can claim
* @notice its ownership. If the symbol expires and its issuer hasn't used it, then someone else can take it.
* @param _symbol token symbol
* @param _tokenName Name of the token
* @param _owner Address of the owner of the token
* @param _swarmHash Off-chain details of the issuer and token
*/
function registerTicker(address _owner, string _symbol, string _tokenName, bytes32 _swarmHash) public whenNotPaused {
require(_owner != address(0), "Owner should not be 0x");
require(bytes(_symbol).length > 0 && bytes(_symbol).length <= 10, "Ticker length should always between 0 & 10");
if(registrationFee > 0)
require(ERC20(polyToken).transferFrom(msg.sender, this, registrationFee), "Failed transferFrom because of sufficent Allowance is not provided");
string memory symbol = upper(_symbol);
require(expiryCheck(symbol), "Ticker is already reserved");
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, false);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
}
/**
* @notice Change the expiry time for the token symbol
* @param _newExpiry new time period for token symbol expiry
*/
function changeExpiryLimit(uint256 _newExpiry) public onlyOwner {
require(_newExpiry >= 1 days, "Expiry should greater than or equal to 1 day");
uint256 _oldExpiry = expiryLimit;
expiryLimit = _newExpiry;
emit LogChangeExpiryLimit(_oldExpiry, _newExpiry);
}
/**
* @notice Check the validity of the symbol
* @param _symbol token symbol
* @param _owner address of the owner
* @param _tokenName Name of the token
* @return bool
*/
function checkValidity(string _symbol, address _owner, string _tokenName) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
require(registeredSymbols[symbol].status != true, "Symbol status should not equal to true");
require(registeredSymbols[symbol].owner == _owner, "Owner of the symbol should matched with the requested issuer address");
require(registeredSymbols[symbol].timestamp.add(expiryLimit) >= now, "Ticker should not be expired");
registeredSymbols[symbol].tokenName = _tokenName;
registeredSymbols[symbol].status = true;
return true;
}
/**
* @notice Check the symbol is reserved or not
* @param _symbol Symbol of the token
* @param _owner Owner of the token
* @param _tokenName Name of the token
* @param _swarmHash off-chain hash
* @return bool
*/
function isReserved(string _symbol, address _owner, string _tokenName, bytes32 _swarmHash) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
if (registeredSymbols[symbol].owner == _owner && !expiryCheck(_symbol)) {
registeredSymbols[symbol].status = true;
return false;
}
else if (registeredSymbols[symbol].owner == address(0) || expiryCheck(symbol)) {
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, true);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
return false;
} else
return true;
}
/**
* @notice Returns the owner and timestamp for a given symbol
* @param _symbol symbol
* @return address
* @return uint256
* @return string
* @return bytes32
* @return bool
*/
function getDetails(string _symbol) public view returns (address, uint256, string, bytes32, bool) {
string memory symbol = upper(_symbol);
if (registeredSymbols[symbol].status == true||registeredSymbols[symbol].timestamp.add(expiryLimit) > now) {
return
(
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].swarmHash,
registeredSymbols[symbol].status
);
}else
return (address(0), uint256(0), "", bytes32(0), false);
}
/**
* @notice To re-initialize the token symbol details if symbol validity expires
* @param _symbol token symbol
* @return bool
*/
function expiryCheck(string _symbol) internal returns(bool) {
if (registeredSymbols[_symbol].owner != address(0)) {
if (now > registeredSymbols[_symbol].timestamp.add(expiryLimit) && registeredSymbols[_symbol].status != true) {
registeredSymbols[_symbol] = SymbolDetails(address(0), uint256(0), "", bytes32(0), false);
return true;
}else
return false;
}
return true;
}
/**
* @notice set the ticker registration fee in POLY tokens
* @param _registrationFee registration fee in POLY tokens (base 18 decimals)
*/
function changePolyRegisterationFee(uint256 _registrationFee) public onlyOwner {
require(registrationFee != _registrationFee);
emit LogChangePolyRegisterationFee(registrationFee, _registrationFee);
registrationFee = _registrationFee;
}
/**
* @notice pause registration function
*/
function unpause() public onlyOwner {
_unpause();
}
/**
* @notice unpause registration function
*/
function pause() public onlyOwner {
_pause();
}
} | /**
* @title Registry contract for issuers to reserve their security token symbols
* @notice Allows issuers to reserve their token symbols ahead of actually generating their security token.
* @dev SecurityTokenRegistry would reference this contract and ensure that a token symbol exists here and only its owner can deploy the token with that symbol.
*/ | NatSpecMultiLine | unpause | function unpause() public onlyOwner {
_unpause();
}
| /**
* @notice pause registration function
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1c3fd67e0e5dae16f4d5818e4def156aa71b9a6925640af36a76c616a54e724c | {
"func_code_index": [
7172,
7243
]
} | 5,804 |
|
TickerRegistry | TickerRegistry.sol | 0xc31714e6759a1ee26db1d06af1ed276340cd4233 | Solidity | TickerRegistry | contract TickerRegistry is ITickerRegistry, Util, Pausable, RegistryUpdater, ReclaimTokens {
using SafeMath for uint256;
// constant variable to check the validity to use the symbol
// For now it's value is 15 days;
uint256 public expiryLimit = 15 * 1 days;
// Details of the symbol that get registered with the polymath platform
struct SymbolDetails {
address owner;
uint256 timestamp;
string tokenName;
bytes32 swarmHash;
bool status;
}
// Storage of symbols correspond to their details.
mapping(string => SymbolDetails) registeredSymbols;
// Emit after the symbol registration
event LogRegisterTicker(address indexed _owner, string _symbol, string _name, bytes32 _swarmHash, uint256 indexed _timestamp);
// Emit when the token symbol expiry get changed
event LogChangeExpiryLimit(uint256 _oldExpiry, uint256 _newExpiry);
// Registration fee in POLY base 18 decimals
uint256 public registrationFee;
// Emit when changePolyRegisterationFee is called
event LogChangePolyRegisterationFee(uint256 _oldFee, uint256 _newFee);
constructor (address _polymathRegistry, uint256 _registrationFee) public
RegistryUpdater(_polymathRegistry)
{
registrationFee = _registrationFee;
}
/**
* @notice Register the token symbol for its particular owner
* @notice Once the token symbol is registered to its owner then no other issuer can claim
* @notice its ownership. If the symbol expires and its issuer hasn't used it, then someone else can take it.
* @param _symbol token symbol
* @param _tokenName Name of the token
* @param _owner Address of the owner of the token
* @param _swarmHash Off-chain details of the issuer and token
*/
function registerTicker(address _owner, string _symbol, string _tokenName, bytes32 _swarmHash) public whenNotPaused {
require(_owner != address(0), "Owner should not be 0x");
require(bytes(_symbol).length > 0 && bytes(_symbol).length <= 10, "Ticker length should always between 0 & 10");
if(registrationFee > 0)
require(ERC20(polyToken).transferFrom(msg.sender, this, registrationFee), "Failed transferFrom because of sufficent Allowance is not provided");
string memory symbol = upper(_symbol);
require(expiryCheck(symbol), "Ticker is already reserved");
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, false);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
}
/**
* @notice Change the expiry time for the token symbol
* @param _newExpiry new time period for token symbol expiry
*/
function changeExpiryLimit(uint256 _newExpiry) public onlyOwner {
require(_newExpiry >= 1 days, "Expiry should greater than or equal to 1 day");
uint256 _oldExpiry = expiryLimit;
expiryLimit = _newExpiry;
emit LogChangeExpiryLimit(_oldExpiry, _newExpiry);
}
/**
* @notice Check the validity of the symbol
* @param _symbol token symbol
* @param _owner address of the owner
* @param _tokenName Name of the token
* @return bool
*/
function checkValidity(string _symbol, address _owner, string _tokenName) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
require(registeredSymbols[symbol].status != true, "Symbol status should not equal to true");
require(registeredSymbols[symbol].owner == _owner, "Owner of the symbol should matched with the requested issuer address");
require(registeredSymbols[symbol].timestamp.add(expiryLimit) >= now, "Ticker should not be expired");
registeredSymbols[symbol].tokenName = _tokenName;
registeredSymbols[symbol].status = true;
return true;
}
/**
* @notice Check the symbol is reserved or not
* @param _symbol Symbol of the token
* @param _owner Owner of the token
* @param _tokenName Name of the token
* @param _swarmHash off-chain hash
* @return bool
*/
function isReserved(string _symbol, address _owner, string _tokenName, bytes32 _swarmHash) public returns(bool) {
string memory symbol = upper(_symbol);
require(msg.sender == securityTokenRegistry, "msg.sender should be SecurityTokenRegistry contract");
if (registeredSymbols[symbol].owner == _owner && !expiryCheck(_symbol)) {
registeredSymbols[symbol].status = true;
return false;
}
else if (registeredSymbols[symbol].owner == address(0) || expiryCheck(symbol)) {
registeredSymbols[symbol] = SymbolDetails(_owner, now, _tokenName, _swarmHash, true);
emit LogRegisterTicker (_owner, symbol, _tokenName, _swarmHash, now);
return false;
} else
return true;
}
/**
* @notice Returns the owner and timestamp for a given symbol
* @param _symbol symbol
* @return address
* @return uint256
* @return string
* @return bytes32
* @return bool
*/
function getDetails(string _symbol) public view returns (address, uint256, string, bytes32, bool) {
string memory symbol = upper(_symbol);
if (registeredSymbols[symbol].status == true||registeredSymbols[symbol].timestamp.add(expiryLimit) > now) {
return
(
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].swarmHash,
registeredSymbols[symbol].status
);
}else
return (address(0), uint256(0), "", bytes32(0), false);
}
/**
* @notice To re-initialize the token symbol details if symbol validity expires
* @param _symbol token symbol
* @return bool
*/
function expiryCheck(string _symbol) internal returns(bool) {
if (registeredSymbols[_symbol].owner != address(0)) {
if (now > registeredSymbols[_symbol].timestamp.add(expiryLimit) && registeredSymbols[_symbol].status != true) {
registeredSymbols[_symbol] = SymbolDetails(address(0), uint256(0), "", bytes32(0), false);
return true;
}else
return false;
}
return true;
}
/**
* @notice set the ticker registration fee in POLY tokens
* @param _registrationFee registration fee in POLY tokens (base 18 decimals)
*/
function changePolyRegisterationFee(uint256 _registrationFee) public onlyOwner {
require(registrationFee != _registrationFee);
emit LogChangePolyRegisterationFee(registrationFee, _registrationFee);
registrationFee = _registrationFee;
}
/**
* @notice pause registration function
*/
function unpause() public onlyOwner {
_unpause();
}
/**
* @notice unpause registration function
*/
function pause() public onlyOwner {
_pause();
}
} | /**
* @title Registry contract for issuers to reserve their security token symbols
* @notice Allows issuers to reserve their token symbols ahead of actually generating their security token.
* @dev SecurityTokenRegistry would reference this contract and ensure that a token symbol exists here and only its owner can deploy the token with that symbol.
*/ | NatSpecMultiLine | pause | function pause() public onlyOwner {
_pause();
}
| /**
* @notice unpause registration function
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://1c3fd67e0e5dae16f4d5818e4def156aa71b9a6925640af36a76c616a54e724c | {
"func_code_index": [
7310,
7376
]
} | 5,805 |
|
HollyDAO | src/contracts-nft/holly-dao.sol | 0x0db2a844efe31819cfb8184dca7244b5c29d914a | Solidity | HollyDAO | contract HollyDAO is ERC721, Ownable, ReentrancyGuard {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
Counters.Counter private _ownerCounter;
bool public saleIsActive;
string public baseURI;
uint256 public immutable maxSupply;
uint256 public immutable reservedAmount;
address public immutable proxyRegistryAddress;
uint256 public mintPrice = 40000000000000000; // 0.04 ETH
uint256 public maxSaleMint = 4;
constructor(
string memory _name,
string memory _symbol,
string memory _baseTokenURI,
uint256 _maxSupply,
uint256 _reservedAmount,
address _proxyRegistryAddress
) ERC721(_name, _symbol) {
baseURI = _baseTokenURI;
maxSupply = _maxSupply;
reservedAmount = _reservedAmount;
proxyRegistryAddress = _proxyRegistryAddress;
}
function withdraw() external onlyOwner {
uint256 balance = address(this).balance;
Address.sendValue(payable(owner()), balance);
}
function setBaseURI(string memory _baseTokenURI) public onlyOwner {
baseURI = _baseTokenURI;
}
function toggleSaleState() public onlyOwner {
saleIsActive = !saleIsActive;
}
function mint(uint256 _mintAmount) public payable nonReentrant {
require(saleIsActive, "Public mint is not open");
require(msg.value >= _mintAmount * mintPrice, "Insufficient funds");
require(
_mintAmount < maxSaleMint + 1,
"Max mint amount per tx exceeded"
);
uint256 totalSupply = _tokenIdCounter.current();
require(totalSupply < maxSupply, "All NFTs have been minted.");
for (uint256 i = 0; i < _mintAmount; i++) {
_safeMint(_msgSender(), totalSupply + i);
}
_tokenIdCounter._value += _mintAmount;
}
function mintReserved(address to, uint256 amount) public onlyOwner {
require(
_ownerCounter.current() + amount <= reservedAmount,
"Max reserved amount reached."
);
uint256 totalSupply = _tokenIdCounter.current();
for (uint256 i = 0; i < amount; i++) {
_safeMint(to, totalSupply + i);
}
_tokenIdCounter._value += amount;
_ownerCounter._value += amount;
}
// Returns the current amount of NFTs minted.
function currentSupply() public view returns (uint256) {
return _tokenIdCounter.current();
}
function isApprovedForAll(address account, address operator)
public
view
override
returns (bool)
{
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(account)) == operator) {
return true;
}
return ERC721.isApprovedForAll(account, operator);
}
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
} | currentSupply | function currentSupply() public view returns (uint256) {
return _tokenIdCounter.current();
}
| // Returns the current amount of NFTs minted. | LineComment | v0.8.10+commit.fc410830 | MIT | {
"func_code_index": [
2379,
2487
]
} | 5,806 |
|||
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
| // Function 01 - Fallback Function To Receive Donation In Eth | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
2721,
2871
]
} | 5,807 |
||
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | HodlTokens | function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
nt256 affiliatecomission = mul(amount, affiliate) / 100; // *
nt256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
int256 data_amountbalance = mul(amount, 72) / 100;
int256 data_cashbackbalance = 0;
ddress data_referrer = superOwner;
ashbackcode[msg.sender] = superOwner;
mit onCashbackCode(msg.sender, superOwner);
systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
else {
ata_amountbalance = sub(amount, affiliatecomission);
ata_cashbackbalance = mul(amount, cashback) / 100;
ata_referrer = cashbackcode[msg.sender];
systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
Insert to Database
serSafes[msg.sender].push(_currentIndex);
afes[_currentIndex] =
fe(
urrentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
| // Function 02 - Contribute (Hodl Platform) | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
2920,
4738
]
} | 5,808 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | ClaimTokens | function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
| // Function 03 - Claim (Hodl Platform) | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
4786,
5113
]
} | 5,809 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | GetUserSafesLength | function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
| // Function 04 - Get How Many Contribute ? | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
8224,
8361
]
} | 5,810 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | GetSafe | function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
| // Function 05 - Get Data Values | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
8402,
8920
]
} | 5,811 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | GetTokenFees | function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
| // Function 06 - Get Tokens Reserved For The Owner As Commission | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
8991,
9136
]
} | 5,812 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | GetContractBalance | function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
| // Function 07 - Get Contract's Balance | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
9186,
9304
]
} | 5,813 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | CashbackCode | function CashbackCode(address _cashbackcode) public {
(cashbackcode[msg.sender] == 0) {
ashbackcode[msg.sender] = _cashbackcode;
mit onCashbackCode(msg.sender, _cashbackcode);
}
| //Function 08 - Cashback Code | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
9341,
9570
]
} | 5,814 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | StoreComission | function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
| // Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
9671,
10159
]
} | 5,815 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | DeleteSafe | function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
| //??? Function 02 - Delete Safe Values In Storage | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
10217,
10711
]
} | 5,816 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | storeProfileHashed | function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
| //??? Function 03 - Store The Profile's Hash In The Blockchain | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
10782,
10979
]
} | 5,817 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | GetHodlTokensBalance | function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
| //??? Function 04 - Get User's Any Token Balance | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
11032,
11437
]
} | 5,818 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | AddContractAddress | function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
| // 00 Insert Token Contract Address | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
11731,
11889
]
} | 5,819 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | OwnerRetireHodl | function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
| // 01 Claim ( By Owner ) | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
11920,
12120
]
} | 5,820 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | ChangeHodlingTime | function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
| // 02 Change Hodling Time | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
12157,
12335
]
} | 5,821 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | ChangeAllTimeHighPrice | function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
| // 03 Change All Time High Price | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
12379,
12598
]
} | 5,822 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | ChangeComission | function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
| // 04 Change Comission Value | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
12634,
12791
]
} | 5,823 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | WithdrawEth | function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
| // 05 - Withdraw Ether Received Through Fallback Function | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
12858,
13056
]
} | 5,824 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | WithdrawTokenFees | function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
| // 06 Withdraw Token Fees By Token Address | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
13110,
13540
]
} | 5,825 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | WithdrawAllFees | function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
| // 07 Withdraw All Eth And All Tokens Fees | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
13590,
14373
]
} | 5,826 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | GetTokensAddressesWithFees | function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
| // 08 - Returns All Tokens Addresses With Fees | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
14439,
15218
]
} | 5,827 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | ReturnAllTokens | function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
| // 09 - Return All Tokens To Their Respective Addresses | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
15285,
15937
]
} | 5,828 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
| /**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
16109,
16316
]
} | 5,829 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
| /**
* @dev Integer division of two numbers, truncating the quotient.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
16410,
16710
]
} | 5,830 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
| /**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
16834,
16962
]
} | 5,831 |
|
ldoh | ldoh.sol | 0x56aeb2a3ca5f7c5a04b7e7c4f8115dc8f0df9f8a | Solidity | ldoh | contract ldoh is BlockableContract {
event onCashbackCode(address indexed hodler, address cashbackcode);
event onStoreProfileHash(address indexed hodler, string profileHashed);
event onHodlTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onClaimTokens(address indexed hodler, address indexed tokenAddress, string tokenSymbol, uint256 amount, uint256 endtime);
event onReturnAll(uint256 returned);
// Variables // * = New ** = Undeveloped
address internal AXPRtoken;
mapping(address => string) public profileHashed; // User Prime
mapping(address => address) public cashbackcode; // Cashback Code
mapping(address => bool) public contractaddress; // Contract Address
// Default Setting
uint256 public percent = 1200; // * Percent Permonth ( Only Test = 1200% )
uint256 private constant affiliate = 12; // * 12% from deposit
uint256 private constant cashback = 16; // * 16% from deposit
uint256 private constant totalreceive = 88; // * 88% from deposit
uint256 private constant seconds30days = 2592000; // *
struct Safe {
uint256 id;
uint256 amount;
uint256 endtime;
address user;
address tokenAddress;
string tokenSymbol;
uint256 amountbalance; // * --- > 88% from deposit
uint256 cashbackbalance; // * --- > 16% from deposit
uint256 lasttime; // * --- > Last Withdraw
uint256 percentage; // * --- > return tokens every month
uint256 percentagereceive; // * --- > 0 %
uint256 tokenreceive; // * --- > 0 Token
uint256 affiliatebalance; // **
address referrer; // **
}
mapping(address => uint256[]) public _userSafes; // ?????
mapping(address => uint256) public _totalSaved; // Token Balance
mapping(uint256 => Safe) private _safes; // Struct safe database
uint256 private _currentIndex; // Sequential number ( Start from 500 )
uint256 public _countSafes; // Total Smart Contract User
uint256 public hodlingTime;
uint256 public allTimeHighPrice;
uint256 public comission;
mapping(address => uint256) private _systemReserves; // Token Balance ( Reserve )
address[] public _listedReserves; // ?????
//Constructor
constructor() public {
AXPRtoken = 0xC39E626A04C5971D770e319760D7926502975e47;
hodlingTime = 730 days;
_currentIndex = 500;
comission = 12;
}
// Function 01 - Fallback Function To Receive Donation In Eth
function () public payable {
require(msg.value > 0);
_systemReserves[0x0] = add(_systemReserves[0x0], msg.value);
}
// Function 02 - Contribute (Hodl Platform)
function HodlTokens(address tokenAddress, uint256 amount) public contractActive {
require(tokenAddress != 0x0);
require(amount > 0);
if(contractaddress[tokenAddress] = false) { revert(); }
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.transferFrom(msg.sender, address(this), amount));
uint256 affiliatecomission = mul(amount, affiliate) / 100; // *
uint256 nocashback = mul(amount, 28) / 100; // *
if (cashbackcode[msg.sender] == 0 ) {
uint256 data_amountbalance = mul(amount, 72) / 100;
uint256 data_cashbackbalance = 0;
address data_referrer = superOwner;
cashbackcode[msg.sender] = superOwner;
emit onCashbackCode(msg.sender, superOwner);
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], nocashback);
} else {
data_amountbalance = sub(amount, affiliatecomission);
data_cashbackbalance = mul(amount, cashback) / 100;
data_referrer = cashbackcode[msg.sender];
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], affiliatecomission); } //--->>> Dont forget to change code
// Insert to Database
_userSafes[msg.sender].push(_currentIndex);
_safes[_currentIndex] =
Safe(
_currentIndex, amount, now + hodlingTime, msg.sender, tokenAddress, token.symbol(), data_amountbalance, data_cashbackbalance, now, percent, 0, 0, 0, data_referrer);
// Update Token Balance, Current Index, CountSafes
_totalSaved[tokenAddress] = add(_totalSaved[tokenAddress], amount);
_currentIndex++;
_countSafes++;
emit onHodlTokens(msg.sender, tokenAddress, token.symbol(), amount, now + hodlingTime);
}
// Function 03 - Claim (Hodl Platform)
function ClaimTokens(address tokenAddress, uint256 id) public {
require(tokenAddress != 0x0);
require(id != 0);
Safe storage s = _safes[id];
require(s.user == msg.sender);
if(s.amountbalance == 0) { revert(); }
RetireHodl(tokenAddress, id);
}
function RetireHodl(address tokenAddress, uint256 id) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
if(s.endtime < now) // Hodl Complete
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
eventAmount = s.amountbalance;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amountbalance); // *
s.amountbalance = 0;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
else
{
uint256 timeframe = sub(now, s.lasttime);
uint256 CalculateWithdraw = s.amount * s.percentage / 100 * timeframe / seconds30days ; // SAFE MATH FUNCTIONS ???
uint256 MaxWithdraw = mul(s.amount, 10);
// Maximum withdraw before unlocked, Max 10% Accumulation
if (CalculateWithdraw > MaxWithdraw) {
uint256 MaxAccumulation = MaxWithdraw;
} else { MaxAccumulation = CalculateWithdraw; }
// Maximum withdraw = User Amount Balance
if (MaxAccumulation > s.amountbalance) {
uint256 realAmount = s.amountbalance;
} else { realAmount = MaxAccumulation; }
uint256 newamountbalance = sub(s.amountbalance, realAmount);
UpdateUserData(tokenAddress, id, newamountbalance, realAmount);
}
}
function UpdateUserData(address tokenAddress, uint256 id, uint256 newamountbalance, uint256 realAmount) private {
Safe storage s = _safes[id];
require(s.id != 0);
require(s.tokenAddress == tokenAddress);
uint256 eventAmount;
address eventTokenAddress = s.tokenAddress;
string memory eventTokenSymbol = s.tokenSymbol;
s.amountbalance = newamountbalance;
s.lasttime = now;
uint256 tokenaffiliate = mul(s.amount, affiliate) / 100 ;
uint256 tokenreceived = s.amount - tokenaffiliate - newamountbalance; // * SAFE MATH FUNCTIONS ???
uint256 percentagereceived = tokenreceived / s.amount * 100000000000000000000; // * SAFE MATH FUNCTIONS ???
s.tokenreceive = tokenreceived;
s.percentagereceive = percentagereceived;
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], realAmount);
PayToken(s.user, s.tokenAddress, realAmount);
eventAmount = realAmount;
emit onClaimTokens(msg.sender, eventTokenAddress, eventTokenSymbol, eventAmount, now);
}
function PayToken(address user, address tokenAddress, uint256 amount) private {
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(user, amount);
}
// Function 04 - Get How Many Contribute ?
function GetUserSafesLength(address hodler) public view returns (uint256 length) {
return _userSafes[hodler].length;
}
// Function 05 - Get Data Values
function GetSafe(uint256 _id) public view
returns (uint256 id, address user, address tokenAddress, uint256 amount, uint256 endtime, string tokenSymbol, uint256 amountbalance, uint256 lasttime, uint256 percentage, uint256 percentagereceive, uint256 tokenreceive, address referrer)
{
Safe storage s = _safes[_id];
return(s.id, s.user, s.tokenAddress, s.amount, s.endtime, s.tokenSymbol, s.amountbalance, s.lasttime, s.percentage, s.percentagereceive, s.tokenreceive, s.referrer);
}
// Function 06 - Get Tokens Reserved For The Owner As Commission
function GetTokenFees(address tokenAddress) public view returns (uint256 amount) {
return _systemReserves[tokenAddress];
}
// Function 07 - Get Contract's Balance
function GetContractBalance() public view returns(uint256)
{
return address(this).balance;
}
//Function 08 - Cashback Code
function CashbackCode(address _cashbackcode) public {
if (cashbackcode[msg.sender] == 0) {
cashbackcode[msg.sender] = _cashbackcode;
emit onCashbackCode(msg.sender, _cashbackcode);
}
}
// Useless Function ( Public )
//??? Function 01 - Store Comission From Unfinished Hodl
function StoreComission(address tokenAddress, uint256 amount) private {
_systemReserves[tokenAddress] = add(_systemReserves[tokenAddress], amount);
bool isNew = true;
for(uint256 i = 0; i < _listedReserves.length; i++) {
if(_listedReserves[i] == tokenAddress) {
isNew = false;
break;
}
}
if(isNew) _listedReserves.push(tokenAddress);
}
//??? Function 02 - Delete Safe Values In Storage
function DeleteSafe(Safe s) private {
_totalSaved[s.tokenAddress] = sub(_totalSaved[s.tokenAddress], s.amount);
delete _safes[s.id];
uint256[] storage vector = _userSafes[msg.sender];
uint256 size = vector.length;
for(uint256 i = 0; i < size; i++) {
if(vector[i] == s.id) {
vector[i] = vector[size-1];
vector.length--;
break;
}
}
}
//??? Function 03 - Store The Profile's Hash In The Blockchain
function storeProfileHashed(string _profileHashed) public {
profileHashed[msg.sender] = _profileHashed;
emit onStoreProfileHash(msg.sender, _profileHashed);
}
//??? Function 04 - Get User's Any Token Balance
function GetHodlTokensBalance(address tokenAddress) public view returns (uint256 balance) {
require(tokenAddress != 0x0);
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if(s.user == msg.sender && s.tokenAddress == tokenAddress)
balance += s.amount;
}
return balance;
}
function ContractAddress(address _contractaddress, bool status) public {
contractaddress[_contractaddress] = status;
}
////////////////////////////////// onlyOwner //////////////////////////////////
// 00 Insert Token Contract Address
function AddContractAddress(address tokenAddress, bool contractstatus) public onlyOwner {
contractaddress[tokenAddress] = contractstatus;
}
// 01 Claim ( By Owner )
function OwnerRetireHodl(address tokenAddress, uint256 id) public onlyOwner {
require(tokenAddress != 0x0);
require(id != 0);
RetireHodl(tokenAddress, id);
}
// 02 Change Hodling Time
function ChangeHodlingTime(uint256 newHodlingDays) onlyOwner public {
require(newHodlingDays >= 60);
hodlingTime = newHodlingDays * 1 days;
}
// 03 Change All Time High Price
function ChangeAllTimeHighPrice(uint256 newAllTimeHighPrice) onlyOwner public {
require(newAllTimeHighPrice > allTimeHighPrice);
allTimeHighPrice = newAllTimeHighPrice;
}
// 04 Change Comission Value
function ChangeComission(uint256 newComission) onlyOwner public {
require(newComission <= 30);
comission = newComission;
}
// 05 - Withdraw Ether Received Through Fallback Function
function WithdrawEth(uint256 amount) onlyOwner public {
require(amount > 0);
require(address(this).balance >= amount);
msg.sender.transfer(amount);
}
// 06 Withdraw Token Fees By Token Address
function WithdrawTokenFees(address tokenAddress) onlyOwner public {
require(_systemReserves[tokenAddress] > 0);
uint256 amount = _systemReserves[tokenAddress];
_systemReserves[tokenAddress] = 0;
ERC20Interface token = ERC20Interface(tokenAddress);
require(token.balanceOf(address(this)) >= amount);
token.transfer(msg.sender, amount);
}
// 07 Withdraw All Eth And All Tokens Fees
function WithdrawAllFees() onlyOwner public {
// Ether
uint256 x = _systemReserves[0x0];
if(x > 0 && x <= address(this).balance) {
_systemReserves[0x0] = 0;
msg.sender.transfer(_systemReserves[0x0]);
}
// Tokens
address ta;
ERC20Interface token;
for(uint256 i = 0; i < _listedReserves.length; i++) {
ta = _listedReserves[i];
if(_systemReserves[ta] > 0)
{
x = _systemReserves[ta];
_systemReserves[ta] = 0;
token = ERC20Interface(ta);
token.transfer(msg.sender, x);
}
}
_listedReserves.length = 0;
}
// 08 - Returns All Tokens Addresses With Fees
function GetTokensAddressesWithFees()
onlyOwner public view
returns (address[], string[], uint256[])
{
uint256 length = _listedReserves.length;
address[] memory tokenAddress = new address[](length);
string[] memory tokenSymbol = new string[](length);
uint256[] memory tokenFees = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
tokenAddress[i] = _listedReserves[i];
ERC20Interface token = ERC20Interface(tokenAddress[i]);
tokenSymbol[i] = token.symbol();
tokenFees[i] = GetTokenFees(tokenAddress[i]);
}
return (tokenAddress, tokenSymbol, tokenFees);
}
// 09 - Return All Tokens To Their Respective Addresses
function ReturnAllTokens(bool onlyAXPR) onlyOwner public
{
uint256 returned;
for(uint256 i = 1; i < _currentIndex; i++) {
Safe storage s = _safes[i];
if (s.id != 0) {
if (
(onlyAXPR && s.tokenAddress == AXPRtoken) ||
!onlyAXPR
)
{
PayToken(s.user, s.tokenAddress, s.amountbalance);
_countSafes--;
returned++;
}
}
}
emit onReturnAll(returned);
}
////////////////////////////////////////////////
/**
* SAFE MATH FUNCTIONS
*
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | // Contract 03 | LineComment | add | function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
| /**
* @dev Adds two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://02e0fb3aa588a80e54cc382100aefc3ea27765f0766984c5ab32b36bc16f2818 | {
"func_code_index": [
17036,
17182
]
} | 5,832 |
|
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | initMISOTokenFactory | function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
| /// @dev GP: Migrate to the BentoBox. | NatSpecSingleLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
2661,
2928
]
} | 5,833 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | setMinimumFee | function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
| /**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
3017,
3244
]
} | 5,834 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | setIntegratorFeePct | function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
| /**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
3350,
3774
]
} | 5,835 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | setDividends | function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
| /**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
3871,
4150
]
} | 5,836 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | setLocked | function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
| /**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
4258,
4471
]
} | 5,837 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | setCurrentTemplateId | function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
| /**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
4665,
5246
]
} | 5,838 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | hasTokenMinterRole | function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
| /**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
5462,
5614
]
} | 5,839 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | deployToken | function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
| /**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
5924,
7428
]
} | 5,840 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | createToken | function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
| /**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
7788,
8338
]
} | 5,841 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | addTokenTemplate | function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
| /**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
8530,
9287
]
} | 5,842 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | removeTokenTemplate | function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
| /**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
9465,
10210
]
} | 5,843 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | numberOfTokens | function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
| /**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
10318,
10417
]
} | 5,844 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | getTokenTemplate | function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
| /**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
10683,
10818
]
} | 5,845 |
||||
MISOTokenFactory | contracts/MISOTokenFactory.sol | 0xdd8cbc86625f28cc58fe1ee13a9ee3bb5d9e1f2a | Solidity | MISOTokenFactory | contract MISOTokenFactory is CloneFactory, SafeTransfer{
/// @notice Responsible for access rights to the contract
MISOAccessControls public accessControls;
bytes32 public constant TOKEN_MINTER_ROLE = keccak256("TOKEN_MINTER_ROLE");
/// @notice Constant to indicate precision
uint256 private constant INTEGRATOR_FEE_PRECISION = 1000;
/// @notice Whether token factory has been initialized or not.
bool private initialised;
/// @notice Struct to track Token template.
struct Token {
bool exists;
uint256 templateId;
uint256 index;
}
/// @notice Mapping from token address created through this contract to Token struct.
mapping(address => Token) public tokenInfo;
/// @notice Array of tokens created using the factory.
address[] public tokens;
/// @notice Template id to track respective token template.
uint256 public tokenTemplateId;
/// @notice Mapping from token template id to token template address.
mapping(uint256 => address) private tokenTemplates;
/// @notice mapping from token template address to token template id
mapping(address => uint256) private tokenTemplateToId;
/// @notice mapping from template type to template id
mapping(uint256 => uint256) public currentTemplateId;
/// @notice Minimum fee to create a token through the factory.
uint256 public minimumFee;
uint256 public integratorFeePct;
/// @notice Contract locked status. If locked, only minters can deploy
bool public locked;
/// @notice Any MISO dividends collected are sent here.
address payable public misoDiv;
/// @notice Event emitted when first initializing Miso Token Factory.
event MisoInitTokenFactory(address sender);
/// @notice Event emitted when a token is created using template id.
event TokenCreated(address indexed owner, address indexed addr, address tokenTemplate);
/// @notice event emitted when a token is initialized using template id
event TokenInitialized(address indexed addr, uint256 templateId, bytes data);
/// @notice Event emitted when a token template is added.
event TokenTemplateAdded(address newToken, uint256 templateId);
/// @notice Event emitted when a token template is removed.
event TokenTemplateRemoved(address token, uint256 templateId);
constructor() public {
}
/**
* @notice Single gateway to initialize the MISO Token Factory with proper address.
* @dev Can only be initialized once.
* @param _accessControls Sets address to get the access controls from.
*/
/// @dev GP: Migrate to the BentoBox.
function initMISOTokenFactory(address _accessControls) external {
require(!initialised);
initialised = true;
locked = true;
accessControls = MISOAccessControls(_accessControls);
emit MisoInitTokenFactory(msg.sender);
}
/**
* @notice Sets the minimum fee.
* @param _amount Fee amount.
*/
function setMinimumFee(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
minimumFee = _amount;
}
/**
* @notice Sets integrator fee percentage.
* @param _amount Percentage amount.
*/
function setIntegratorFeePct(uint256 _amount) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
/// @dev this is out of 1000, ie 25% = 250
require(
_amount <= INTEGRATOR_FEE_PRECISION,
"MISOTokenFactory: Range is from 0 to 1000"
);
integratorFeePct = _amount;
}
/**
* @notice Sets dividend address.
* @param _divaddr Dividend address.
*/
function setDividends(address payable _divaddr) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(_divaddr != address(0));
misoDiv = _divaddr;
}
/**
* @notice Sets the factory to be locked or unlocked.
* @param _locked bool.
*/
function setLocked(bool _locked) external {
require(
accessControls.hasAdminRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
locked = _locked;
}
/**
* @notice Sets the current template ID for any type.
* @param _templateType Type of template.
* @param _templateId The ID of the current template for that type
*/
function setCurrentTemplateId(uint256 _templateType, uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be admin"
);
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
require(IMisoToken(tokenTemplates[_templateId]).tokenTemplate() == _templateType, "MISOTokenFactory: incorrect _templateType");
currentTemplateId[_templateType] = _templateId;
}
/**
* @notice Used to check whether an address has the minter role
* @param _address EOA or contract being checked
* @return bool True if the account has the role or false if it does not
*/
function hasTokenMinterRole(address _address) public view returns (bool) {
return accessControls.hasRole(TOKEN_MINTER_ROLE, _address);
}
/**
* @notice Creates a token corresponding to template id and transfers fees.
* @dev Initializes token with parameters passed
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @return token Token address.
*/
function deployToken(
uint256 _templateId,
address payable _integratorFeeAccount
)
public payable returns (address token)
{
/// @dev If the contract is locked, only admin and minters can deploy.
if (locked) {
require(accessControls.hasAdminRole(msg.sender)
|| accessControls.hasMinterRole(msg.sender)
|| hasTokenMinterRole(msg.sender),
"MISOTokenFactory: Sender must be minter if locked"
);
}
require(msg.value >= minimumFee, "MISOTokenFactory: Failed to transfer minimumFee");
require(tokenTemplates[_templateId] != address(0), "MISOTokenFactory: incorrect _templateId");
uint256 integratorFee = 0;
uint256 misoFee = msg.value;
if (_integratorFeeAccount != address(0) && _integratorFeeAccount != misoDiv) {
integratorFee = misoFee * integratorFeePct / INTEGRATOR_FEE_PRECISION;
misoFee = misoFee - integratorFee;
}
token = createClone(tokenTemplates[_templateId]);
/// @dev GP: Triple check the token index is correct.
tokenInfo[token] = Token(true, _templateId, tokens.length);
tokens.push(token);
emit TokenCreated(msg.sender, token, tokenTemplates[_templateId]);
if (misoFee > 0) {
misoDiv.transfer(misoFee);
}
if (integratorFee > 0) {
_integratorFeeAccount.transfer(integratorFee);
}
}
/**
* @notice Creates a token corresponding to template id.
* @dev Initializes token with parameters passed.
* @param _templateId Template id of token to create.
* @param _integratorFeeAccount Address to pay the fee to.
* @param _data Data to be passed to the token contract for init.
* @return token Token address.
*/
function createToken(
uint256 _templateId,
address payable _integratorFeeAccount,
bytes calldata _data
)
external payable returns (address token)
{
token = deployToken(_templateId, _integratorFeeAccount);
emit TokenInitialized(address(token), _templateId, _data);
IMisoToken(token).initToken(_data);
uint256 initialTokens = IERC20(token).balanceOf(address(this));
if (initialTokens > 0 ) {
_safeTransfer(token, msg.sender, initialTokens);
}
}
/**
* @notice Function to add a token template to create through factory.
* @dev Should have operator access.
* @param _template Token template to create a token.
*/
function addTokenTemplate(address _template) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
uint256 templateType = IMisoToken(_template).tokenTemplate();
require(templateType > 0, "MISOTokenFactory: Incorrect template code ");
require(tokenTemplateToId[_template] == 0, "MISOTokenFactory: Template exists");
tokenTemplateId++;
tokenTemplates[tokenTemplateId] = _template;
tokenTemplateToId[_template] = tokenTemplateId;
currentTemplateId[templateType] = tokenTemplateId;
emit TokenTemplateAdded(_template, tokenTemplateId);
}
/**
* @notice Function to remove a token template.
* @dev Should have operator access.
* @param _templateId Refers to template that is to be deleted.
*/
function removeTokenTemplate(uint256 _templateId) external {
require(
accessControls.hasAdminRole(msg.sender) ||
accessControls.hasOperatorRole(msg.sender),
"MISOTokenFactory: Sender must be operator"
);
require(tokenTemplates[_templateId] != address(0));
address template = tokenTemplates[_templateId];
uint256 templateType = IMisoToken(tokenTemplates[_templateId]).tokenTemplate();
if (currentTemplateId[templateType] == _templateId) {
delete currentTemplateId[templateType];
}
tokenTemplates[_templateId] = address(0);
delete tokenTemplateToId[template];
emit TokenTemplateRemoved(template, _templateId);
}
/**
* @notice Get the total number of tokens in the factory.
* @return Token count.
*/
function numberOfTokens() external view returns (uint256) {
return tokens.length;
}
function getTokens() external view returns (address[] memory) {
return tokens;
}
/**
* @notice Get the address based on template ID.
* @param _templateId Token template ID.
* @return Address of the required template ID.
*/
function getTokenTemplate(uint256 _templateId) external view returns (address ) {
return tokenTemplates[_templateId];
}
/**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/
function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
} | getTemplateId | function getTemplateId(address _tokenTemplate) external view returns (uint256) {
return tokenTemplateToId[_tokenTemplate];
}
| /**
* @notice Get the ID based on template address.
* @param _tokenTemplate Token template address.
* @return ID of the required template address.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | {
"func_code_index": [
10994,
11134
]
} | 5,846 |
||||
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
243,
429
]
} | 5,847 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
675,
906
]
} | 5,848 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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 underflow");
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
1170,
1312
]
} | 5,849 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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 underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
1596,
1827
]
} | 5,850 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
2065,
2541
]
} | 5,851 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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,
string memory errorMessage
) 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, errorMessage);
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
2779,
3294
]
} | 5,852 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
3757,
3894
]
} | 5,853 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @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.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
4377,
4761
]
} | 5,854 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
5213,
5348
]
} | 5,855 |
Timelock | Timelock.sol | 0xf6f9375060fd7472ff7233e9909ab045feefc699 | 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 addition of two unsigned integers, reverting with custom message on overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, errorMessage);
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction underflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on underflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot underflow.
*/
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 multiplication of two unsigned integers, reverting on overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(
uint256 a,
uint256 b,
string memory errorMessage
) 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, errorMessage);
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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @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.5.17+commit.d19bba13 | Unknown | bzzr://1f8fbdf8084aa3c7dd08c19d331a9ac0c2520824eceae3954b34e9a79af85f20 | {
"func_code_index": [
5820,
6025
]
} | 5,856 |
HistoryMkrSingleWhitelist | contracts/HistoryMkr_single_whitelist.sol | 0x1b6d4c04d23e119d7046e50c9fa294945d811fb2 | Solidity | FeelGood | interface FeelGood {
// mind the `view` modifier
function balanceOf(address _owner) external view returns (uint256);
} | balanceOf | function balanceOf(address _owner) external view returns (uint256);
| // mind the `view` modifier | LineComment | v0.8.7+commit.e28d00a7 | {
"func_code_index": [
53,
124
]
} | 5,857 |
||||
HistoryMkrSingleWhitelist | contracts/HistoryMkr_single_whitelist.sol | 0x1b6d4c04d23e119d7046e50c9fa294945d811fb2 | Solidity | HistoryMkrSingleWhitelist | contract HistoryMkrSingleWhitelist is HistoryMkr, ERC721Pausable, ERC721Burnable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdTracker;
mapping(address => uint8) preMintBalanceLedger; //map to track preMintBalances (otherwise they can move away and buy again)
bool private preMintEnabled = false;
bool public running = true;
FeelGood public feelGoodContract;
constructor(string memory name, string memory symbol, string memory _provenanceHash, address _whitelistContract, address payable _treasurer, uint16 _initialId, uint16 _treasurersTokens, uint16 _maxAvailableTokens)
HistoryMkr(name, symbol, _provenanceHash, _treasurer, _initialId, _treasurersTokens, _maxAvailableTokens) {
royaltyPercentageBasePoints = 500; //5%
feelGoodContract = FeelGood(_whitelistContract);
}
function _beforeTokenTransfer(address from, address to, uint256 tokenId)
internal
whenNotPaused
override(HistoryMkr, ERC721, ERC721Pausable) {
super._beforeTokenTransfer(from, to, tokenId);
}
function _burn(uint256 tokenId) internal override(HistoryMkr, ERC721) {
super._burn(tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override(HistoryMkr, ERC721) returns (bool) {
return super.supportsInterface(interfaceId);
}
function contractURI() public view override returns (string memory) {
return "ipfs://QmRTBo4Zz38qAqu53GBXuzRWWgVvUnuFsbtp1rGYqRQabS/";
}
function tokenURI(uint256 tokenId) public view override(ERC721, HistoryMkr) returns (string memory) {
return super.tokenURI(tokenId);
}
function preMint() public payable whenMintPaused() {
require(preMintEnabled, "this can only be done before any minting is open to public");
require(preMintBalanceLedger[msg.sender] == 0, "you have bought your limit"); //checking in our map
uint256 senderBalance = feelGoodContract.balanceOf(msg.sender);
require(senderBalance > 0, "you are not on the whitelist for preMint purchasing");
require(_tokenIdTracker.current() + 1 <= maxAvailableTokens, "all tokens have been minted");
require(!Address.isContract(msg.sender), "address cannot be a contract");
require(msg.value == _salePrice, "Ether sent is not equal to PRICE" );
payable(treasurer).transfer(msg.value);
transferNFTs(1, msg.sender);
preMintBalanceLedger[msg.sender] = preMintBalanceLedger[msg.sender] + 1;
}
function currentState() public view returns (string memory) {
console.log("checking current state");
string memory state = "idle";
if (paused()) {
state = "paused";
} else if (preMintEnabled) {
state = "premint";
} else if (!mintPaused) {
state = "mint";
}
console.log("returning state:", state);
return state;
}
function startMintingProcess(uint256 tokenPrice) public override whenRunning() whenPreMintDisabled() onlyOwner {
super.startMintingProcess(tokenPrice);
}
function startPreMintingProcess(uint256 tokenPrice) public whenRunning() whenMintPaused() onlyOwner {
require(balanceOf(treasurer) >= treasurersTokens, "cannot pre mint until all tokens have been claimed");
_salePrice = tokenPrice;
preMintEnabled = true;
}
function stopPreMintingProcess() public whenMintPaused() onlyOwner {
preMintEnabled = false;
}
function pause() public onlyOwner {
_pause();
}
function unpause() public whenRunning() onlyOwner {
_unpause();
}
//very dangerosus. Stops the entire contract
function endContract() public onlyOwner() {
pause();
preMintEnabled = false;
running = false;
}
function _baseURI() internal view virtual override (HistoryMkr, ERC721) returns (string memory) {
return baseURI;
}
function setNewTreasurer(address payable _treasurer) public whenPaused onlyOwner {
treasurer = _treasurer;
}
modifier whenRunning() {
require(running, "contract is no longer running");
_;
}
modifier whenPreMintDisabled() {
require(!preMintEnabled, "pre mint is running");
_;
}
} | endContract | function endContract() public onlyOwner() {
pause();
preMintEnabled = false;
running = false;
}
| //very dangerosus. Stops the entire contract | LineComment | v0.8.7+commit.e28d00a7 | {
"func_code_index": [
3727,
3854
]
} | 5,858 |
||||
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | SafeERC20 | library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(ERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(ERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*/
function safeApprove(ERC20 token, address spender, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(ERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(ERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function _callOptionalReturn(ERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) { // Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
} | safeApprove | function safeApprove(ERC20 token, address spender, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
| /**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
637,
826
]
} | 5,859 |
||
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | AdminAuth | contract AdminAuth {
using SafeERC20 for ERC20;
address public owner;
address public admin;
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
constructor() public {
owner = msg.sender;
}
/// @notice Admin is set by owner first time, after that admin is super role and has permission to change owner
/// @param _admin Address of multisig that becomes admin
function setAdminByOwner(address _admin) public {
require(msg.sender == owner);
require(admin == address(0));
admin = _admin;
}
/// @notice Admin is able to set new admin
/// @param _admin Address of multisig that becomes new admin
function setAdminByAdmin(address _admin) public {
require(msg.sender == admin);
admin = _admin;
}
/// @notice Admin is able to change owner
/// @param _owner Address of new owner
function setOwnerByAdmin(address _owner) public {
require(msg.sender == admin);
owner = _owner;
}
/// @notice Destroy the contract
function kill() public onlyOwner {
selfdestruct(payable(owner));
}
/// @notice withdraw stuck funds
function withdrawStuckFunds(address _token, uint _amount) public onlyOwner {
if (_token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(owner).transfer(_amount);
} else {
ERC20(_token).safeTransfer(owner, _amount);
}
}
} | setAdminByOwner | function setAdminByOwner(address _admin) public {
require(msg.sender == owner);
require(admin == address(0));
admin = _admin;
}
| /// @notice Admin is set by owner first time, after that admin is super role and has permission to change owner
/// @param _admin Address of multisig that becomes admin | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
447,
613
]
} | 5,860 |
||
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | AdminAuth | contract AdminAuth {
using SafeERC20 for ERC20;
address public owner;
address public admin;
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
constructor() public {
owner = msg.sender;
}
/// @notice Admin is set by owner first time, after that admin is super role and has permission to change owner
/// @param _admin Address of multisig that becomes admin
function setAdminByOwner(address _admin) public {
require(msg.sender == owner);
require(admin == address(0));
admin = _admin;
}
/// @notice Admin is able to set new admin
/// @param _admin Address of multisig that becomes new admin
function setAdminByAdmin(address _admin) public {
require(msg.sender == admin);
admin = _admin;
}
/// @notice Admin is able to change owner
/// @param _owner Address of new owner
function setOwnerByAdmin(address _owner) public {
require(msg.sender == admin);
owner = _owner;
}
/// @notice Destroy the contract
function kill() public onlyOwner {
selfdestruct(payable(owner));
}
/// @notice withdraw stuck funds
function withdrawStuckFunds(address _token, uint _amount) public onlyOwner {
if (_token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(owner).transfer(_amount);
} else {
ERC20(_token).safeTransfer(owner, _amount);
}
}
} | setAdminByAdmin | function setAdminByAdmin(address _admin) public {
require(msg.sender == admin);
admin = _admin;
}
| /// @notice Admin is able to set new admin
/// @param _admin Address of multisig that becomes new admin | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
730,
857
]
} | 5,861 |
||
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | AdminAuth | contract AdminAuth {
using SafeERC20 for ERC20;
address public owner;
address public admin;
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
constructor() public {
owner = msg.sender;
}
/// @notice Admin is set by owner first time, after that admin is super role and has permission to change owner
/// @param _admin Address of multisig that becomes admin
function setAdminByOwner(address _admin) public {
require(msg.sender == owner);
require(admin == address(0));
admin = _admin;
}
/// @notice Admin is able to set new admin
/// @param _admin Address of multisig that becomes new admin
function setAdminByAdmin(address _admin) public {
require(msg.sender == admin);
admin = _admin;
}
/// @notice Admin is able to change owner
/// @param _owner Address of new owner
function setOwnerByAdmin(address _owner) public {
require(msg.sender == admin);
owner = _owner;
}
/// @notice Destroy the contract
function kill() public onlyOwner {
selfdestruct(payable(owner));
}
/// @notice withdraw stuck funds
function withdrawStuckFunds(address _token, uint _amount) public onlyOwner {
if (_token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(owner).transfer(_amount);
} else {
ERC20(_token).safeTransfer(owner, _amount);
}
}
} | setOwnerByAdmin | function setOwnerByAdmin(address _owner) public {
require(msg.sender == admin);
owner = _owner;
}
| /// @notice Admin is able to change owner
/// @param _owner Address of new owner | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
951,
1078
]
} | 5,862 |
||
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | AdminAuth | contract AdminAuth {
using SafeERC20 for ERC20;
address public owner;
address public admin;
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
constructor() public {
owner = msg.sender;
}
/// @notice Admin is set by owner first time, after that admin is super role and has permission to change owner
/// @param _admin Address of multisig that becomes admin
function setAdminByOwner(address _admin) public {
require(msg.sender == owner);
require(admin == address(0));
admin = _admin;
}
/// @notice Admin is able to set new admin
/// @param _admin Address of multisig that becomes new admin
function setAdminByAdmin(address _admin) public {
require(msg.sender == admin);
admin = _admin;
}
/// @notice Admin is able to change owner
/// @param _owner Address of new owner
function setOwnerByAdmin(address _owner) public {
require(msg.sender == admin);
owner = _owner;
}
/// @notice Destroy the contract
function kill() public onlyOwner {
selfdestruct(payable(owner));
}
/// @notice withdraw stuck funds
function withdrawStuckFunds(address _token, uint _amount) public onlyOwner {
if (_token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(owner).transfer(_amount);
} else {
ERC20(_token).safeTransfer(owner, _amount);
}
}
} | kill | function kill() public onlyOwner {
selfdestruct(payable(owner));
}
| /// @notice Destroy the contract | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
1119,
1204
]
} | 5,863 |
||
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | AdminAuth | contract AdminAuth {
using SafeERC20 for ERC20;
address public owner;
address public admin;
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
constructor() public {
owner = msg.sender;
}
/// @notice Admin is set by owner first time, after that admin is super role and has permission to change owner
/// @param _admin Address of multisig that becomes admin
function setAdminByOwner(address _admin) public {
require(msg.sender == owner);
require(admin == address(0));
admin = _admin;
}
/// @notice Admin is able to set new admin
/// @param _admin Address of multisig that becomes new admin
function setAdminByAdmin(address _admin) public {
require(msg.sender == admin);
admin = _admin;
}
/// @notice Admin is able to change owner
/// @param _owner Address of new owner
function setOwnerByAdmin(address _owner) public {
require(msg.sender == admin);
owner = _owner;
}
/// @notice Destroy the contract
function kill() public onlyOwner {
selfdestruct(payable(owner));
}
/// @notice withdraw stuck funds
function withdrawStuckFunds(address _token, uint _amount) public onlyOwner {
if (_token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(owner).transfer(_amount);
} else {
ERC20(_token).safeTransfer(owner, _amount);
}
}
} | withdrawStuckFunds | function withdrawStuckFunds(address _token, uint _amount) public onlyOwner {
if (_token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(owner).transfer(_amount);
} else {
ERC20(_token).safeTransfer(owner, _amount);
}
}
| /// @notice withdraw stuck funds | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
1246,
1536
]
} | 5,864 |
||
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | subscribe | function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
| /// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
1237,
2507
]
} | 5,865 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | unsubscribe | function unsubscribe() external {
_unsubscribe(msg.sender);
}
| /// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
2615,
2695
]
} | 5,866 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | checkParams | function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
| /// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
2964,
3167
]
} | 5,867 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | _unsubscribe | function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
| /// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
3310,
4050
]
} | 5,868 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | isSubscribed | function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
| /// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
4216,
4393
]
} | 5,869 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | getHolder | function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
| /// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
4596,
4796
]
} | 5,870 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | getSubscribers | function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
| /// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
4905,
5019
]
} | 5,871 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | getSubscribersByPage | function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
| /// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
5276,
5790
]
} | 5,872 |
CompoundSubscriptions | CompoundSubscriptions.sol | 0x52015effd577e08f498a0ccc11905925d58d6207 | Solidity | CompoundSubscriptions | contract CompoundSubscriptions is AdminAuth {
struct CompoundHolder {
address user;
uint128 minRatio;
uint128 maxRatio;
uint128 optimalRatioBoost;
uint128 optimalRatioRepay;
bool boostEnabled;
}
struct SubPosition {
uint arrPos;
bool subscribed;
}
CompoundHolder[] public subscribers;
mapping (address => SubPosition) public subscribersPos;
uint public changeIndex;
event Subscribed(address indexed user);
event Unsubscribed(address indexed user);
event Updated(address indexed user);
event ParamUpdates(address indexed user, uint128, uint128, uint128, uint128, bool);
/// @dev Called by the DSProxy contract which owns the Compound position
/// @notice Adds the users Compound poistion in the list of subscriptions so it can be monitored
/// @param _minRatio Minimum ratio below which repay is triggered
/// @param _maxRatio Maximum ratio after which boost is triggered
/// @param _optimalBoost Ratio amount which boost should target
/// @param _optimalRepay Ratio amount which repay should target
/// @param _boostEnabled Boolean determing if boost is enabled
function subscribe(uint128 _minRatio, uint128 _maxRatio, uint128 _optimalBoost, uint128 _optimalRepay, bool _boostEnabled) external {
// if boost is not enabled, set max ratio to max uint
uint128 localMaxRatio = _boostEnabled ? _maxRatio : uint128(-1);
require(checkParams(_minRatio, localMaxRatio), "Must be correct params");
SubPosition storage subInfo = subscribersPos[msg.sender];
CompoundHolder memory subscription = CompoundHolder({
minRatio: _minRatio,
maxRatio: localMaxRatio,
optimalRatioBoost: _optimalBoost,
optimalRatioRepay: _optimalRepay,
user: msg.sender,
boostEnabled: _boostEnabled
});
changeIndex++;
if (subInfo.subscribed) {
subscribers[subInfo.arrPos] = subscription;
emit Updated(msg.sender);
emit ParamUpdates(msg.sender, _minRatio, localMaxRatio, _optimalBoost, _optimalRepay, _boostEnabled);
} else {
subscribers.push(subscription);
subInfo.arrPos = subscribers.length - 1;
subInfo.subscribed = true;
emit Subscribed(msg.sender);
}
}
/// @notice Called by the users DSProxy
/// @dev Owner who subscribed cancels his subscription
function unsubscribe() external {
_unsubscribe(msg.sender);
}
/// @dev Checks limit if minRatio is bigger than max
/// @param _minRatio Minimum ratio, bellow which repay can be triggered
/// @param _maxRatio Maximum ratio, over which boost can be triggered
/// @return Returns bool if the params are correct
function checkParams(uint128 _minRatio, uint128 _maxRatio) internal pure returns (bool) {
if (_minRatio > _maxRatio) {
return false;
}
return true;
}
/// @dev Internal method to remove a subscriber from the list
/// @param _user The actual address that owns the Compound position
function _unsubscribe(address _user) internal {
require(subscribers.length > 0, "Must have subscribers in the list");
SubPosition storage subInfo = subscribersPos[_user];
require(subInfo.subscribed, "Must first be subscribed");
address lastOwner = subscribers[subscribers.length - 1].user;
SubPosition storage subInfo2 = subscribersPos[lastOwner];
subInfo2.arrPos = subInfo.arrPos;
subscribers[subInfo.arrPos] = subscribers[subscribers.length - 1];
subscribers.pop(); // remove last element and reduce arr length
changeIndex++;
subInfo.subscribed = false;
subInfo.arrPos = 0;
emit Unsubscribed(msg.sender);
}
/// @dev Checks if the user is subscribed
/// @param _user The actual address that owns the Compound position
/// @return If the user is subscribed
function isSubscribed(address _user) public view returns (bool) {
SubPosition storage subInfo = subscribersPos[_user];
return subInfo.subscribed;
}
/// @dev Returns subscribtion information about a user
/// @param _user The actual address that owns the Compound position
/// @return Subscription information about the user if exists
function getHolder(address _user) public view returns (CompoundHolder memory) {
SubPosition storage subInfo = subscribersPos[_user];
return subscribers[subInfo.arrPos];
}
/// @notice Helper method to return all the subscribed CDPs
/// @return List of all subscribers
function getSubscribers() public view returns (CompoundHolder[] memory) {
return subscribers;
}
/// @notice Helper method for the frontend, returns all the subscribed CDPs paginated
/// @param _page What page of subscribers you want
/// @param _perPage Number of entries per page
/// @return List of all subscribers for that page
function getSubscribersByPage(uint _page, uint _perPage) public view returns (CompoundHolder[] memory) {
CompoundHolder[] memory holders = new CompoundHolder[](_perPage);
uint start = _page * _perPage;
uint end = start + _perPage;
end = (end > holders.length) ? holders.length : end;
uint count = 0;
for (uint i = start; i < end; i++) {
holders[count] = subscribers[i];
count++;
}
return holders;
}
////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position
function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
} | /// @title Stores subscription information for Compound automatization | NatSpecSingleLine | unsubscribeByAdmin | function unsubscribeByAdmin(address _user) public onlyOwner {
SubPosition storage subInfo = subscribersPos[_user];
if (subInfo.subscribed) {
_unsubscribe(_user);
}
}
| ////////////// ADMIN METHODS ///////////////////
/// @notice Admin function to unsubscribe a CDP
/// @param _user The actual address that owns the Compound position | NatSpecSingleLine | v0.6.6+commit.6c089d02 | MIT | ipfs://cc3a54bef48e7c0949180eded7674ff5bd977a5f62bcb41a4f71e8a203e1c0ad | {
"func_code_index": [
5975,
6192
]
} | 5,873 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | SafeERC20 | library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
callOptionalReturn(
token,
abi.encodeWithSelector(token.transfer.selector, to, value)
);
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
callOptionalReturn(
token,
abi.encodeWithSelector(token.transferFrom.selector, from, to, value)
);
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(
token,
abi.encodeWithSelector(token.approve.selector, spender, value)
);
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(
value
);
callOptionalReturn(
token,
abi.encodeWithSelector(
token.approve.selector,
spender,
newAllowance
)
);
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(
value,
"SafeERC20: decreased allowance below zero"
);
callOptionalReturn(
token,
abi.encodeWithSelector(
token.approve.selector,
spender,
newAllowance
)
);
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
// solhint-disable-next-line max-line-length
require(
abi.decode(returndata, (bool)),
"SafeERC20: ERC20 operation did not succeed"
);
}
}
} | /**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/ | NatSpecMultiLine | callOptionalReturn | function callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
require(address(token).isContract(), "SafeERC20: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
// solhint-disable-next-line max-line-length
require(
abi.decode(returndata, (bool)),
"SafeERC20: ERC20 operation did not succeed"
);
}
}
| /**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
2698,
3879
]
} | 5,874 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | 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 onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
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 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
521,
605
]
} | 5,875 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | 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 onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
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 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 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
1163,
1308
]
} | 5,876 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | 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 onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
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 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 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
1458,
1736
]
} | 5,877 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | token | function token() public view returns (IERC20) {
return _token;
}
| /**
* @return the token being sold.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
2116,
2199
]
} | 5,878 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | wallet | function wallet() public view returns (address payable) {
return _wallet;
}
| /**
* @return the address where funds are collected.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
2275,
2369
]
} | 5,879 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | rate | function rate() public view returns (uint256) {
return _rate;
}
| /**
* @return the number of token units a buyer gets per wei.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
2454,
2536
]
} | 5,880 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | weiRaised | function weiRaised() public view returns (uint256) {
return _weiRaised;
}
| /**
* @return the amount of wei raised.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
2599,
2691
]
} | 5,881 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | buyTokens | function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
| /**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
3022,
3686
]
} | 5,882 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | _preValidatePurchase | function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
| /**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
4234,
4925
]
} | 5,883 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | _deliverTokens | function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
| /**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
5208,
5352
]
} | 5,884 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | _getTokenAmount | function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
| /**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
5603,
5762
]
} | 5,885 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | Crowdsale | contract Crowdsale is Context, Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// The token being sold
IERC20 public _token;
mapping(address => uint256) public _balances;
mapping(address => uint256) public _balancesPurchased;
// Address where funds are collected
address payable private _wallet;
uint256 private _maxCapETH = 300e18;
uint256 public _currentSaleToken = 0;
uint256 public _capTokenSale = 400000e18;
uint256 private _individualMaxCap = 10e18;
uint256 private _individualMinCap = 5e17;
uint256 private _rate;
// Amount of wei raised
uint256 private _weiRaised;
/**
* Event for token purchase logging
* @param purchaser who paid for the tokens
* @param beneficiary who got the tokens
* @param value weis paid for purchase
* @param amount amount of tokens purchased
*/
event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
/**
* @param rate Number of token units a buyer gets per wei
* @dev The rate is the conversion between wei and the smallest and indivisible
* token unit. So, if you are using a rate of 1 with a ERC20Detailed token
* with 3 decimals called TOK, 1 wei will give you 1 unit, or 0.001 TOK.
* @param wallet Address where collected funds will be forwarded to
* @param token Address of the token being sold
*/
constructor(
uint256 rate,
address payable wallet,
IERC20 token
) public {
require(rate > 0, "Crowdsale: rate is 0");
require(wallet != address(0), "Crowdsale: wallet is the zero address");
require(
address(token) != address(0),
"Crowdsale: token is the zero address"
);
_rate = rate;
_wallet = wallet;
_token = token;
}
receive() external payable {
buyTokens();
}
/**
* @return the token being sold.
*/
function token() public view returns (IERC20) {
return _token;
}
/**
* @return the address where funds are collected.
*/
function wallet() public view returns (address payable) {
return _wallet;
}
/**
* @return the number of token units a buyer gets per wei.
*/
function rate() public view returns (uint256) {
return _rate;
}
/**
* @return the amount of wei raised.
*/
function weiRaised() public view returns (uint256) {
return _weiRaised;
}
function remainingTokenSale() public view returns (uint256) {
return _capTokenSale.sub(_currentSaleToken);
}
/**
* @dev low level token purchase ***DO NOT OVERRIDE***
* This function has a non-reentrancy guard, so it shouldn't be called by
* another `nonReentrant` function.
*/
function buyTokens() public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_msgSender(), weiAmount);
// calculate token amount to be created
uint256 tokens = _getTokenAmount(weiAmount);
// update state
require(_weiRaised <= _maxCapETH);
_weiRaised = _weiRaised.add(weiAmount);
emit TokensPurchased(_msgSender(), _msgSender(), weiAmount, tokens);
_forwardFunds();
_currentSaleToken = _currentSaleToken.add(tokens);
require(_capTokenSale >= _currentSaleToken);
_balances[_msgSender()] = _balances[_msgSender()].add(tokens);
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met.
* Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
* super._preValidatePurchase(beneficiary, weiAmount);
* require(weiRaised().add(weiAmount) <= cap);
* @param beneficiary Address performing the token purchase
* @param weiAmount Value in wei involved in the purchase
*/
function _preValidatePurchase(address beneficiary, uint256 weiAmount)
internal
virtual
{
require(
beneficiary != address(0),
"Crowdsale: beneficiary is the zero address"
);
require(weiAmount != 0, "Crowdsale: weiAmount is 0");
require(
weiAmount >= _individualMinCap,
"Crowdsale: Min individual cap"
);
_balancesPurchased[beneficiary] = _balancesPurchased[beneficiary].add(
weiAmount
);
require(
_balancesPurchased[beneficiary] <= _individualMaxCap,
"Crowdsale: Max individual cap"
);
}
/**
* @dev Source of tokens. Override this method to modify the way in which the crowdsale ultimately gets and sends
* its tokens.
* @param beneficiary Address performing the token purchase
* @param tokenAmount Number of tokens to be emitted
*/
function _deliverTokens(address beneficiary, uint256 tokenAmount) internal {
_token.safeTransfer(beneficiary, tokenAmount);
}
/**
* @dev Override to extend the way in which ether is converted to tokens.
* @param weiAmount Value in wei to be converted into tokens
* @return Number of tokens that can be purchased with the specified _weiAmount
*/
function _getTokenAmount(uint256 weiAmount)
internal
view
returns (uint256)
{
return weiAmount.mul(_rate);
}
/**
* @dev Determines how ETH is stored/forwarded on purchases.
*/
function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
} | /**
* @title Crowdsale
* @dev Crowdsale is a base contract for managing a token crowdsale,
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
*/ | NatSpecMultiLine | _forwardFunds | function _forwardFunds() internal {
uint256 weiAmount = msg.value;
_wallet.transfer(weiAmount);
}
| /**
* @dev Determines how ETH is stored/forwarded on purchases.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
5849,
5974
]
} | 5,886 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | TimedCrowdsale | abstract contract TimedCrowdsale is Crowdsale {
using SafeMath for uint256;
uint256 private _openingTime;
uint256 private _closingTime;
uint256 public _finalizedTime;
bool public _isStopped = false;
bool public isDepositedTokenSale = false;
function start() public onlyOwner {
require(!isOpen(), "TimedCrowdsale: opened");
require(isDepositedTokenSale, "TimedCrowdsale: no token sale");
_openingTime = block.timestamp;
}
function stop() public onlyOwner {
require(isOpen(), "TimedCrowdsale: closed");
_isStopped = true;
}
/**
* @dev Reverts if not in crowdsale time range.
*/
modifier onlyWhileOpen {
require(isOpen() && !_isStopped, "TimedCrowdsale: not open");
_;
}
modifier withdrawable {
require(
_finalizedTime > 0 &&
block.timestamp > _finalizedTime.add(30 minutes)
);
_;
}
/**
* @return the crowdsale opening time.
*/
function openingTime() public view returns (uint256) {
return _openingTime;
}
/**
* @return true if the crowdsale is open, false otherwise.
*/
function isOpen() public view returns (bool) {
return _openingTime > 0 && block.timestamp >= _openingTime;
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return _openingTime > 0 && _isStopped;
}
} | /**
* @title TimedCrowdsale
* @dev Crowdsale accepting contributions only within a time frame.
*/ | NatSpecMultiLine | openingTime | function openingTime() public view returns (uint256) {
return _openingTime;
}
| /**
* @return the crowdsale opening time.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
1062,
1158
]
} | 5,887 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | TimedCrowdsale | abstract contract TimedCrowdsale is Crowdsale {
using SafeMath for uint256;
uint256 private _openingTime;
uint256 private _closingTime;
uint256 public _finalizedTime;
bool public _isStopped = false;
bool public isDepositedTokenSale = false;
function start() public onlyOwner {
require(!isOpen(), "TimedCrowdsale: opened");
require(isDepositedTokenSale, "TimedCrowdsale: no token sale");
_openingTime = block.timestamp;
}
function stop() public onlyOwner {
require(isOpen(), "TimedCrowdsale: closed");
_isStopped = true;
}
/**
* @dev Reverts if not in crowdsale time range.
*/
modifier onlyWhileOpen {
require(isOpen() && !_isStopped, "TimedCrowdsale: not open");
_;
}
modifier withdrawable {
require(
_finalizedTime > 0 &&
block.timestamp > _finalizedTime.add(30 minutes)
);
_;
}
/**
* @return the crowdsale opening time.
*/
function openingTime() public view returns (uint256) {
return _openingTime;
}
/**
* @return true if the crowdsale is open, false otherwise.
*/
function isOpen() public view returns (bool) {
return _openingTime > 0 && block.timestamp >= _openingTime;
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return _openingTime > 0 && _isStopped;
}
} | /**
* @title TimedCrowdsale
* @dev Crowdsale accepting contributions only within a time frame.
*/ | NatSpecMultiLine | isOpen | function isOpen() public view returns (bool) {
return _openingTime > 0 && block.timestamp >= _openingTime;
}
| /**
* @return true if the crowdsale is open, false otherwise.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
1243,
1370
]
} | 5,888 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | TimedCrowdsale | abstract contract TimedCrowdsale is Crowdsale {
using SafeMath for uint256;
uint256 private _openingTime;
uint256 private _closingTime;
uint256 public _finalizedTime;
bool public _isStopped = false;
bool public isDepositedTokenSale = false;
function start() public onlyOwner {
require(!isOpen(), "TimedCrowdsale: opened");
require(isDepositedTokenSale, "TimedCrowdsale: no token sale");
_openingTime = block.timestamp;
}
function stop() public onlyOwner {
require(isOpen(), "TimedCrowdsale: closed");
_isStopped = true;
}
/**
* @dev Reverts if not in crowdsale time range.
*/
modifier onlyWhileOpen {
require(isOpen() && !_isStopped, "TimedCrowdsale: not open");
_;
}
modifier withdrawable {
require(
_finalizedTime > 0 &&
block.timestamp > _finalizedTime.add(30 minutes)
);
_;
}
/**
* @return the crowdsale opening time.
*/
function openingTime() public view returns (uint256) {
return _openingTime;
}
/**
* @return true if the crowdsale is open, false otherwise.
*/
function isOpen() public view returns (bool) {
return _openingTime > 0 && block.timestamp >= _openingTime;
}
/**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/
function hasClosed() public view returns (bool) {
return _openingTime > 0 && _isStopped;
}
} | /**
* @title TimedCrowdsale
* @dev Crowdsale accepting contributions only within a time frame.
*/ | NatSpecMultiLine | hasClosed | function hasClosed() public view returns (bool) {
return _openingTime > 0 && _isStopped;
}
| /**
* @dev Checks whether the period in which the crowdsale is open has already elapsed.
* @return Whether crowdsale period has elapsed
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
1535,
1644
]
} | 5,889 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | PostDeliveryCrowdsale | abstract contract PostDeliveryCrowdsale is TimedCrowdsale {
using SafeMath for uint256;
IERC20 private _tokenSale;
mapping(address => bool) public withdrawableTokens;
constructor(IERC20 _token) public {
_tokenSale = _token;
}
/**
* @dev Withdraw tokens only after crowdsale ends.
*/
function withdrawTokens() public withdrawable {
require(!withdrawableTokens[_msgSender()]);
uint256 amount = _balances[_msgSender()];
require(
amount > 0,
"PostDeliveryCrowdsale: beneficiary is not due any tokens"
);
_deliverTokens(_msgSender(), amount);
withdrawableTokens[_msgSender()] = true;
}
function depositTokenSale() public onlyOwner {
_tokenSale.transferFrom(_msgSender(), address(this), _capTokenSale);
isDepositedTokenSale = true;
}
/**
* @return the balance of an account.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
} | /**
* @title PostDeliveryCrowdsale
* @dev Crowdsale that locks tokens from withdrawal until it ends.
*/ | NatSpecMultiLine | withdrawTokens | function withdrawTokens() public withdrawable {
require(!withdrawableTokens[_msgSender()]);
uint256 amount = _balances[_msgSender()];
require(
amount > 0,
"PostDeliveryCrowdsale: beneficiary is not due any tokens"
);
_deliverTokens(_msgSender(), amount);
withdrawableTokens[_msgSender()] = true;
}
| /**
* @dev Withdraw tokens only after crowdsale ends.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
341,
730
]
} | 5,890 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | PostDeliveryCrowdsale | abstract contract PostDeliveryCrowdsale is TimedCrowdsale {
using SafeMath for uint256;
IERC20 private _tokenSale;
mapping(address => bool) public withdrawableTokens;
constructor(IERC20 _token) public {
_tokenSale = _token;
}
/**
* @dev Withdraw tokens only after crowdsale ends.
*/
function withdrawTokens() public withdrawable {
require(!withdrawableTokens[_msgSender()]);
uint256 amount = _balances[_msgSender()];
require(
amount > 0,
"PostDeliveryCrowdsale: beneficiary is not due any tokens"
);
_deliverTokens(_msgSender(), amount);
withdrawableTokens[_msgSender()] = true;
}
function depositTokenSale() public onlyOwner {
_tokenSale.transferFrom(_msgSender(), address(this), _capTokenSale);
isDepositedTokenSale = true;
}
/**
* @return the balance of an account.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
} | /**
* @title PostDeliveryCrowdsale
* @dev Crowdsale that locks tokens from withdrawal until it ends.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
| /**
* @return the balance of an account.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
971,
1086
]
} | 5,891 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | FinalizableCrowdsale | abstract contract FinalizableCrowdsale is PostDeliveryCrowdsale {
using SafeMath for uint256;
bool private _finalized;
event CrowdsaleFinalized();
constructor() internal {
_finalized = false;
}
/**
* @return true if the crowdsale is finalized, false otherwise.
*/
function finalized() public view returns (bool) {
return _finalized;
}
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() public {
require(!_finalized, "FinalizableCrowdsale: already finalized");
require(hasClosed(), "FinalizableCrowdsale: not closed");
_finalized = true;
_finalization();
emit CrowdsaleFinalized();
}
/**
* @dev Can be overridden to add finalization logic. The overriding function
* should call super._finalization() to ensure the chain of finalization is
* executed entirely.
*/
function _finalization() internal {
_finalizedTime = block.timestamp;
if (_currentSaleToken < _capTokenSale) {
_token.transfer(address(0), _capTokenSale.sub(_currentSaleToken));
}
}
} | /**
* @title FinalizableCrowdsale
* @dev Extension of TimedCrowdsale with a one-off finalization action, where one
* can do extra work after finishing.
*/ | NatSpecMultiLine | finalized | function finalized() public view returns (bool) {
return _finalized;
}
| /**
* @return true if the crowdsale is finalized, false otherwise.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
324,
413
]
} | 5,892 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | FinalizableCrowdsale | abstract contract FinalizableCrowdsale is PostDeliveryCrowdsale {
using SafeMath for uint256;
bool private _finalized;
event CrowdsaleFinalized();
constructor() internal {
_finalized = false;
}
/**
* @return true if the crowdsale is finalized, false otherwise.
*/
function finalized() public view returns (bool) {
return _finalized;
}
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() public {
require(!_finalized, "FinalizableCrowdsale: already finalized");
require(hasClosed(), "FinalizableCrowdsale: not closed");
_finalized = true;
_finalization();
emit CrowdsaleFinalized();
}
/**
* @dev Can be overridden to add finalization logic. The overriding function
* should call super._finalization() to ensure the chain of finalization is
* executed entirely.
*/
function _finalization() internal {
_finalizedTime = block.timestamp;
if (_currentSaleToken < _capTokenSale) {
_token.transfer(address(0), _capTokenSale.sub(_currentSaleToken));
}
}
} | /**
* @title FinalizableCrowdsale
* @dev Extension of TimedCrowdsale with a one-off finalization action, where one
* can do extra work after finishing.
*/ | NatSpecMultiLine | finalize | function finalize() public {
require(!_finalized, "FinalizableCrowdsale: already finalized");
require(hasClosed(), "FinalizableCrowdsale: not closed");
_finalized = true;
_finalization();
emit CrowdsaleFinalized();
}
| /**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
572,
847
]
} | 5,893 |
IBaseTokenPresale | @openzeppelin/contracts/token/ERC20/SafeERC20.sol | 0x74af7b62aca57ef5d049bff138cc66c58699e67d | Solidity | FinalizableCrowdsale | abstract contract FinalizableCrowdsale is PostDeliveryCrowdsale {
using SafeMath for uint256;
bool private _finalized;
event CrowdsaleFinalized();
constructor() internal {
_finalized = false;
}
/**
* @return true if the crowdsale is finalized, false otherwise.
*/
function finalized() public view returns (bool) {
return _finalized;
}
/**
* @dev Must be called after crowdsale ends, to do some extra finalization
* work. Calls the contract's finalization function.
*/
function finalize() public {
require(!_finalized, "FinalizableCrowdsale: already finalized");
require(hasClosed(), "FinalizableCrowdsale: not closed");
_finalized = true;
_finalization();
emit CrowdsaleFinalized();
}
/**
* @dev Can be overridden to add finalization logic. The overriding function
* should call super._finalization() to ensure the chain of finalization is
* executed entirely.
*/
function _finalization() internal {
_finalizedTime = block.timestamp;
if (_currentSaleToken < _capTokenSale) {
_token.transfer(address(0), _capTokenSale.sub(_currentSaleToken));
}
}
} | /**
* @title FinalizableCrowdsale
* @dev Extension of TimedCrowdsale with a one-off finalization action, where one
* can do extra work after finishing.
*/ | NatSpecMultiLine | _finalization | function _finalization() internal {
_finalizedTime = block.timestamp;
if (_currentSaleToken < _capTokenSale) {
_token.transfer(address(0), _capTokenSale.sub(_currentSaleToken));
}
}
| /**
* @dev Can be overridden to add finalization logic. The overriding function
* should call super._finalization() to ensure the chain of finalization is
* executed entirely.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | Unlicense | ipfs://c2b7db62fd51af0b4f7376a6510d4ef5d8ba3234336ff55455cb13ac6c300e2f | {
"func_code_index": [
1058,
1289
]
} | 5,894 |
EXODUS2 | Arrays.sol | 0x76e422de0ce8842ebe837bc7ab6984b4fff88055 | Solidity | Arrays | library Arrays {
/**
* @dev Upper bound search function which is kind of binary search algoritm. It searches sorted
* array to find index of the element value. If element is found then returns it's index otherwise
* it returns index of first element which is grater than searched value. If searched element is
* bigger than any array element function then returns first index after last element (i.e. all
* values inside the array are smaller than the target). Complexity O(log n).
* @param array The array sorted in ascending order.
* @param element The element's value to be find.
* @return The calculated index value. Returns 0 for empty array.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
if (array.length == 0) {
return 0;
}
uint256 low = 0;
uint256 high = array.length;
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds down (it does integer division with truncation).
if (array[mid] > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && array[low - 1] == element) {
return low - 1;
} else {
return low;
}
}
} | /**
* @title Arrays
* @dev Utility library of inline array functions
*/ | NatSpecMultiLine | findUpperBound | function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
if (array.length == 0) {
return 0;
}
uint256 low = 0;
uint256 high = array.length;
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds down (it does integer division with truncation).
if (array[mid] > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && array[low - 1] == element) {
return low - 1;
} else {
return low;
}
}
| /**
* @dev Upper bound search function which is kind of binary search algoritm. It searches sorted
* array to find index of the element value. If element is found then returns it's index otherwise
* it returns index of first element which is grater than searched value. If searched element is
* bigger than any array element function then returns first index after last element (i.e. all
* values inside the array are smaller than the target). Complexity O(log n).
* @param array The array sorted in ascending order.
* @param element The element's value to be find.
* @return The calculated index value. Returns 0 for empty array.
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6 | {
"func_code_index": [
700,
1596
]
} | 5,895 |
EXODUS2 | ERC165.sol | 0x76e422de0ce8842ebe837bc7ab6984b4fff88055 | Solidity | ERC165 | contract ERC165 is IERC165 {
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
/**
* @dev a mapping of interface id to whether or not it's supported
*/
mapping(bytes4 => bool) private _supportedInterfaces;
/**
* @dev A contract implementing SupportsInterfaceWithLookup
* implement ERC165 itself
*/
constructor () internal {
_registerInterface(_INTERFACE_ID_ERC165);
}
/**
* @dev implement supportsInterface(bytes4) using a lookup table
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
return _supportedInterfaces[interfaceId];
}
/**
* @dev internal method for registering an interface
*/
function _registerInterface(bytes4 interfaceId) internal {
require(interfaceId != 0xffffffff);
_supportedInterfaces[interfaceId] = true;
}
} | /**
* @title ERC165
* @author Matt Condon (@shrugs)
* @dev Implements ERC165 using a lookup table.
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 interfaceId) external view returns (bool) {
return _supportedInterfaces[interfaceId];
}
| /**
* @dev implement supportsInterface(bytes4) using a lookup table
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6 | {
"func_code_index": [
618,
755
]
} | 5,896 |
EXODUS2 | ERC165.sol | 0x76e422de0ce8842ebe837bc7ab6984b4fff88055 | Solidity | ERC165 | contract ERC165 is IERC165 {
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
/**
* @dev a mapping of interface id to whether or not it's supported
*/
mapping(bytes4 => bool) private _supportedInterfaces;
/**
* @dev A contract implementing SupportsInterfaceWithLookup
* implement ERC165 itself
*/
constructor () internal {
_registerInterface(_INTERFACE_ID_ERC165);
}
/**
* @dev implement supportsInterface(bytes4) using a lookup table
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
return _supportedInterfaces[interfaceId];
}
/**
* @dev internal method for registering an interface
*/
function _registerInterface(bytes4 interfaceId) internal {
require(interfaceId != 0xffffffff);
_supportedInterfaces[interfaceId] = true;
}
} | /**
* @title ERC165
* @author Matt Condon (@shrugs)
* @dev Implements ERC165 using a lookup table.
*/ | NatSpecMultiLine | _registerInterface | function _registerInterface(bytes4 interfaceId) internal {
require(interfaceId != 0xffffffff);
_supportedInterfaces[interfaceId] = true;
}
| /**
* @dev internal method for registering an interface
*/ | NatSpecMultiLine | v0.5.0+commit.1d4f565a | MIT | bzzr://4dc56cdfb144f689c22393e93357ad564cda72fe3ce195f496cd46ea489767e6 | {
"func_code_index": [
830,
992
]
} | 5,897 |
Fridgits | contracts/Fridgits.sol | 0x2112cc1f375f698ff0203243fe3eee7d5af969ae | Solidity | Fridgits | contract Fridgits is ERC721A, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.05 ether;
uint256 public maxSupply = 10000;
uint256 public maxMintAmount = 100;
uint256 public nftPerAddressLimit = 100;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721A(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
// internal
function _baseURI() internal view virtual override returns (string memory)
{
return baseURI;
}
// public
function mint(uint256 _mintAmount) public payable
{
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
_safeMint(msg.sender, _mintAmount);
}
function isWhitelisted(address _user) public view returns (bool)
{
for (uint i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if(revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
//only owner
function reveal() public onlyOwner {
revealed = true;
}
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
function withdraw() public payable onlyOwner {
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
}
} | _baseURI | function _baseURI() internal view virtual override returns (string memory)
{
return baseURI;
}
| // internal | LineComment | v0.8.7+commit.e28d00a7 | MIT | ipfs://4ce3c80292b1d2c0f518b760e06a8e46e92f8c5eb4d9450f122a9749f7204d1f | {
"func_code_index": [
867,
986
]
} | 5,898 |
||
Fridgits | contracts/Fridgits.sol | 0x2112cc1f375f698ff0203243fe3eee7d5af969ae | Solidity | Fridgits | contract Fridgits is ERC721A, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.05 ether;
uint256 public maxSupply = 10000;
uint256 public maxMintAmount = 100;
uint256 public nftPerAddressLimit = 100;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721A(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
// internal
function _baseURI() internal view virtual override returns (string memory)
{
return baseURI;
}
// public
function mint(uint256 _mintAmount) public payable
{
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
_safeMint(msg.sender, _mintAmount);
}
function isWhitelisted(address _user) public view returns (bool)
{
for (uint i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if(revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
//only owner
function reveal() public onlyOwner {
revealed = true;
}
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
function withdraw() public payable onlyOwner {
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
}
} | mint | function mint(uint256 _mintAmount) public payable
{
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
_safeMint(msg.sender, _mintAmount);
}
| // public | LineComment | v0.8.7+commit.e28d00a7 | MIT | ipfs://4ce3c80292b1d2c0f518b760e06a8e46e92f8c5eb4d9450f122a9749f7204d1f | {
"func_code_index": [
1004,
1911
]
} | 5,899 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.