comment
stringlengths
11
2.99k
function_code
stringlengths
165
3.15k
version
stringclasses
80 values
// 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] == tokenAddre...
0.4.25
//??? 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++) { ...
0.4.25
//??? 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) ...
0.4.25
// 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 ...
0.4.25
// 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); ...
0.4.25
// 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) || ...
0.4.25
/** * 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; }
0.4.25
/** * Creates the contract and sets the owners * @param owners_dot_recipient - array of 16 owner records (MultiOwnable.Owner.recipient fields) * @param owners_dot_share - array of 16 owner records (MultiOwnable.Owner.share fields) */
function BlindCroupierTokenDistribution (address[16] owners_dot_recipient, uint[16] owners_dot_share) MultiOwnable(owners_dot_recipient, owners_dot_share) { MultiOwnable.Owner[16] memory owners; for(uint __recipient_iterator__ = 0; __recipient_iterator__ < owners_dot_recipient.length;__recipient_iterator__++) ...
0.4.15
/** * @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, ...
0.6.12
/** * @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]...
0.6.12
/** * @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) ...
0.6.12
/** * @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); ...
0.6.12
/** * @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();...
0.6.12
/** * @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)); ...
0.6.12
/** * @notice Transfer `_amount` from `msg.sender.address()` to `_to`. * * @param _to Address that will receive. * @param _amount Amount to be transferred. */
function transfer(address _to, uint256 _amount) returns (bool success) { assert(allowTransactions); assert(!frozenAccount[msg.sender]); assert(balanceOf[msg.sender] >= _amount); assert(balanceOf[_to] + _amount >= balanceOf[_to]); activateAccount(msg.sender); activateAccount(_to); bala...
0.3.6
/** * @notice Transfer `_amount` from `_from` to `_to`. * * @param _from Origin address * @param _to Address that will receive * @param _amount Amount to be transferred. * @return result of the method call */
function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) { assert(allowTransactions); assert(!frozenAccount[msg.sender]); assert(!frozenAccount[_from]); assert(balanceOf[_from] >= _amount); assert(balanceOf[_to] + _amount >= balanceOf[_to]); assert(_amount ...
0.3.6
/** * @notice Approve spender `_spender` to transfer `_amount` from `msg.sender.address()` * * @param _spender Address that receives the cheque * @param _amount Amount on the cheque * @param _extraData Consequential contract to be executed by spender in same transcation. * @return result of the method call ...
function approveAndCall(address _spender, uint256 _amount, bytes _extraData) returns (bool success) { assert(allowTransactions); assert(!frozenAccount[msg.sender]); allowance[msg.sender][_spender] = _amount; activateAccount(msg.sender); activateAccount(_spender); activateAllowanceRecord(ms...
0.3.6
/// @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 _optima...
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, localMa...
0.6.6
/// @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...
0.6.6
/// @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 : e...
0.6.6
/** * @notice 'Returns the fee for a transfer from `from` to `to` on an amount `amount`. * * Fee's consist of a possible * - import fee on transfers to an address * - export fee on transfers from an address * DVIP ownership on an address * - reduces fee on a transfer from this address to an impor...
function feeFor(address from, address to, uint256 amount) constant external returns (uint256 value) { uint256 fee = exportFee[from] + importFee[to]; if (fee == 0) return 0; uint256 amountHeld; bool discounted = true; uint256 oneDVIPUnit; if (exportFee[from] == 0 && balanceOf[from] != 0 && ...
0.3.6
/** * @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); _...
0.6.12
/** * @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, w...
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(...
0.6.12
/** * @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...
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); ...
0.5.0
/** * @notice Query if a contract supports ERC165 * @param account The address of the contract to query for support of ERC165 * @return true if the contract at account implements ERC165 */
function _supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, _INTERFACE_ID_ERC165) && ...
0.5.0
/** * @notice Query if a contract implements interfaces, also checks support of ERC165 * @param account The address of the contract to query for support of an interface * @param interfaceIds A list of interface identifiers, as specified in ERC-165 * @return true if the contract at account indicates support all inte...
function _supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!_supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i ...
0.5.0
/** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interfa...
function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { // success determines whether the staticcall succeeded and result determines // whether the contract at account indicates support of _interfaceId (bool success, bool result) = _callERC165Supports...
0.5.0
/** * @notice Calls the function with selector 0x01ffc9a7 (ERC165) and suppresses throw * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return success true if the STATICCALL succeeded, false otherwise * @ret...
function _callERC165SupportsInterface(address account, bytes4 interfaceId) private view returns (bool success, bool result) { bytes memory encodedParams = abi.encodeWithSelector(_INTERFACE_ID_ERC165, interfaceId); // solhint-disable-next-line no-inline-assembly assem...
0.5.0
/** * @dev Appends a byte array to the end of the buffer. Resizes if doing so * would exceed the capacity of the buffer. * @param buf The buffer to append to. * @param data The data to append. * @return The original buffer. */
function append(buffer memory buf, bytes data) internal pure returns(buffer memory) { if(data.length + buf.buf.length > buf.capacity) { resize(buf, max(buf.capacity, data.length) * 2); } uint dest; uint src; uint len = data.length; assembly { ...
0.4.24
// "addresses" may not be longer than 256
function arrayContainsAddress256(address[] addresses, address value) internal pure returns (bool) { for (uint8 i = 0; i < addresses.length; i++) { if (addresses[i] == value) { return true; } } return false; }
0.4.16
// creates clone using minimal proxy
function createClone(bytes32 _salt, address _target) internal returns (address _result) { bytes20 _targetBytes = bytes20(_target); assembly { let clone := mload(0x40) mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(c...
0.7.3
// parseInt(parseFloat*10^_b)
function parseInt(string _a, uint _b) internal pure returns (uint) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i=0; i<bresult.length; i++){ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){ if (decimals){ ...
0.4.24
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) { uint minLength = length + toOffset; // Buffer too small require(to.length >= minLength); // Should be a better way? // NOTE: the offset 32 is added to skip the `s...
0.4.24
// the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license // Duplicate Solidity's ecrecover, but catching the CALL return value
function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) { // We do our own memory management here. Solidity uses memory offset // 0x40 to store the current end of memory. We write past it (as // writes are memory extensions), but don't update the...
0.4.24
/** * Hook on `transfer` and call `Withdraw.beforeBalanceChange` function. */
function transfer(address _to, uint256 _value) public returns (bool) { /** * Validates the destination is not 0 address. */ require(_to != address(0), "this is illegal address"); require(_value != 0, "illegal transfer value"); /** * Calls Withdraw contract via Allocator contract. * Passing...
0.5.17
/** * Hook on `transferFrom` and call `Withdraw.beforeBalanceChange` function. */
function transferFrom( address _from, address _to, uint256 _value ) public returns (bool) { /** * Validates the source and destination is not 0 address. */ require(_from != address(0), "this is illegal address"); require(_to != address(0), "this is illegal address"); require(_value != 0, ...
0.5.17
/** * Transfers the staking amount to the original owner. */
function withdraw(address _sender, uint256 _value) external { /** * Validates the sender is Lockup contract. */ require(msg.sender == config().lockup(), "this is illegal address"); /** * Transfers the passed amount to the original owner. */ ERC20 devToken = ERC20(config().token()); bool...
0.5.17
/** * Sets EToken2 address, assigns symbol and name. * * Can be set only once. * * @param _etoken2 EToken2 contract address. * @param _symbol assigned symbol. * @param _name assigned name. * * @return success. */
function init(EToken2Interface _etoken2, string _symbol, string _name) returns(bool) { if (address(etoken2) != 0x0) { return false; } etoken2 = _etoken2; etoken2Symbol = _bytes32(_symbol); name = _name; symbol = _symbol; return true; }
0.4.15
/** * Propose next asset implementation contract address. * * Can only be called by current asset owner. * * Note: freeze-time should not be applied for the initial setup. * * @param _newVersion asset implementation contract address. * * @return success. */
function proposeUpgrade(address _newVersion) onlyAssetOwner() returns(bool) { // Should not already be in the upgrading process. if (pendingVersion != 0x0) { return false; } // New version address should be other than 0x0. if (_newVersion == 0x0) { ...
0.4.15
/** * Finalize an upgrade process setting new asset implementation contract address. * * Can only be called after an upgrade freeze-time. * * @return success. */
function commitUpgrade() returns(bool) { if (pendingVersion == 0x0) { return false; } if (pendingVersionTimestamp + UPGRADE_FREEZE_TIME > now) { return false; } latestVersion = pendingVersion; delete pendingVersion; delete pendingV...
0.4.15
/* * @dev Returns a newly allocated string containing the concatenation of * `self` and `other`. * @param self The first slice to concatenate. * @param other The second slice to concatenate. * @return The concatenation of the two strings. */
function concat(slice memory self, slice memory other) internal pure returns (string memory) { string memory ret = new string(self._len + other._len); uint retptr; assembly { retptr := add(ret, 32) } memcpy(retptr, self._ptr, self._len); memcpy(retptr + self._...
0.5.0
// SCALE-encode payload
function encodeCall( address _token, address _sender, bytes32 _recipient, uint256 _amount ) private pure returns (bytes memory) { return abi.encodePacked( MINT_CALL, _token, _sender, byte(0x00), // En...
0.7.6
// Decodes a SCALE encoded uint256 by converting bytes (bid endian) to little endian format
function decodeUint256(bytes memory data) public pure returns (uint256) { uint256 number; for (uint256 i = data.length; i > 0; i--) { number = number + uint256(uint8(data[i - 1])) * (2**(8 * (i - 1))); } return number; }
0.7.6
// Sources: // * https://ethereum.stackexchange.com/questions/15350/how-to-convert-an-bytes-to-address-in-solidity/50528 // * https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
function reverse256(uint256 input) internal pure returns (uint256 v) { v = input; // swap bytes v = ((v & 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >> 8) | ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8); // swap 2-b...
0.7.6
// ========== Claiming ==========
function burnForPhysical(uint16[] calldata _burnTokenIds, uint16 editionId, uint16 editionTokenId, bool claimNFT) public whenNotPaused nonReentrant { require(editionId <= numBurnEditions, "Edition not found"); require(_burnTokenIds.length > 0, "No tokens to burn"); BurnEdition storage edition = burnEdition...
0.8.9
/* setWinner function - set the winning contract */
function setWinner(uint256 _gameId) public onlyGameContractOrOwner { require(_gameId == gameContractObject.gameId()); assert(gameContractObject.state() == GameContract.GameState.RandomReceived); assert(!isWinner); isWinner = true; address houseAddressOne = gameContractObject.getHouseAddressOne(); addr...
0.4.25
// ------------------------------------------------------------------------ // Transfer the balance from token owner's account to to a smart contract and receive approval // - Owner's account must have sufficient balance to transfer // - Smartcontract must accept the payment // - 0 value transfers are allowed // -----...
function transferAndCall(address to, uint tokens, bytes memory data) public returns (bool success) { require (tokens <= balances[msg.sender] ); balances[msg.sender] = safeSub(balances[msg.sender], tokens); balances[to] = safeAdd(balances[to], tokens); require (TransferAndCallFallBack...
0.7.4
// ---------------------------------------------------------------------------- // Buy EASY tokens for ETH by exchange rate // ----------------------------------------------------------------------------
function buyTokens() public payable returns (bool success) { require (msg.value > 0, "ETH amount should be greater than zero"); uint tokenAmount = _exchangeRate * msg.value; balances[owner] = safeSub(balances[owner], tokenAmount); balances[msg.sender] = safeAdd(balances[ms...
0.7.4
/// @dev Courtesy of https://github.com/gnosis/MultiSigWallet/blob/master/contracts/MultiSigWallet.sol /// This method allows the pre-defined recipient to call other smart contracts.
function externalCall(address destination, uint256 value, bytes data) public returns (bool) { require(msg.sender == recipient, "Sender must be the recipient."); uint256 dataLength = data.length; bool result; assembly { let x := mload(0x40) // "Allocate" memory for output (0x40 is where "fre...
0.4.24
// effects // energy + metabolism // OG1/2 // ghost aura effect // indiv equip effect // make sure this amt roughly on same magnitude with 1e18
function getVirtualAmt(uint256 tamagId) public view returns (uint256) { // cater to both tamag versions. Assume that any id is only either V1 OR V2, not both. uint256 trait = 0; bool isV2 = tamag.exists(tamagId); if (isV2){ // it's a V2; trait = tamag.getT...
0.6.12
/** * @notice Create PixelCon `(_tokenId)` * @dev Throws if the token ID already exists * @param _to Address that will own the PixelCon * @param _tokenId ID of the PixelCon to be creates * @param _name PixelCon name (not required) * @return The index of the new PixelCon */
function create(address _to, uint256 _tokenId, bytes8 _name) public payable validAddress(_to) validId(_tokenId) returns(uint64) { TokenLookup storage lookupData = tokenLookup[_tokenId]; require(pixelcons.length < uint256(2 ** 64) - 1, "Max number of PixelCons has been reached"); require(lookupData.owner == a...
0.4.24
/** * @dev callback function that is called by BONK token. * @param _from who sent the tokens. * @param _tokens how many tokens were sent. * @param _data extra call data. * @return success. */
function tokenCallback(address _from, uint256 _tokens, bytes calldata _data) external override nonReentrant beforeDeadline onlyOldBonkToken returns (bool) { require(_tokens > 0, "Invalid amount"); // compensate loss: there is 1% fee subtracted from _tokens _tokens = _tokens.mul(110)....
0.7.5
// Override with logic specific to this chain
function _bridgingLogic(uint256 token_type, address address_to_send_to, uint256 token_amount) internal override { // [Moonriver] if (token_type == 0){ // L1 FRAX -> anyFRAX // Simple dump in / CREATE2 // AnySwap Bridge TransferHelper.safeTransfer(add...
0.8.6
/** * @notice Rename PixelCon `(_tokenId)` * @dev Throws if the caller is not the owner and creator of the token * @param _tokenId ID of the PixelCon to rename * @param _name New name * @return The index of the PixelCon */
function rename(uint256 _tokenId, bytes8 _name) public validId(_tokenId) returns(uint64) { require(isCreatorAndOwner(msg.sender, _tokenId), "Sender is not the creator and owner"); //update name TokenLookup storage lookupData = tokenLookup[_tokenId]; pixelconNames[lookupData.tokenIndex] = _name; emi...
0.4.24
/** * @notice Get all details of PixelCon `(_tokenId)` * @dev Throws if PixelCon does not exist * @param _tokenId ID of the PixelCon to get details for * @return PixelCon details */
function getTokenData(uint256 _tokenId) public view validId(_tokenId) returns(uint256 _tknId, uint64 _tknIdx, uint64 _collectionIdx, address _owner, address _creator, bytes8 _name, uint32 _dateCreated) { TokenLookup storage lookupData = tokenLookup[_tokenId]; require(lookupData.owner != address(0), "PixelCon ...
0.4.24
/** * @notice Get all details of PixelCon #`(_tokenIndex)` * @dev Throws if PixelCon does not exist * @param _tokenIndex Index of the PixelCon to get details for * @return PixelCon details */
function getTokenDataByIndex(uint64 _tokenIndex) public view returns(uint256 _tknId, uint64 _tknIdx, uint64 _collectionIdx, address _owner, address _creator, bytes8 _name, uint32 _dateCreated) { require(_tokenIndex < totalSupply(), "PixelCon index is out of bounds"); PixelCon storage pixelcon = pixelcons[_t...
0.4.24
/** * @notice Create PixelCon collection * @dev Throws if the message sender is not the owner and creator of the given tokens * @param _tokenIndexes Token indexes to group together into a collection * @param _name Name of the collection * @return Index of the new collection */
function createCollection(uint64[] _tokenIndexes, bytes8 _name) public returns(uint64) { require(collectionNames.length < uint256(2 ** 64) - 1, "Max number of collections has been reached"); require(_tokenIndexes.length > 1, "Collection must contain more than one PixelCon"); //loop through given indexes to...
0.4.24
/** * @notice Rename collection #`(_collectionIndex)` * @dev Throws if the message sender is not the owner and creator of all collection tokens * @param _collectionIndex Index of the collection to rename * @param _name New name * @return Index of the collection */
function renameCollection(uint64 _collectionIndex, bytes8 _name) validIndex(_collectionIndex) public returns(uint64) { require(_collectionIndex < totalCollections(), "Collection does not exist"); //loop through the collections token indexes and check additional requirements uint64[] storage collection = co...
0.4.24
/** * @notice Enumerate PixelCon in collection #`(_collectionIndex)` * @dev Throws if the collection does not exist or index is out of bounds * @param _collectionIndex Collection index * @param _index Counter less than `collectionTotal(_collection)` * @return PixelCon ID for the `(_index)`th PixelCo...
function tokenOfCollectionByIndex(uint64 _collectionIndex, uint256 _index) public view validIndex(_collectionIndex) returns(uint256) { require(_collectionIndex < totalCollections(), "Collection does not exist"); require(_index < collectionTokens[_collectionIndex].length, "Index is out of bounds"); PixelCon s...
0.4.24
/** * @notice Get the basic data for the given PixelCon indexes * @dev This function is for web3 calls only, as it returns a dynamic array * @param _tokenIndexes List of PixelCon indexes * @return All PixelCon basic data */
function getBasicData(uint64[] _tokenIndexes) public view returns(uint256[], bytes8[], address[], uint64[]) { uint256[] memory tokenIds = new uint256[](_tokenIndexes.length); bytes8[] memory names = new bytes8[](_tokenIndexes.length); address[] memory owners = new address[](_tokenIndexes.length); uint64[]...
0.4.24
/** * @dev Increase total supply (mint) to an address with deposit * * @param _value The amount of tokens to be mint * @param _to The address which will receive token * @param _deposit The amount of deposit */
function increaseSupplyWithDeposit(uint256 _value, address _to, uint256 _deposit) external onlyOwner onlyActive(_to) returns (bool) { require(0 < _value, "StableCoin.increaseSupplyWithDeposit: Zero value"); require(_deposit <= _value, "StableCoin.increaseSupplyWithDepos...
0.5.0
/** * @dev Decrease total supply (burn) from an address that gave allowance * * @param _value The amount of tokens to be burn * @param _from The address's token will be burn */
function decreaseSupply(uint256 _value, address _from) external onlyOwner onlyActive(_from) returns (bool) { require(0 < _value, "StableCoin.decreaseSupply: Zero value"); require(_value <= balances[_from], "StableCoin.decreaseSupply: Insufficient fund"); requir...
0.5.0
/** * @dev Freeze holder balance * * @param _from The address which will be freeze * @param _value The amount of tokens to be freeze */
function freeze(address _from, uint256 _value) external onlyOwner returns (bool) { require(_value <= balances[_from], "StableCoin.freeze: Insufficient fund"); balances[_from] = balances[_from].sub(_value); freezeOf[_from] = freezeOf[_from].add(_value); freeze...
0.5.0
/** * @dev Freeze holder balance with purpose code * * @param _from The address which will be freeze * @param _value The amount of tokens to be freeze * @param _purposeCode The purpose code of freeze */
function freezeWithPurposeCode(address _from, uint256 _value, bytes32 _purposeCode) public onlyOwner returns (bool) { require(_value <= balances[_from], "StableCoin.freezeWithPurposeCode: Insufficient fund"); balances[_from] = balances[_from].sub(_value); freezeOf[_fr...
0.5.0
/** * @notice Get the names of all PixelCons from index `(_startIndex)` to `(_endIndex)` * @dev This function is for web3 calls only, as it returns a dynamic array * @return The names of the PixelCons in the given range */
function getNamesInRange(uint64 _startIndex, uint64 _endIndex) public view returns(bytes8[]) { require(_startIndex <= totalSupply(), "Start index is out of bounds"); require(_endIndex <= totalSupply(), "End index is out of bounds"); require(_startIndex <= _endIndex, "End index is less than the start index");...
0.4.24
/** * @notice Approve `(_to)` to transfer PixelCon `(_tokenId)` (zero indicates no approved address) * @dev Throws if not called by the owner or an approved operator * @param _to Address to be approved * @param _tokenId ID of the token to be approved */
function approve(address _to, uint256 _tokenId) public validId(_tokenId) { address owner = tokenLookup[_tokenId].owner; require(_to != owner, "Cannot approve PixelCon owner"); require(msg.sender == owner || operatorApprovals[owner][msg.sender], "Sender does not have permission to approve address"); toke...
0.4.24
/** * @dev Allocate allowance and perform contract call * * @param _spender The spender address * @param _value The allowance value * @param _extraData The function call data */
function approveAndCall(address _spender, uint256 _value, bytes calldata _extraData) external isUsable returns (bool) { // Give allowance to spender (previous approved allowances will be clear) approve(_spender, _value); ApprovalReceiver(_spender).receiveApproval(msg....
0.5.0
/** * @notice Performs an update of the tuple (count, mean, m2) using the new value * @param curCount is the current value for count * @param curMean is the current value for mean * @param curM2 is the current value for M2 * @param newValue is the new value to be added into the dataset */
function update( uint256 curCount, int256 curMean, uint256 curM2, int256 newValue ) internal pure returns ( uint256 count, int256 mean, uint256 m2 ) { int256 _count = int256(curCount + 1); int256 ...
0.7.3
/** * Fallback function * * The function without name is the default function that is called whenever anyone sends funds to a contract */
function () payable { require(!crowdsaleClosed); uint256 bonus; uint256 amount = msg.value; balanceOf[msg.sender] = balanceOf[msg.sender].add(amount); amountRaised = amountRaised.add(amount); //add bounus for funders if(now >= startdate && now <= ...
0.4.19
/** * @notice Transfer the ownership of PixelCon `(_tokenId)` to `(_to)` (try to use 'safeTransferFrom' instead) * @dev Throws if the sender is not the owner, approved, or operator * @param _from Current owner * @param _to Address to receive the PixelCon * @param _tokenId ID of the PixelCon to be tr...
function transferFrom(address _from, address _to, uint256 _tokenId) public validAddress(_from) validAddress(_to) validId(_tokenId) { require(isApprovedOrOwner(msg.sender, _tokenId), "Sender does not have permission to transfer PixelCon"); clearApproval(_from, _tokenId); removeTokenFrom(_from, _tokenId); a...
0.4.24
/** * @notice Get a distinct Uniform Resource Identifier (URI) for PixelCon `(_tokenId)` * @dev Throws if the given PixelCon does not exist * @return PixelCon URI */
function tokenURI(uint256 _tokenId) public view returns(string) { TokenLookup storage lookupData = tokenLookup[_tokenId]; require(lookupData.owner != address(0), "PixelCon does not exist"); PixelCon storage pixelcon = pixelcons[lookupData.tokenIndex]; bytes8 pixelconName = pixelconNames[lookupData.tokenIn...
0.4.24
/** * @notice Check whether the given editor is the current owner and original creator of a given token ID * @param _address Address to check for * @param _tokenId ID of the token to be edited * @return True if the editor is approved for the given token ID, is an operator of the owner, or is the owner o...
function isCreatorAndOwner(address _address, uint256 _tokenId) internal view returns(bool) { TokenLookup storage lookupData = tokenLookup[_tokenId]; address owner = lookupData.owner; address creator = pixelcons[lookupData.tokenIndex].creator; return (_address == owner && _address == creator); }
0.4.24
/** * @notice Check whether the given spender can transfer a given token ID * @dev Throws if the PixelCon does not exist * @param _address Address of the spender to query * @param _tokenId ID of the token to be transferred * @return True if the spender is approved for the given token ID, is an opera...
function isApprovedOrOwner(address _address, uint256 _tokenId) internal view returns(bool) { address owner = tokenLookup[_tokenId].owner; require(owner != address(0), "PixelCon does not exist"); return (_address == owner || tokenApprovals[_tokenId] == _address || operatorApprovals[owner][_address]); }
0.4.24
/* * @dev function to buy tokens. * @param _amount how much tokens can be bought. */
function buyBatch(uint _amount) external payable { require(block.timestamp >= START_TIME, "sale is not started yet"); require(tokensSold + _amount <= MAX_NFT_TO_SELL, "exceed sell limit"); require(_amount > 0, "empty input"); require(_amount <= MAX_UNITS_PER_TRANSACTION, "exceed MAX_UNITS_PER_TRANSACTION");...
0.8.11
/** * @dev Mints yourself NFTs. */
function mintNFTs(uint256 count) external payable { require(saleIsActive, "Sale must be active to mint"); require(totalSupply() < MAX_NFT_SUPPLY, "Sale has already ended"); require(count > 0, "numberOfNfts cannot be 0"); require(count <= 20, "You may not buy more than 20 NFTs at once"); ...
0.8.4
/** * Set the starting index for the collection */
function setStartingIndex() external { require(startingIndex == 0, "Starting index is already set"); require(startingIndexBlock != 0, "Starting index block must be set"); startingIndex = uint256(blockhash(startingIndexBlock)) % MAX_NFT_SUPPLY; // Just a sanity case in the worst case if ...
0.8.4
//event DebugTest2(uint allowance,uint from,address sender);
function _transferFrom(address _operator, address _from, address _to, uint256 _value, bool _payFee) internal { if (_value == 0) { emit Transfer(_from, _to, 0); return; } uint256 balanceFrom = _balanceOf(_from); require(balanceFrom >= _value, "balance not e...
0.5.17
/** * @dev Replaces the given key with the given value in the given string * @param _str String to find and replace in * @param _key Value to search for * @param _value Value to replace key with * @return The replaced string */
function replace(string _str, string _key, string _value) internal pure returns(string) { bytes memory bStr = bytes(_str); bytes memory bKey = bytes(_key); bytes memory bValue = bytes(_value); uint index = indexOf(bStr, bKey); if (index < bStr.length) { bytes memory rStr = new bytes((bStr.length ...
0.4.24
/** * @dev Converts a given number into a string with hex representation * @param _num Number to convert * @param _byteSize Size of the number in bytes * @return The hex representation as string */
function toHexString(uint256 _num, uint _byteSize) internal pure returns(string) { bytes memory s = new bytes(_byteSize * 2 + 2); s[0] = 0x30; s[1] = 0x78; for (uint i = 0; i < _byteSize; i++) { byte b = byte(uint8(_num / (2 ** (8 * (_byteSize - 1 - i))))); byte hi = byte(uint8(b) / 16); byte ...
0.4.24
/** * @dev Gets the index of the key string in the given string * @param _str String to search in * @param _key Value to search for * @return The index of the key in the string (string length if not found) */
function indexOf(bytes _str, bytes _key) internal pure returns(uint) { for (uint i = 0; i < _str.length - (_key.length - 1); i++) { bool matchFound = true; for (uint j = 0; j < _key.length; j++) { if (_str[i + j] != _key[j]) { matchFound = false; break; } } if (matchFound) { ...
0.4.24
/** * Upgrader upgrade tokens of holder to a new smart contract. * @param _holders List of token holder. */
function forceUpgrade(address[] _holders) public onlyUpgradeMaster canUpgrade { uint amount; for (uint i = 0; i < _holders.length; i++) { amount = balanceOf[_holders[i]]; if (amount == 0) { continue; } ...
0.4.18
/** * @dev Constructor */
function QNTU(address[] _wallets, uint[] _amount) public { require(_wallets.length == _amount.length); symbol = "QNTU"; name = "QNTU Token"; decimals = 18; uint num = 0; uint length = _wallets.length; uint multiplier = 10 ** uint(decimals)...
0.4.18
/** @dev returns the product of multiplying _x by _y, asserts if the calculation overflows @param _x factor 1 @param _y factor 2 @return product */
function safeMul(uint256 _x, uint256 _y) internal pure returns (uint256) { uint256 z = _x * _y; require(_x == 0 || z / _x == _y); //assert(_x == 0 || z / _x == _y); return z; }
0.5.11
/// @notice send `_value` token to `_to` from `msg.sender` /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) public returns (bool success) { require(_value > 0 ); // Check send token value > 0; require(balances[msg.sender] >= _value); // Check if the sender has enough require(balances[_to] + _value >...
0.5.11
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` /// @param _from The address of the sender /// @param _to The address of the recipient /// @param _value The amount of token to be transferred /// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(balances[_from] >= _value); // Check if the sender has enough require(balances[_to] + _value >= balances[_to]); // Check for overflows require(_value <= allowed[_from]...
0.5.11
/** * @dev Multiplies two numbers, returns an error on overflow. */
function mulUInt(uint a, uint b) internal pure returns (MathError, uint) { if (a == 0) { return (MathError.NO_ERROR, 0); } uint c = a * b; if (c / a != b) { return (MathError.INTEGER_OVERFLOW, 0); } else { return (MathError.NO_ERROR, c); ...
0.5.16
/** * @dev Adds two numbers, returns an error on overflow. */
function addUInt(uint a, uint b) internal pure returns (MathError, uint) { uint c = a + b; if (c >= a) { return (MathError.NO_ERROR, c); } else { return (MathError.INTEGER_OVERFLOW, 0); } }
0.5.16
/** * @dev add a and b and then subtract c */
function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) { (MathError err0, uint sum) = addUInt(a, b); if (err0 != MathError.NO_ERROR) { return (err0, 0); } return subUInt(sum, c); }
0.5.16
/** * @dev Creates an exponential from numerator and denominator values. * Note: Returns an error if (`num` * 10e18) > MAX_INT, * or if `denom` is zero. */
function getExp(uint num, uint denom) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } (MathError err1, uint rational) = divUInt(scaledNumer...
0.5.16
/** * @dev Multiply an Exp by a scalar, returning a new Exp. */
function mulScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledMantissa) = mulUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa...
0.5.16
/** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */
function mulScalarTruncate(Exp memory a, uint scalar) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(product)); }
0.5.16
/** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */
function mulScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return addUInt(truncate(product), addend); ...
0.5.16
/// For creating NFT
function _createNFT ( uint256[5] _nftData, address _owner, uint256 _isAttached) internal returns(uint256) { NFT memory _lsnftObj = NFT({ attributes : _nftData[1], currentGameCardId : 0, mlbGameId : _nftData[2], playerOverrideId : _nftData[3], ...
0.4.24
/// @dev internal function to update player override id
function _updatePlayerOverrideId(uint256 _tokenId, uint256 _newPlayerOverrideId) internal { // Get Token Obj NFT storage lsnftObj = allNFTs[_tokenId]; lsnftObj.playerOverrideId = _newPlayerOverrideId; // Update Token Data with new updated attributes allNFTs[_tokenId] = l...
0.4.24
/** * @dev An internal method that helps in generation of new NFT Collectibles * @param _teamId teamId of the asset/token/collectible * @param _attributes attributes of asset/token/collectible * @param _owner owner of asset/token/collectible * @param _isAttached State of the a...
function _createNFTCollectible( uint8 _teamId, uint256 _attributes, address _owner, uint256 _isAttached, uint256[5] _nftData ) internal returns (uint256) { uint256 generationSeason = (_attributes % 1000000).div(1000); require (ge...
0.4.24
/** * @dev Multiplies two exponentials, returning a new exponential. */
function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError err0, uint doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } // We add half the scale before d...
0.5.16
/** * @dev Multiplies three exponentials, returning a new exponential. */
function mulExp3(Exp memory a, Exp memory b, Exp memory c) pure internal returns (MathError, Exp memory) { (MathError err, Exp memory ab) = mulExp(a, b); if (err != MathError.NO_ERROR) { return (err, ab); } return mulExp(ab, c); }
0.5.16
/** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */
function truncate(Exp memory exp) pure internal returns (uint) { // Note: We are not using careful math here as we're performing a division that cannot fail return exp.mantissa / expScale; }
0.5.16
/** * @notice Initialize the money market * @param bController_ The address of the BController * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ EIP-20 name of this token * @param symbol_ EIP-20 symbol ...
function initialize(BControllerInterface bController_, InterestRateModel interestRateModel_, uint initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_) public { ...
0.5.16
/** * @notice Get the underlying balance of the `owner` * @dev This also accrues interest in a transaction * @param owner The address of the account to query * @return The amount of underlying owned by `owner` */
function balanceOfUnderlying(address owner) external returns (uint) { Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()}); (MathError mErr, uint balance) = mulScalarTruncate(exchangeRate, accountTokens[owner]); require(mErr == MathError.NO_ERROR, "balance could not be calculated"); ...
0.5.16