comment stringlengths 11 2.99k | function_code stringlengths 165 3.15k | version stringclasses 80
values |
|---|---|---|
// Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above | function Coinware() {
balances[msg.sender] = 40000000000000000000000000; // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS)
totalSupply = 400000000000000000000... | 0.4.25 |
/// @dev Returns true if and only if the function is running in the constructor | function isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effecti... | 0.6.11 |
/**
* @dev claim private tokens from the contract balance.
* `amount` means how many tokens must be claimed.
* Can be used only by an owner or by any whitelisted person
*/ | function claimPrivateTokens(uint amount) public {
require(privateWhitelist[msg.sender] > 0, "Sender is not whitelisted");
require(privateWhitelist[msg.sender] >= amount, "Exceeded token amount");
require(currentPrivatePool >= amount, "Exceeded private pool");
currentPrivate... | 0.6.11 |
/**
* ICO constructor
* Define ICO details and contribution period
*/ | function Ico(uint256 _icoStart, uint256 _icoEnd, address[] _team, uint256 _tokensPerEth) public {
// require (_icoStart >= now);
require (_icoEnd >= _icoStart);
require (_tokensPerEth > 0);
owner = msg.sender;
icoStart = _icoStart;
icoEnd = _icoEnd;
tokensPerEth = _tokensPerEth;
... | 0.4.18 |
/**
*
* Function allowing investors to participate in the ICO.
* Specifying the beneficiary will change who will receive the tokens.
* Fund tokens will be distributed based on amount of ETH sent by investor, and calculated
* using tokensPerEth value.
*/ | function participate(address beneficiary) public payable {
require (beneficiary != address(0));
require (now >= icoStart && now <= icoEnd);
require (msg.value > 0);
uint256 ethAmount = msg.value;
uint256 numTokens = ethAmount.mul(tokensPerEth);
require(totalSupply.add(numTokens) <= har... | 0.4.18 |
/**
* Internal burn function, only callable by team
*
* @param _amount is the amount of tokens to burn.
*/ | function freeze(uint256 _amount) public onlySaleAddress returns (bool) {
reconcileDividend(msg.sender);
require(_amount <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_amount);
totalSupply = totalSupply.sub(... | 0.4.18 |
/**
* Calculate the divends for the current period given the AUM profit
*
* @param totalProfit is the amount of total profit in USD.
*/ | function reportProfit(int256 totalProfit, address saleAddress) public onlyTeam returns (bool) {
// first we new dividends if this period was profitable
if (totalProfit > 0) {
// We only care about 50% of this, as the rest is reinvested right away
uint256 profit = uint256(totalProfit).mul(tokenPr... | 0.4.18 |
/**
* Calculate the divends for the current period given the dividend
* amounts (USD * tokenPrecision).
*/ | function addNewDividends(uint256 profit) internal {
uint256 newAum = aum.add(profit); // 18 sig digits
tokenValue = newAum.mul(tokenPrecision).div(totalSupply); // 18 sig digits
uint256 totalDividends = profit.mul(tokenPrecision).div(tokenValue); // 18 sig digits
uint256 managementDividends = totalD... | 0.4.18 |
// Reconcile all outstanding dividends for an address
// into its balance. | function reconcileDividend(address _owner) internal {
var (owedDividend, dividends) = getOwedDividend(_owner);
for (uint i = 0; i < dividends.length; i++) {
if (dividends[i] > 0) {
Reconcile(_owner, lastDividend[_owner] + i, dividends[i]);
Transfer(0x0, _owner, dividends[i]);
... | 0.4.18 |
// free for gutter cats | function freeSale(uint256 catID) external nonReentrant {
require(tx.origin == msg.sender, "no...");
require(freeMintLive, "free mint not live");
require(_currentIndex + 1 <= maxNormalSupplyID, "out of stock");
require(!usedCatIDs[catID], "you can only mint once with this id");
... | 0.8.11 |
//sets the gang addresses | function setGutterAddresses(
address cats,
address rats,
address pigeons,
address dogs
) external onlyOwner {
gutterCatNFTAddress = cats; //0xEdB61f74B0d09B2558F1eeb79B247c1F363Ae452
gutterRatNFTAddress = rats; //0xD7B397eDad16ca8111CA4A3B832d0a5E3ae2438C
gutt... | 0.8.11 |
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
*/ | function isApprovedForAll(address owner, address operator)
public
view
override
returns (bool)
{
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(owner)) ... | 0.8.11 |
/**
* Withdraw processed allowance from a specific epoch
*/ | function withdraw(uint256 epoch) external {
require(epoch < currentEpoch(), "Can only withdraw from past epochs");
User storage user = userData[msg.sender];
uint256 amount = user.Exits[epoch];
delete user.Exits[epoch];
totalPerEpoch[epoch] -= amount; // TODO: WHen this goes to ... | 0.8.4 |
// All the following overrides are optional, if you want to modify default behavior.
// How the protection gets disabled. | function protectionChecker() internal view override returns(bool) {
return ProtectionSwitch_timestamp(1620086399); // Switch off protection on Monday, May 3, 2021 11:59:59 PM.
// return ProtectionSwitch_block(13000000); // Switch off protection on block 13000000.
//return ProtectionSwitch_manual... | 0.8.4 |
/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
* - the caller must have the `BURNER_ROLE`.
*/ | function burnFrom(address account, uint256 amount) public {
require(hasRole(BURNER_ROLE, _msgSender()), "Standard: must have burner role to burn");
uint256 currentAllowance = allowance(account, _msgSender());
require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
_... | 0.8.4 |
/**
* When given allowance, transfers a token from the "_from" to the "_to" of quantity "_quantity".
* Ensures that the recipient has received the correct quantity (ie no fees taken on transfer)
*
* @param _token ERC20 token to approve
* @param _from The account to transfer tokens from
... | function transferFrom(
IERC20 _token,
address _from,
address _to,
uint256 _quantity
)
internal
{
// Call specified ERC20 contract to transfer tokens (via proxy).
if (_quantity > 0) {
uint256 existingBalance = _token.balanceOf(_to);
... | 0.6.10 |
/**
* @dev Divides value a by value b (result is rounded down - positive numbers toward 0 and negative away from 0).
*/ | function divDown(int256 a, int256 b) internal pure returns (int256) {
require(b != 0, "Cant divide by 0");
require(a != MIN_INT_256 || b != -1, "Invalid input");
int256 result = a.div(b);
if (a ^ b < 0 && a % b != 0) {
result = result.sub(1);
}
retu... | 0.6.10 |
// deletes proposal signature data after successfully executing a multiSig function | function deleteProposal(Data storage self, bytes32 _whatFunction)
internal
{
//done for readability sake
bytes32 _whatProposal = whatProposal(_whatFunction);
address _whichAdmin;
//delete the admins votes & log. i know for loops are terrible. but we have to... | 0.4.24 |
// returns address of an admin who signed for any given function | function checkSigner (Data storage self, bytes32 _whatFunction, uint256 _signer)
internal
view
returns (address signer)
{
require(_signer > 0, "MSFun checkSigner failed - 0 not allowed");
bytes32 _whatProposal = whatProposal(_whatFunction);
return (self.proposa... | 0.4.24 |
/* Transfers tokens from your address to other */ | function transfer(address _to, uint256 _value) lockAffected returns (bool success) {
require(_to != 0x0 && _to != address(this));
balances[msg.sender] = balances[msg.sender].sub(_value); // Deduct senders balance
balances[_to] = balances[_to].add(_value); // Add recivers blaance
Transf... | 0.4.13 |
/** Current market price per pixel for this region if it is the first sale of this region
*/ | function calculateRegionInitialSalePixelPrice(address[16] _contracts, uint256 _regionId) view public returns (uint256) {
require(BdpDataStorage(BdpContracts.getBdpDataStorage(_contracts)).getRegionUpdatedAt(_regionId) > 0); // region exists
var purchasedPixels = countPurchasedPixels(_contracts);
var (area,,) =... | 0.4.19 |
/**
* @dev Tries to returns the value associated with `key`. O(1).
* Does not revert if `key` is not in the map.
*/ | function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
bytes32 value = map._values[key];
if (value == bytes32(0)) {
return (_contains(map, key), bytes32(0));
} else {
return (true, value);
}
} | 0.8.12 |
/** Setup is allowed one whithin one day after purchase
*/ | function calculateSetupAllowedUntil(address[16] _contracts, uint256 _regionId) view public returns (uint256) {
var (updatedAt, purchasedAt) = BdpDataStorage(BdpContracts.getBdpDataStorage(_contracts)).getRegionUpdatedAtPurchasedAt(_regionId);
if(updatedAt != purchasedAt) {
return 0;
} else {
return pur... | 0.4.19 |
/**
* @dev Internal function to add a token ID to the list of a given address
* @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/ | function addToken(address[16] _contracts, address _to, uint256 _tokenId) private {
var ownStorage = BdpOwnershipStorage(BdpContracts.getBdpOwnershipStorage(_contracts));
require(ownStorage.getTokenOwner(_tokenId) == address(0));
// Set token owner
ownStorage.setTokenOwner(_tokenId, _to);
// Add tok... | 0.4.19 |
/**
* @dev Remove token from ownedTokens list
* Note that this will handle single-element arrays. In that case, both ownedTokenIndex and lastOwnedTokenIndex are going to
* be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
* the lastOwnedTok... | function removeFromOwnedToken(BdpOwnershipStorage _ownStorage, address _from, uint256 _tokenId) private {
var ownedTokenIndex = _ownStorage.getOwnedTokensIndex(_tokenId);
var lastOwnedTokenIndex = _ownStorage.getOwnedTokensLength(_from).sub(1);
var lastOwnedToken = _ownStorage.getOwnedToken(_from, lastOwnedTok... | 0.4.19 |
// BdpControllerHelper | function () public {
address _impl = BdpContracts.getBdpControllerHelper(contracts);
require(_impl != address(0));
bytes memory data = msg.data;
assembly {
let result := delegatecall(gas, _impl, add(data, 0x20), mload(data), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndat... | 0.4.19 |
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/ | function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
... | 0.8.12 |
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/ | function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId); // internal owner
_beforeTokenTransfer(owner, address(0), tokenId);
// Clear approvals
_approve(address(0), tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[to... | 0.8.12 |
// Initializes contract | function WatermelonBlockToken(address _icoAddr, address _teamAddr, address _emergencyAddr) {
icoAddr = _icoAddr;
teamAddr = _teamAddr;
emergencyAddr = _emergencyAddr;
balances[icoAddr] = tokensICO;
balances[teamAddr] = teamReserve;
// seed investors
add... | 0.4.24 |
// Send some of your tokens to a given address | function transfer(address _to, uint _value) returns(bool) {
if (lockupParticipants[msg.sender].lockupAmount > 0) {
if (now < lockupParticipants[msg.sender].lockupTime) {
require(balances[msg.sender].sub(_value) >= lockupParticipants[msg.sender].lockupAmount);
}
... | 0.4.24 |
// A contract or person attempts to get the tokens of somebody else.
// This is only allowed if the token holder approved. | function transferFrom(address _from, address _to, uint _value) returns(bool) {
if (lockupParticipants[_from].lockupAmount > 0) {
if (now < lockupParticipants[_from].lockupTime) {
require(balances[_from].sub(_value) >= lockupParticipants[_from].lockupAmount);
}
... | 0.4.24 |
// >>> approve other rewards on dex
// function _approveDex() internal override { super._approveDex(); }
// >>> include other rewards
// function _migrateRewards(address _newStrategy) internal override { super._migrateRewards(_newStrategy); }
// >>> include all other rewards in eth besides _claimableBasicInETH()
// fun... | function _setPathTarget(uint _tokenId, uint _id) internal {
if (_id == 0) {
pathTarget[_tokenId] = usdt;
}
else if (_id == 1) {
pathTarget[_tokenId] = wbtc;
}
else {
pathTarget[_tokenId] = weth;
}
} | 0.6.12 |
/// @dev Sets the reference to the plugin contract.
/// @param _address - Address of plugin contract. | function addPlugin(address _address) external onlyOwner
{
PluginInterface candidateContract = PluginInterface(_address);
// verify that a contract is what we expect
require(candidateContract.isPluginInterface());
// Set the new contract address
plugins[_address] = c... | 0.4.26 |
/// @dev Remove plugin and calls onRemove to cleanup | function removePlugin(address _address) external onlyOwner
{
plugins[_address].onRemove();
delete plugins[_address];
uint256 kindex = 0;
while (kindex < pluginsArray.length)
{
if (address(pluginsArray[kindex]) == _address)
{
... | 0.4.26 |
/// @dev Common function to be used also in backend | function getSigner(
address _pluginAddress,
uint40 _signId,
uint40 _cutieId,
uint128 _value,
uint256 _parameter,
uint8 _v,
bytes32 _r,
bytes32 _s
)
public pure returns (address)
{
bytes32 msgHash = hashArguments(_pluginAddre... | 0.4.26 |
/// @dev Put a cutie up for plugin feature with signature.
/// Can be used for items equip, item sales and other features.
/// Signatures are generated by Operator role. | function runPluginSigned(
address _pluginAddress,
uint40 _signId,
uint40 _cutieId,
uint128 _value,
uint256 _parameter,
uint8 _v,
bytes32 _r,
bytes32 _s
)
external
// whenNotPaused
payable
{
require (isVa... | 0.4.26 |
/// @dev Put a cutie up for plugin feature. | function runPlugin(
address _pluginAddress,
uint40 _cutieId,
uint256 _parameter
) external payable
{
// If cutie is already on any auction or in adventure, this will throw
// because it will be owned by the other contract.
// If _cutieId is 0, then cutie i... | 0.4.26 |
// private sale (25% discount) | function presale(uint256 amount) public payable returns (bool) {
if (block.timestamp < startTimeStamp || block.timestamp >= endTimeStamp) {
return false;
}
uint256 presaleAmount = amount * 10 ** 18;
lvnContract.presale(msg.sender, presaleAmount);
address payable reci... | 0.8.0 |
/**
* @dev registers a name. UI will always display the last name you registered.
* but you will still own all previously registered names to use as affiliate
* links.
* - must pay a registration fee.
* - name must be unique
* - names will be converted to lowercase
* - name cannot start or end with a sp... | function registerNameXID(string _nameString, uint256 _affCode, bool _all)
isHuman()
public
payable
{
// make sure name fees paid
require (msg.value >= registrationFee_, "umm..... you have to pay the name fee");
// filter name + condition checks
... | 0.4.24 |
/**
* @dev players, if you registered a profile, before a game was released, or
* set the all bool to false when you registered, use this function to push
* your profile to a single game. also, if you've updated your name, you
* can use this to push your name to games of your choosing.
* -functionhash- 0x81... | function addMeToGame(uint256 _gameID)
isHuman()
public
{
require(_gameID <= gID_, "silly player, that game doesn't exist yet");
address _addr = msg.sender;
uint256 _pID = pIDxAddr_[_addr];
require(_pID != 0, "hey there buddy, you dont even have an account");
... | 0.4.24 |
/**
* @dev players, use this to push your player profile to all registered games.
* -functionhash- 0x0c6940ea
*/ | function addMeToAllGames()
isHuman()
public
{
address _addr = msg.sender;
uint256 _pID = pIDxAddr_[_addr];
require(_pID != 0, "hey there buddy, you dont even have an account");
uint256 _laff = plyr_[_pID].laff;
uint256 _totalNames = plyr_[_pID].names;
... | 0.4.24 |
/**
* @dev players use this to change back to one of your old names. tip, you'll
* still need to push that info to existing games.
* -functionhash- 0xb9291296
* @param _nameString the name you want to use
*/ | function useMyOldName(string _nameString)
isHuman()
public
{
// filter name, and get pID
bytes32 _name = _nameString.nameFilter();
uint256 _pID = pIDxAddr_[msg.sender];
// make sure they own the name
require(plyrNames_[_pID][_name] == true,... | 0.4.24 |
/**
* @dev Custom accessor to create a unique token
* @param _to address of diamond owner
* @param _issuer string the issuer agency name
* @param _report string the issuer agency unique Nr.
* @param _state diamond state, "sale" is the init state
* @param _cccc bytes32 cut, clarity, color, and carat class of diamo... | function mintDiamondTo(
address _to,
address _custodian,
bytes3 _issuer,
bytes16 _report,
bytes8 _state,
bytes20 _cccc,
uint24 _carat,
bytes32 _attributesHash,
bytes8 _currentHashingAlgorithm
)
public auth
returns(uint)
{
... | 0.5.11 |
/**
* @dev Gets the Diamond at a given _tokenId of all the diamonds in this contract
* Reverts if the _tokenId is greater or equal to the total number of diamonds
* @param _tokenId uint representing the index to be accessed of the diamonds list
* @return Returns all the relevant information about a specific diamond... | function getDiamondInfo(uint _tokenId)
public
view
ifExist(_tokenId)
returns (
address[2] memory ownerCustodian,
bytes32[6] memory attrs,
uint24 carat_
)
{
Diamond storage _diamond = diamonds[_tokenId];
bytes32 attributesHas... | 0.5.11 |
/// @notice Sell `amount` tokens to contract
/// @param amount amount of tokens to be sold | function sell(uint256 amount) public {
address myAddress = this;
require(myAddress.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
_transfer(msg.sender, this, amount); // makes the transfers
msg.sender.transfer(amount * sellPrice); ... | 0.4.26 |
// Separate function as it is used by derived contracts too | function _removeBid(uint bidId) internal {
Bid memory thisBid = bids[ bidId ];
bids[ thisBid.prev ].next = thisBid.next;
bids[ thisBid.next ].prev = thisBid.prev;
delete bids[ bidId ]; // clearning storage
delete contributors[ msg.sender ]; // clearning storage
// cannot delete from acco... | 0.4.24 |
// We are starting from TAIL and going upwards
// This is to simplify the case of increasing bids (can go upwards, cannot go lower)
// NOTE: blockSize gas limit in case of so many bids (wishful thinking) | function searchInsertionPoint(uint _contribution, uint _startSearch) view public returns (uint) {
require(_contribution > bids[_startSearch].value, "your contribution and _startSearch does not make sense, it will search in a wrong direction");
Bid memory lowerBid = bids[_startSearch];
Bid memory higher... | 0.4.24 |
/**
* @dev Inits the wallet by setting the owner and authorising a list of modules.
* @param _owner The owner.
* @param _modules The modules to authorise.
*/ | function init(address _owner, address[] _modules) external {
require(owner == address(0) && modules == 0, "BW: wallet already initialised");
require(_modules.length > 0, "BW: construction requires at least 1 module");
owner = _owner;
modules = _modules.length;
for(uint256 i ... | 0.4.24 |
/**
* @dev Enables/Disables a module.
* @param _module The target module.
* @param _value Set to true to authorise the module.
*/ | function authoriseModule(address _module, bool _value) external moduleOnly {
if (authorised[_module] != _value) {
if(_value == true) {
modules += 1;
authorised[_module] = true;
Module(_module).init(this);
}
else {
... | 0.4.24 |
/**
* Initializes this wrapper contract
*
* Should set cards, proto, quality, and uniswap exchange
*
* Should fail if already initialized by checking if cardWrapperFatory is set
*
*/ | function init(ICards _cards, uint16 _proto, uint8 _quality, IUniswapExchange _uniswapExchange) public {
require(address(cardWrapperFactory) == address(0x0), 'CardWrapper:Already initialized');
cardWrapperFactory = CardERC20WrapperFactory(msg.sender);
uniswapExchange = _uniswapExchange;
... | 0.5.12 |
// public minting | function mint(uint256 _mintAmount) public payable nonReentrant{
uint256 s = totalSupply();
require(status, "Off" );
require(_mintAmount > 0, "0" );
require(_mintAmount <= maxMint, "Too many" );
require(s + _mintAmount <= maxSupply, "Max" );
require(msg.value >= cost * _mintAmount);
for (uint256 i = 0; i <... | 0.8.11 |
// admin minting | function adminMint(address[] calldata recipient) external onlyOwner{
uint256 s = totalSupply();
require(s + recipient.length <= maxSupply, "Too many" );
for(uint i = 0; i < recipient.length; ++i){
_safeMint(recipient[i], s++, "" );
}
delete s;
} | 0.8.11 |
// Allows the developer to set the crowdsale and token addresses. | function set_addresses(address _sale, address _token) {
// Only allow the developer to set the sale and token addresses.
require(msg.sender == developer);
// Only allow setting the addresses once.
// Set the crowdsale and token addresses.
sale = _sale;
token = ERC20(_token);
} | 0.4.13 |
/// @inheritdoc IERC721BulkTransfer | function transfer(
address collection,
address recipient,
uint256[] calldata tokenIds
) external {
require(tokenIds.length > 0, "Invalid token ids amount");
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
IERC72... | 0.8.9 |
/**
* @dev Executes a relayed transaction.
* @param _wallet The target wallet.
* @param _data The data for the relayed transaction
* @param _nonce The nonce used to prevent replay attacks.
* @param _signatures The signatures as a concatenated byte array.
* @param _gasPrice The gas price to use for the gas r... | function execute(
BaseWallet _wallet,
bytes _data,
uint256 _nonce,
bytes _signatures,
uint256 _gasPrice,
uint256 _gasLimit
)
external
returns (bool success)
{
uint startGas = gasleft();
bytes32 signHash = getSignHash(... | 0.4.24 |
/**
* @dev Generates the signed hash of a relayed transaction according to ERC 1077.
* @param _from The starting address for the relayed transaction (should be the module)
* @param _to The destination address for the relayed transaction (should be the wallet)
* @param _value The value for the relayed transactio... | function getSignHash(
address _from,
address _to,
uint256 _value,
bytes _data,
uint256 _nonce,
uint256 _gasPrice,
uint256 _gasLimit
)
internal
pure
returns (bytes32)
{
return keccak256(
abi.en... | 0.4.24 |
/**
* @dev Checks that a nonce has the correct format and is valid.
* It must be constructed as nonce = {block number}{timestamp} where each component is 16 bytes.
* @param _wallet The target wallet.
* @param _nonce The nonce
*/ | function checkAndUpdateNonce(BaseWallet _wallet, uint256 _nonce) internal returns (bool) {
if(_nonce <= relayer[_wallet].nonce) {
return false;
}
uint256 nonceBlock = (_nonce & 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000) >> 128;
if(nonceBlock >... | 0.4.24 |
/**
* @dev Recovers the signer at a given position from a list of concatenated signatures.
* @param _signedHash The signed hash
* @param _signatures The concatenated signatures.
* @param _index The index of the signature to recover.
*/ | function recoverSigner(bytes32 _signedHash, bytes _signatures, uint _index) internal pure returns (address) {
uint8 v;
bytes32 r;
bytes32 s;
// we jump 32 (0x20) as the first slot of bytes contains the length
// we jump 65 (0x41) per signature
// for v we load 32 by... | 0.4.24 |
/**
* @dev Refunds the gas used to the Relayer.
* For security reasons the default behavior is to not refund calls with 0 or 1 signatures.
* @param _wallet The target wallet.
* @param _gasUsed The gas used.
* @param _gasPrice The gas price for the refund.
* @param _gasLimit The gas limit for the refund.
... | function refund(BaseWallet _wallet, uint _gasUsed, uint _gasPrice, uint _gasLimit, uint _signatures, address _relayer) internal {
uint256 amount = 29292 + _gasUsed; // 21000 (transaction) + 7620 (execution of refund) + 672 to log the event + _gasUsed
// only refund if gas price not null, more than 1 s... | 0.4.24 |
/**
* @dev Returns false if the refund is expected to fail.
* @param _wallet The target wallet.
* @param _gasUsed The expected gas used.
* @param _gasPrice The expected gas price for the refund.
*/ | function verifyRefund(BaseWallet _wallet, uint _gasUsed, uint _gasPrice, uint _signatures) internal view returns (bool) {
if(_gasPrice > 0
&& _signatures > 1
&& (address(_wallet).balance < _gasUsed * _gasPrice || _wallet.authorised(this) == false)) {
return false;
... | 0.4.24 |
/**
* @dev Checks that the wallet address provided as the first parameter of the relayed data is the same
* as the wallet passed as the input of the execute() method.
@return false if the addresses are different.
*/ | function verifyData(address _wallet, bytes _data) private pure returns (bool) {
require(_data.length >= 36, "RM: Invalid dataWallet");
address dataWallet;
// solium-disable-next-line security/no-inline-assembly
assembly {
//_data = {length:32}{sig:4}{_wallet:32}{...}
... | 0.4.24 |
/**
* @dev Lets an authorised module revoke a guardian from a wallet.
* @param _wallet The target wallet.
* @param _guardian The guardian to revoke.
*/ | function revokeGuardian(BaseWallet _wallet, address _guardian) external onlyModule(_wallet) {
GuardianStorageConfig storage config = configs[_wallet];
address lastGuardian = config.guardians[config.guardians.length - 1];
if (_guardian != lastGuardian) {
uint128 targetIndex = conf... | 0.4.24 |
/**
* @dev Gets the list of guaridans for a wallet.
* @param _wallet The target wallet.
* @return the list of guardians.
*/ | function getGuardians(BaseWallet _wallet) external view returns (address[]) {
GuardianStorageConfig storage config = configs[_wallet];
address[] memory guardians = new address[](config.guardians.length);
for (uint256 i = 0; i < config.guardians.length; i++) {
guardians[i] = confi... | 0.4.24 |
/**
* @dev Checks if an address is an account guardian or an account authorised to sign on behalf of a smart-contract guardian
* given a list of guardians.
* @param _guardians the list of guardians
* @param _guardian the address to test
* @return true and the list of guardians minus the found guardian upon su... | function isGuardian(address[] _guardians, address _guardian) internal view returns (bool, address[]) {
if(_guardians.length == 0 || _guardian == address(0)) {
return (false, _guardians);
}
bool isFound = false;
address[] memory updatedGuardians = new address[](_guardians... | 0.4.24 |
/**
* @dev Checks if an address is the owner of a guardian contract.
* The method does not revert if the call to the owner() method consumes more then 5000 gas.
* @param _guardian The guardian contract
* @param _owner The owner to verify.
*/ | function isGuardianOwner(address _guardian, address _owner) internal view returns (bool) {
address owner = address(0);
bytes4 sig = bytes4(keccak256("owner()"));
// solium-disable-next-line security/no-inline-assembly
assembly {
let ptr := mload(0x40)
mstore... | 0.4.24 |
/**
* @dev transfers tokens (ETH or ERC20) from a wallet.
* @param _wallet The target wallet.
* @param _token The address of the token to transfer.
* @param _to The destination address
* @param _amount The amoutnof token to transfer
* @param _data The data for the transaction (only for ETH transfers)
*/ | function transferToken(
BaseWallet _wallet,
address _token,
address _to,
uint256 _amount,
bytes _data
)
external
onlyExecute
onlyWhenUnlocked(_wallet)
{
// eth transfer to whitelist
if(_token == ETH_TOKEN) {
... | 0.4.24 |
// *************** Implementation of RelayerModule methods ********************* // | function validateSignatures(BaseWallet _wallet, bytes _data, bytes32 _signHash, bytes _signatures) internal view returns (bool) {
address lastSigner = address(0);
address[] memory guardians = guardianStorage.getGuardians(_wallet);
bool isGuardian = false;
for (uint8 i = 0; i < _signa... | 0.4.24 |
/**
* @dev Function to mint tokens, and lock some of them with a release time
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @param _lockedAmount The amount of tokens to be locked.
* @param _releaseTime The timestamp about to release, which could... | function mintWithLock(address _to, uint256 _amount, uint256 _lockedAmount, uint256 _releaseTime) external returns (bool) {
require(mintAgents[msg.sender] && totalSupply_.add(_amount) <= cap);
require(_amount >= _lockedAmount);
totalSupply_ = totalSupply_.add(_amount);
balances[_to]... | 0.4.23 |
// Update reward variables of the given pool to be up-to-date.
//function mint(uint256 amount) public onlyOwner{
// bacon.mint(devaddr, amount);
//}
// Update reward variables of the given pool to be up-to-date. | function updatePool(uint256 _pid) public {
doHalvingCheck(false);
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpSupply = pool.lpToken.balanceOf(address(this));
if (lpSupply == 0) {
pool.last... | 0.6.12 |
// Deposit LP tokens to MasterChef for BACON allocation. | function deposit(uint256 _pid, uint256 _amount) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
updatePool(_pid);
if (user.amount > 0) {
uint256 pending = user.amount.mul(pool.accBaconPerShare).div(1e12).sub(user.rewardDebt... | 0.6.12 |
// swaps any combination of ERC-20/721/1155
// User needs to approve assets before invoking swap | function multiAssetSwap(
ERC20Details memory inputERC20s,
ERC721Details[] memory inputERC721s,
ERC1155Details[] memory inputERC1155s,
MarketRegistry.BuyDetails[] memory buyDetails,
ExchangeRegistry.SwapDetails[] memory swapDetails,
address[] memory addrs // [changeI... | 0.8.0 |
// Emergency function: In case any ERC1155 tokens get stuck in the contract unintentionally
// Only owner can retrieve the asset balance to a recipient address | function rescueERC1155(address asset, uint256[] calldata ids, uint256[] calldata amounts, address recipient) onlyOwner external {
for (uint256 i = 0; i < ids.length; i++) {
IERC1155(asset).safeTransferFrom(address(this), recipient, ids[i], amounts[i], "");
}
} | 0.8.0 |
// user buy PASS from contract with specific erc20 tokens | function mint() public nonReentrant returns (uint256 tokenId) {
require(address(erc20) != address(0), "FixPrice: erc20 address is null.");
require((tokenIdTracker.current() <= maxSupply), "exceeds maximum supply");
tokenId = tokenIdTracker.current(); // accumulate the token id
IERC20Upgradeable(erc20)... | 0.8.4 |
// withdraw erc20 tokens from contract
// anyone can withdraw reserve of erc20 tokens to receivingAddress | function withdraw() public nonReentrant {
if (address(erc20) == address(0)) {
emit Withdraw(receivingAddress, _getBalance());
(bool success, ) = payable(receivingAddress).call{value: _getBalance()}(
""
);
require(success, "Failed to send Ether");
} else {
uint256 amount = ... | 0.8.4 |
// -------------------------------------------------------- INTERNAL -------------------------------------------------------------------- | function _requireValidPermit(
address signer,
address spender,
uint256 id,
uint256 deadline,
uint256 nonce,
bytes memory sig
) internal view {
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
_DOMAIN_SEPARAT... | 0.8.9 |
/// @dev Return the DOMAIN_SEPARATOR. | function _DOMAIN_SEPARATOR() internal view returns (bytes32) {
uint256 chainId;
//solhint-disable-next-line no-inline-assembly
assembly {
chainId := chainid()
}
// in case a fork happen, to support the chain that had to change its chainId,, we compute the domain oper... | 0.8.9 |
/* Batch token transfer. Used by contract creator to distribute initial tokens to holders */ | function batchTransfer(address[] _recipients, uint[] _values) onlyOwner returns (bool) {
require( _recipients.length > 0 && _recipients.length == _values.length);
uint total = 0;
for(uint i = 0; i < _values.length; i++){
total = total.add(_values[i]);
}
requir... | 0.4.18 |
//*** Payable ***// | function() payable public {
require(msg.value>0);
require(msg.sender != 0x0);
uint256 weiAmount;
uint256 tokens;
wallet=owner;
if(isPreSale()){
wallet=preSaleAddress;
weiAmount=6000;
}
else if(isIco()){... | 0.4.19 |
//*** Transfer From ***// | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
if(transfersEnabled){
// Check if the sender has enough
require(balanceOf[_from] >= _value);
// Check allowed
require(_value <= allowed[_from][msg.sender]);
// Subtract from th... | 0.4.19 |
// @notice tokensale
// @param recipient The address of the recipient
// @return the transaction address and send the event as Transfer | function tokensale(address recipient) public payable {
require(recipient != 0x0);
uint256 weiAmount = msg.value;
uint tokens = weiAmount.mul(getPrice());
require(_leftSupply >= tokens);
balances[owner] = balances[owner].sub(tokens);
balances[recipient] = balan... | 0.4.11 |
// Token distribution to founder, develoment team, partners, charity, and bounty | function sendBPESOToken(address to, uint256 value) public onlyOwner {
require (
to != 0x0 && value > 0 && _leftSupply >= value
);
balances[owner] = balances[owner].sub(value);
balances[to] = balances[to].add(value);
_leftSupply = _leftSupply.sub(value);
... | 0.4.11 |
// @notice send `value` token to `to` from `from`
// @param from The address of the sender
// @param to The address of the recipient
// @param value The amount of token to be transferred
// @return the transaction address and send the event as Transfer | function transferFrom(address from, address to, uint256 value) public {
require (
allowed[from][msg.sender] >= value && balances[from] >= value && value > 0
);
balances[from] = balances[from].sub(value);
balances[to] = balances[to].add(value);
allowed[from][msg.... | 0.4.11 |
/**
* @dev Joins and plays game.
* @param _id Game id to join.
* @param _referral Address for referral.
* TESTED
*/ | function joinAndPlayGame(uint256 _id, address _referral) external payable onlyNotCreator(_id) onlyAllowedToPlay {
Game storage game = games[_id];
require(game.creator != address(0), "No game with such id");
require(game.winner == address(0), "Game has winner");
require(game.bet == msg.value, "Wrong ... | 0.6.0 |
/**
* @dev Withdraws prize for won game.
* @param _maxLoop max loop.
* TESTED
*/ | function withdrawGamePrizes(uint256 _maxLoop) external {
require(_maxLoop > 0, "_maxLoop == 0");
uint256[] storage pendingGames = gamesWithPendingPrizeWithdrawalForAddress[msg.sender];
require(pendingGames.length > 0, "no pending");
require(_maxLoop <= pendingGames.length, "wrong _maxLoop");
... | 0.6.0 |
/**
* GameRaffle
* TESTED
*/ | function withdrawRafflePrizes() external override {
require(rafflePrizePendingForAddress[msg.sender] > 0, "No raffle prize");
uint256 prize = rafflePrizePendingForAddress[msg.sender];
delete rafflePrizePendingForAddress[msg.sender];
addressPrizeTotal[msg.sender] = addressPrizeTotal[msg.sende... | 0.6.0 |
/**
* @dev Adds game idx to the beginning of topGames.
* @param _id Game idx to be added.
* TESTED
*/ | function addTopGame(uint256 _id) external payable onlyCreator(_id) {
require(msg.value == minBet, "Wrong fee");
require(topGames[0] != _id, "Top in TopGames");
uint256[5] memory topGamesTmp = [_id, 0, 0, 0, 0];
bool isIdPresent;
for (uint8 i = 0; i < 4; i ++) {
if (topGames[i] ... | 0.6.0 |
/**
* @dev Removes game idx from topGames.
* @param _id Game idx to be removed.
* TESTED
*/ | function removeTopGame(uint256 _id) private {
uint256[5] memory tmpArr;
bool found;
for(uint256 i = 0; i < 5; i ++) {
if(topGames[i] == _id) {
found = true;
} else {
if (found) {
tmpArr[i-1] = topGames[i];
} else {
tmpArr[i] = topGames[... | 0.6.0 |
/// @notice give the list of owners for the list of ids given.
/// @param ids The list if token ids to check.
/// @return addresses The list of addresses, corresponding to the list of ids. | function owners(uint256[] calldata ids) external view returns (address[] memory addresses) {
addresses = new address[](ids.length);
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
addresses[i] = address(uint160(_owners[id]));
}
} | 0.8.9 |
/// @notice mint one of bleep if not already minted. Can only be called by `minter`.
/// @param id bleep id which represent a pair of (note, instrument).
/// @param to address that will receive the Bleep. | function mint(uint16 id, address to) external {
require(msg.sender == minter, "ONLY_MINTER_ALLOWED");
require(id < 1024, "INVALID_BLEEP");
require(to != address(0), "NOT_TO_ZEROADDRESS");
require(to != address(this), "NOT_TO_THIS");
address owner = _ownerOf(id);
require(... | 0.8.9 |
/// @notice mint multiple bleeps if not already minted. Can only be called by `minter`.
/// @param ids list of bleep id which represent each a pair of (note, instrument).
/// @param to address that will receive the Bleeps. | function multiMint(uint16[] calldata ids, address to) external {
require(msg.sender == minter, "ONLY_MINTER_ALLOWED");
require(to != address(0), "NOT_TO_ZEROADDRESS");
require(to != address(this), "NOT_TO_THIS");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i]... | 0.8.9 |
//management functions
//add lenders for the strategy to choose between
// only governance to stop strategist adding dodgy lender | function addLender(address a) public onlyGovernance {
IGenericLender n = IGenericLender(a);
require(n.strategy() == address(this), "Undocked Lender");
for (uint256 i = 0; i < lenders.length; i++) {
require(a != address(lenders[i]), "Already Added");
}
lenders.... | 0.6.12 |
//force removes the lender even if it still has a balance | function _removeLender(address a, bool force) internal {
for (uint256 i = 0; i < lenders.length; i++) {
if (a == address(lenders[i])) {
bool allWithdrawn = lenders[i].withdrawAll();
if (!force) {
require(allWithdrawn, "WITHDRAW FAILED");
... | 0.6.12 |
//Returns the status of all lenders attached the strategy | function lendStatuses() public view returns (lendStatus[] memory) {
lendStatus[] memory statuses = new lendStatus[](lenders.length);
for (uint256 i = 0; i < lenders.length; i++) {
lendStatus memory s;
s.name = lenders[i].lenderName();
s.add = address(lenders[i]);... | 0.6.12 |
//the weighted apr of all lenders. sum(nav * apr)/totalNav | function estimatedAPR() public view returns (uint256) {
uint256 bal = estimatedTotalAssets();
if (bal == 0) {
return 0;
}
uint256 weightedAPR = 0;
for (uint256 i = 0; i < lenders.length; i++) {
weightedAPR = weightedAPR.add(lenders[i].weightedAp... | 0.6.12 |
//Estimates the impact on APR if we add more money. It does not take into account adjusting position | function _estimateDebtLimitIncrease(uint256 change) internal view returns (uint256) {
uint256 highestAPR = 0;
uint256 aprChoice = 0;
uint256 assets = 0;
for (uint256 i = 0; i < lenders.length; i++) {
uint256 apr = lenders[i].aprAfterDeposit(change);
if (ap... | 0.6.12 |
//Estimates debt limit decrease. It is not accurate and should only be used for very broad decision making | function _estimateDebtLimitDecrease(uint256 change) internal view returns (uint256) {
uint256 lowestApr = uint256(-1);
uint256 aprChoice = 0;
for (uint256 i = 0; i < lenders.length; i++) {
uint256 apr = lenders[i].aprAfterDeposit(change);
if (apr < lowestApr) {
... | 0.6.12 |
//gives estiomate of future APR with a change of debt limit. Useful for governance to decide debt limits | function estimatedFutureAPR(uint256 newDebtLimit) public view returns (uint256) {
uint256 oldDebtLimit = vault.strategies(address(this)).totalDebt;
uint256 change;
if (oldDebtLimit < newDebtLimit) {
change = newDebtLimit - oldDebtLimit;
return _estimateDebtLimitIncre... | 0.6.12 |
/*
* Key logic.
* The algorithm moves assets from lowest return to highest
* like a very slow idiots bubble sort
* we ignore debt outstanding for an easy life
*/ | function adjustPosition(uint256 _debtOutstanding) internal override {
_debtOutstanding; //ignored. we handle it in prepare return
//emergency exit is dealt with at beginning of harvest
if (emergencyExit) {
return;
}
//we just keep all money in want if we dont ... | 0.6.12 |
//share must add up to 1000. 500 means 50% etc | function manualAllocation(lenderRatio[] memory _newPositions) public onlyAuthorized {
uint256 share = 0;
for (uint256 i = 0; i < lenders.length; i++) {
lenders[i].withdrawAll();
}
uint256 assets = want.balanceOf(address(this));
for (uint256 i = 0; i < _new... | 0.6.12 |
//cycle through withdrawing from worst rate first | function _withdrawSome(uint256 _amount) internal returns (uint256 amountWithdrawn) {
if (lenders.length == 0) {
return 0;
}
//dont withdraw dust
if (_amount < withdrawalThreshold) {
return 0;
}
amountWithdrawn = 0;
//most situa... | 0.6.12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.