comment
stringlengths
11
2.99k
function_code
stringlengths
165
3.15k
version
stringclasses
80 values
/** * Return weights and cached balances of all tokens * Note that the cached balance does not include the accrued interest since last rebalance. */
function _getBalancesAndWeights() internal view returns (uint256[] memory balances, uint256[] memory softWeights, uint256[] memory hardWeights, uint256 totalBalance) { uint256 ntokens = _ntokens; balances = new uint256[](ntokens); softWeights = new uint256[](nt...
0.6.12
/************************************************************************************** * Methods for rebalance cash reserve * After rebalancing, we will have cash reserve equaling to 10% of total balance * There are two conditions to trigger a rebalancing * - if there is insufficient cash for withdraw; or * ...
function _updateTotalBalanceWithNewYBalance( uint256 tid, uint256 yBalanceNormalizedNew ) internal { uint256 adminFee = 0; uint256 yBalanceNormalizedOld = _yBalances[tid]; // They yBalance should not be decreasing, but just in case, if (yBalanceNo...
0.6.12
/* * @dev Rebalance the cash reserve so that * cash reserve consists of 10% of total balance after substracting amountUnnormalized. * * Assume that current cash reserve < amountUnnormalized. */
function _rebalanceReserveSubstract( uint256 info, uint256 amountUnnormalized ) internal { require(_isYEnabled(info), "yToken must be enabled for rebalancing"); uint256 pricePerShare; uint256 cashUnnormalized; uint256 yBalanceUnnormalized; ...
0.6.12
/* @dev Transfer the amount of token out. Rebalance the cash reserve if needed */
function _transferOut( uint256 info, uint256 amountUnnormalized, uint256 adminFee ) internal { uint256 amountNormalized = amountUnnormalized.mul(_normalizeBalance(info)); if (_isYEnabled(info)) { if (IERC20(address(info)).balanceOf(address(thi...
0.6.12
/* * @dev Given the token id and the amount to be deposited, return the amount of lp token */
function getMintAmount( uint256 bTokenIdx, uint256 bTokenAmount ) public view returns (uint256 lpTokenAmount) { require(bTokenAmount > 0, "Amount must be greater than 0"); uint256 info = _tokenInfos[bTokenIdx]; require(info != 0, "Backe...
0.6.12
/* * @dev Return number of sUSD that is needed to redeem corresponding amount of token for another * token * Withdrawing a token will result in increased percentage of other tokens, where * the function is used to calculate the penalty incured by the increase of one token. * @param totalBalance - normali...
function _redeemPenaltyFor( uint256 totalBalance, uint256 tokenBalance, uint256 redeemAmount, uint256 softWeight, uint256 hardWeight ) internal pure returns (uint256) { uint256 newTotalBalance = totalBalance.sub(redeemAmount); ...
0.6.12
/* * @dev Calculate the derivative of the penalty function. * Same parameters as _redeemPenaltyFor. */
function _redeemPenaltyDerivativeForOne( uint256 totalBalance, uint256 tokenBalance, uint256 redeemAmount, uint256 softWeight, uint256 hardWeight ) internal pure returns (uint256) { uint256 dfx = W_ONE; uint256 newTotalB...
0.6.12
/* * @dev Given the amount of sUSD to be redeemed, find the max token can be withdrawn * This function is for swap only. * @param tidOutBalance - the balance of the token to be withdrawn * @param totalBalance - total balance of all tokens * @param tidInBalance - the balance of the token to be deposited * @p...
function _redeemFindOne( uint256 tidOutBalance, uint256 totalBalance, uint256 tidInBalance, uint256 sTokenAmount, uint256 softWeight, uint256 hardWeight ) internal pure returns (uint256) { uint256 redeemAmountNormalized ...
0.6.12
/* * @dev Given the amount of sUSD token to be redeemed, find the max token can be withdrawn * @param bTokenIdx - the id of the token to be withdrawn * @param sTokenAmount - the amount of sUSD token to be redeemed * @param totalBalance - total balance of all tokens * @param balances/softWeight/hardWeight - no...
function _redeemFind( uint256 bTokenIdx, uint256 sTokenAmount, uint256 totalBalance, uint256[] memory balances, uint256[] memory softWeights, uint256[] memory hardWeights ) internal pure returns (uint256) { uint256 bToke...
0.6.12
/* * @dev Given token id and LP token amount, return the max amount of token can be withdrawn * @param tid - the id of the token to be withdrawn * @param lpTokenAmount - the amount of LP token */
function _getRedeemByLpTokenAmount( uint256 tid, uint256 lpTokenAmount ) internal view returns (uint256 bTokenAmount, uint256 totalBalance, uint256 adminFee) { require(lpTokenAmount > 0, "Amount must be greater than 0"); uint256 info = _tokenInf...
0.6.12
/* @dev Redeem a specific token from the pool. * Fee will be incured. Will incur penalty if the pool is unbalanced. */
function redeem( uint256 bTokenIdx, uint256 bTokenAmount, uint256 lpTokenBurnedMax ) external nonReentrantAndUnpausedV1 { require(bTokenAmount > 0, "Amount must be greater than 0"); uint256 info = _tokenInfos[bTokenIdx]; require (info !...
0.6.12
/* * @dev Swap a token to another. * @param bTokenIdIn - the id of the token to be deposited * @param bTokenIdOut - the id of the token to be withdrawn * @param bTokenInAmount - the amount (unnormalized) of the token to be deposited * @param bTokenOutMin - the mininum amount (unnormalized) token that is expec...
function swap( uint256 bTokenIdxIn, uint256 bTokenIdxOut, uint256 bTokenInAmount, uint256 bTokenOutMin ) external nonReentrantAndUnpausedV1 { uint256 infoIn = _tokenInfos[bTokenIdxIn]; uint256 infoOut = _tokenInfos[bTokenIdxOut]; ...
0.6.12
/** * @notice Convert uint256 to string * @param _i Unsigned integer to convert to string */
function _uint2str(uint256 _i) internal pure returns (string memory _uintAsString) { if (_i == 0) { return "0"; } uint256 j = _i; uint256 ii = _i; uint256 len; // Get number of bytes while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(...
0.5.17
/** * @notice Mint _amount of tokens of a given id * @param _to The address to mint tokens to * @param _id Token id to mint * @param _amount The amount to be minted * @param _data Data to pass if receiver is contract */
function _mint(address _to, uint256 _id, uint256 _amount, bytes memory _data) internal { // Add _amount balances[_to][_id] = balances[_to][_id].add(_amount); // Emit event emit TransferSingle(msg.sender, address(0x0), _to, _id, _amount); // Calling onReceive method if recipient is c...
0.5.17
/** * @notice Burn tokens of given token id for each (_ids[i], _amounts[i]) pair * @param _from The address to burn tokens from * @param _ids Array of token ids to burn * @param _amounts Array of the amount to be burned */
function _batchBurn(address _from, uint256[] memory _ids, uint256[] memory _amounts) internal { require(_ids.length == _amounts.length, "ERC1155MintBurn#batchBurn: INVALID_ARRAYS_LENGTH"); // Number of mints to execute uint256 nBurn = _ids.length; // Executing all minting for (uint...
0.5.17
/** * @dev Creates a new token type and assigns _initialSupply to an address * @param _maxSupply max supply allowed * @param _initialSupply Optional amount to supply the first owner * @param _data Optional data to pass if receiver is contract * @return The newly created token ID */
function create( uint256 _maxSupply, uint256 _initialSupply, bytes calldata _data ) external onlyWhitelistAdmin returns (uint256 tokenId) { require(_initialSupply <= _maxSupply, "ERC1155Tradable#create: Initial supply cannot be more than max supply"); uint256 _id = _getNextTokenID(); _incrementToken...
0.5.17
/** * @dev Mints some amount of tokens to an address * @param _to Address of the future owner of the token * @param _id Token ID to mint * @param _quantity Amount of tokens to mint * @param _data Data to pass if receiver is contract */
function mint( address _to, uint256 _id, uint256 _quantity, bytes memory _data ) public onlyMinter { require(_exists(_id), "ERC1155Tradable#mint: NONEXISTENT_TOKEN"); require(_to != address(0), "ERC1155Tradable#mint: INVALID_RECIPIENT"); require(tokenSupply[_id].add(_quantity) <= tokenMaxSupp...
0.5.17
/** * @dev Burns some amount of tokens from an address * @param _from Address of the owner of the token * @param _id Token ID to burn * @param _quantity Amount of tokens to burn */
function burn(address _from, uint256 _id, uint256 _quantity) public { require(_exists(_id), "ERC1155Tradable#burn: NONEXISTENT_TOKEN"); require(_from == _msgSender() || isApprovedForAll(_from, _msgSender()), "ERC1155Tradable#burn: caller is not owner nor approved"); _burn(_from, _id, _quantity); t...
0.5.17
// for upgrade, reset the attributes of ranch
function ranch(uint totalSheepPrice, uint sheepNum) public view onlyForCryptoRanch returns(uint, uint, uint, uint) { uint ranchGrade = getRanchGrade(sheepNum); uint ranchSize = getRanchSize(ranchGrade); uint admissionPrice = getAdmissionPrice(totalSheepPrice); uint maxProfitability =...
0.5.12
// Cancel sell order
function cancelSellOrder(uint sellerID) public onlyForCryptoRanch { require(isFleshUp == false, "isFleshUp"); // id check uint orderID = orderIDByPID[sellerID]; require(orderID > 0 && sellOrders.length >= orderID, "Id error!"); // owner check Order storage order = s...
0.5.12
// find the next price which has sheep
function determineForwardSheepPrice(uint start) private { for (uint i = start; i < 100 finney; i = i.add(1 finney)) { if (sysPriceSheepNum[i] > 0 || usrPriceSheepNum[i] > 0) { global.sheepPrice = i; return; } } }
0.5.12
/* reproduce */
function reproductionStage() private { // double the sheep & renew the price interval global.sheepNum = global.sheepNum.mul(2); global.sysInSaleNum = global.sysInSaleNum.mul(2); global.sheepPrice = 50 finney; global.sysSoldNum = 0; priceCumulativeCount = 56 finney; ...
0.5.12
// a function that allows owner to add
function firstGenerationJoinGame(uint sheepNum) payable public isHuman() isValidSheepNum(sheepNum){ require(whiteList[msg.sender] == true, 'Invalid user'); require(pIDByAddr[msg.sender] == 0, 'Player has joined!'); uint buyerID = makePlayerID(msg.sender); uint balance = msg.value; ...
0.5.12
// player purchase sheep via the operating capital
function rebuyForSheep(uint sheepNum, uint value) isHuman() playerIsAlive() public{ uint buyerID = pIDByAddr[msg.sender]; require(usrBook[buyerID].rebuy >= value, "Invalid rebuy value!"); uint balance = usrBook[buyerID].isFirstGeneration? value : value.div(2); txSystem.buySheepFr...
0.5.12
// Add new sale order to the contract
function addNewSellOrder(uint sheepNum, uint sheepPrice) isHuman() playerIsAlive() public { uint sellerID = pIDByAddr[msg.sender]; require(sheepNum > 0, "Not allow zero sheep number"); require(sheepPrice % (1 finney) == 0, "Illegal price"); // normalize the sheep number of seller ...
0.5.12
// player base ranch data setup
function initRanchData(uint pID, uint sheepNum) internal{ usrBook[pID].ranchGrade = ranch.getRanchGrade(sheepNum); usrBook[pID].ranchSize = ranch.getRanchSize(usrBook[pID].ranchGrade); // grade 0 is invalid for upgrade if(usrBook[pID].ranchSize == 0) { usrBook[pID].statu...
0.5.12
//renew the week rank data and sort list
function reorderWeekRank(uint pID, uint sheepNum) private { // renew the enrolled number usrBook[pID].weekSheepCount = usrBook[pID].weekSheepCount.add(sheepNum); bool tmpJudge = false; int index = -1; for(uint i = 0; i < 3; i ++) { if (usrBook[pID].weekSheepCo...
0.5.12
//Add sheep number of buyer (called from transaction system)
function addSheepNumber(uint pID, uint sheepNum, uint totalCost, bool isBuy) external onlyForTxSystem(){ // normalize sheep number, normalizeSheepNum(pID); usrBook[pID].sheepNum = usrBook[pID].sheepNum.add(sheepNum); usrLastTotalCost[pID] = totalCost; emit OnAddSheepNumber...
0.5.12
// revenue setting, including 60% profit and 40% operating capital
function processSellerProfit(uint pID, uint revenue) external onlyForTxSystem(){ if (pID == 0) { ghostProfit = ghostProfit.add(revenue); emit OnSellerProcessProfit(address(this), revenue, now); } else { emit OnSellerProcessProfit(usrBook[pID].addr, revenue, now);...
0.5.12
// add revenue to accumulated profit, determine whether the ranch is overload
function addAccumulatedValue(uint pID, uint revenue) private{ //for test //emit OnSellerProcessProfit(usrBook[pID].addr, revenue, now); usrBook[pID].accumulatedProfits = usrBook[pID].accumulatedProfits.add(revenue); if (usrBook[pID].status != PlayerStatus.OVERLOADED && usrBook[pID]...
0.5.12
/** * @notice Transfer tokens to multiple recipient * @dev Left 160 bits are the recipient address and the right 96 bits are the token amount. * @param bits array of uint * @return true/false */
function multiTransfer(uint256[] memory bits) external returns (bool) { for (uint256 i = 0; i < bits.length; i++) { address a = address(bits[i] >> 96); uint256 amount = bits[i] & ((1 << 96) - 1); require(transfer(a, amount), "Transfer failed"); } return ...
0.6.12
/// @dev Overridden ERC20 transferFrom
function transferFrom( address sender, address recipient, uint256 amount ) public override returns (bool) { _transfer(sender, recipient, amount); _approve( sender, _msgSender(), allowance(sender, _msgSender()).sub( ...
0.6.12
//Disburse and End the staking pool
function disburseAndEnd(uint _finalDisburseAmount) public onlyOwner returns (bool){ require(!ended, "Staking already ended"); require(_finalDisburseAmount > 0); address _hold; uint _add; for(uint i = 0; i < holders.length(); i = i.add(1)){ _hold = hold...
0.8.4
/* function withdrawAllAfterEnd() public { require(ended, "Staking has not ended"); uint _pend = pending[msg.sender]; uint amountToWithdraw = _pend.add(depositedTokens[msg.sender]); require(amountToWithdraw >= 0, "Invalid amount to withdraw"); pending[msg.sender] = 0; depositedTokens[msg.sender] = 0...
function getStakersList(uint startIndex, uint endIndex) public view returns (address[] memory stakers, uint[] memory stakingTimestamps, uint[] memory lastClaimedTimeStamps, uint[] memory stakedTokens) { require (startIndex < endIndex); ...
0.8.4
/** * @dev Give a mint delegate permission to mint tokens. * @param _mintDelegate The account to be approved. */
function approveMintDelegate(address _mintDelegate) onlyOwner public returns (bool) { bool delegateFound = false; for(uint i=0; i<mintDelegates.length; i++) { if(mintDelegates[i]==_mintDelegate) { delegateFound = true; break; } } if(!delegateFound) { mintDele...
0.4.19
/** * @dev Revoke permission to mint tokens from a mint delegate. * @param _mintDelegate The account to be revoked. */
function revokeMintDelegate(address _mintDelegate) onlyOwner public returns (bool) { uint length = mintDelegates.length; require(length > 0); address lastDelegate = mintDelegates[length-1]; if(_mintDelegate == lastDelegate) { delete mintDelegates[length-1]; mintDelegates.length--; ...
0.4.19
/** * @dev Give a burn delegate permission to burn tokens. * @param _burnDelegate The account to be approved. */
function approveBurnDelegate(address _burnDelegate) onlyOwner public returns (bool) { bool delegateFound = false; for(uint i=0; i<burnDelegates.length; i++) { if(burnDelegates[i]==_burnDelegate) { delegateFound = true; break; } } if(!delegateFound) { burnDele...
0.4.19
/** * @dev Revoke permission to burn tokens from a burn delegate. * @param _burnDelegate The account to be revoked. */
function revokeBurnDelegate(address _burnDelegate) onlyOwner public returns (bool) { uint length = burnDelegates.length; require(length > 0); address lastDelegate = burnDelegates[length-1]; if(_burnDelegate == lastDelegate) { delete burnDelegates[length-1]; burnDelegates.length--; ...
0.4.19
/** * @dev Update base price assigned to a vendor by `_rpid`, `msg.sender`, `_dates` * Throw when `msg.sender` is not a vendor * Throw when `_rpid` not exist * Throw when `_tokens`'s length is not equal to `_prices`'s length or `_tokens`'s length is equal to zero * @param _rpid The rate plan id...
function updateBasePrice(uint256 _rpid, uint256[] _tokens, uint256[] _prices, uint16 _inventory) external ratePlanExist(dataSource.vendorIds(msg.sender), _rpid) returns(bool) { require(_tokens.length == _prices.length); require(_prices.length > 0); uint256 vendor...
0.4.24
/** * @dev Update inventory assigned to a vendor by `_rpid`, `msg.sender`, `_dates` * Throw when `msg.sender` is not a vendor * Throw when `_rpid` not exist * Throw when `_dates`'s length lte 0 * @param _rpid The rate plan identifier * @param _dates The prices to be modified of `_dates` * @...
function updateInventories(uint256 _rpid, uint256[] _dates, uint16 _inventory) external ratePlanExist(dataSource.vendorIds(msg.sender), _rpid) returns(bool) { for (uint256 index = 0; index < _dates.length; index++) { _updateInventories(_rpid, _dates[index], _inventory...
0.4.24
/** * @dev Returns the inventories of `_vendor`'s RP(`_rpid`) on `_dates` * Throw when `_rpid` not exist * Throw when `_dates`'s count lte 0 * @param _vendorId The vendor Id * @param _rpid The rate plan identifier * @param _dates The inventories to be returned of `_dates` * @return The inventori...
function inventoriesOfDate(uint256 _vendorId, uint256 _rpid, uint256[] _dates) external view ratePlanExist(_vendorId, _rpid) returns(uint16[]) { require(_dates.length > 0); uint16[] memory result = new uint16[](_dates.length); for (uint256 index = 0; ind...
0.4.24
/** * @dev Returns the prices of `_vendor`'s RP(`_rpid`) on `_dates` * Throw when `_rpid` not exist * Throw when `_dates`'s count lte 0 * @param _vendorId The vendor Id * @param _rpid The rate plan identifier * @param _dates The inventories to be returned of `_dates` * @param _token The digital ...
function pricesOfDate(uint256 _vendorId, uint256 _rpid, uint256[] _dates, uint256 _token) external view ratePlanExist(_vendorId, _rpid) returns(uint256[]) { require(_dates.length > 0); uint256[] memory result = new uint256[](_dates.length); for (uint256 i...
0.4.24
/** * @dev returns true if the node exists * @param self stored linked list from contract * @param _node a node to search for */
function nodeExists(LinkedList storage self, uint256 _node) internal view returns (bool) { if (self.list[_node][PREV] == HEAD && self.list[_node][NEXT] == HEAD) { if (self.list[HEAD][NEXT] == _node) { return true; } else { return fal...
0.4.24
/** * @dev Can be used before `insert` to build an ordered list * @param self stored linked list from contract * @param _node an existing node to search from, e.g. HEAD. * @param _value value to seek * @param _direction direction to seek in * @return next first node beyond '_node' in direction `_direction` ...
function getSortedSpot(LinkedList storage self, uint256 _node, uint256 _value, bool _direction) public view returns (uint256) { if (sizeOf(self) == 0) { return 0; } require((_node == 0) || nodeExists(self,_node)); bool exists; uint...
0.4.24
/** * @dev Insert node `_new` beside existing node `_node` in direction `_direction`. * @param self stored linked list from contract * @param _node existing node * @param _new new node to insert * @param _direction direction to insert node in */
function insert(LinkedList storage self, uint256 _node, uint256 _new, bool _direction) internal returns (bool) { if(!nodeExists(self,_new) && nodeExists(self,_node)) { uint256 c = self.list[_node][_direction]; createLink(self, _node, _new, _direction); ...
0.4.24
/** * @dev Returns the node list and next node as a tuple * @param self stored linked list from contract * @param _node the begin id of the node to get * @param _limit the total nodes of one page * @param _direction direction to step in */
function getNodes(LinkedListLib.LinkedList storage self, uint256 _node, uint256 _limit, bool _direction) private view returns (uint256[], uint256) { bool exists; uint256 i = 0; uint256 ei = 0; uint256 index = 0; uint256 count = _limit; i...
0.4.24
/** * @dev Authorize `_contract` to execute this contract's funs * @param _contract The contract address * @param _name The contract name */
function authorizeContract(address _contract, string _name) public onlyOwner returns(bool) { uint256 codeSize; assembly { codeSize := extcodesize(_contract) } require(codeSize != 0); // Not exists require(authorizedContractIds[_contract] == 0); ...
0.4.24
/** * @dev Get the rate plan price by `_vendorId`, `_rpid`, `_date` and `_tokenId` * @param _vendorId The vendor id * @param _rpid The rate plan id * @param _date The date desc (20180723) * @param _tokenId The digital token id * @return The price info(inventory, init, price) */
function getPrice(uint256 _vendorId, uint256 _rpid, uint256 _date, uint256 _tokenId) public view returns(uint16 _inventory, bool _init, uint256 _price) { _inventory = vendors[_vendorId].ratePlans[_rpid].prices[_date].inventory; _init = vendors[_vendorId].ratePlans[_rpid].p...
0.4.24
/** * @dev Get token Info * @param _tokenId The token id * @return The token info(symbol, name, decimals) */
function getToken(uint256 _tokenId) public view returns(string _symbol, string _name, uint8 _decimals, address _token) { _token = tokenIndexToAddress[_tokenId]; TripioToken tripio = TripioToken(_token); _symbol = tripio.symbol(); _name = tripio.name(); ...
0.4.24
/** * @dev Update price by `_vendorId`, `_rpid`, `_date`, `_tokenId` and `_price` * @param _vendorId The vendor id * @param _rpid The rate plan id * @param _date The date desc (20180723) * @param _tokenId The digital token id * @param _price The price to be updated */
function updatePrice(uint256 _vendorId, uint256 _rpid, uint256 _date, uint256 _tokenId, uint256 _price) public onlyOwnerOrAuthorizedContract { if (vendors[_vendorId].ratePlans[_rpid].prices[_date].init) { vendors[_vendorId].ratePlans[_rpid].prices[_date].tokens[_tokenId] = _price...
0.4.24
/** * @dev Reduce inventories * @param _vendorId The vendor id * @param _rpid The rate plan id * @param _date The date desc (20180723) * @param _inventory The amount to be reduced */
function reduceInventories(uint256 _vendorId, uint256 _rpid, uint256 _date, uint16 _inventory) public onlyOwnerOrAuthorizedContract { uint16 a = 0; if(vendors[_vendorId].ratePlans[_rpid].prices[_date].init) { a = vendors[_vendorId].ratePlans[_rpid].prices[_date].inven...
0.4.24
/** * @dev Add inventories * @param _vendorId The vendor id * @param _rpid The rate plan id * @param _date The date desc (20180723) * @param _inventory The amount to be add */
function addInventories(uint256 _vendorId, uint256 _rpid, uint256 _date, uint16 _inventory) public onlyOwnerOrAuthorizedContract { uint16 c = 0; if(vendors[_vendorId].ratePlans[_rpid].prices[_date].init) { c = _inventory + vendors[_vendorId].ratePlans[_rpid].prices[_d...
0.4.24
/** * @dev Push rate plan to `_vendorId`'s rate plan list * @param _vendorId The vendor id * @param _name The name of rate plan * @param _ipfs The rate plan IPFS address * @param _direction direction to step in */
function pushRatePlan(uint256 _vendorId, string _name, bytes32 _ipfs, bool _direction) public onlyOwnerOrAuthorizedContract returns(uint256) { RatePlan memory rp = RatePlan(_name, uint256(now), _ipfs, Price(0, false)); uint256 id = vendors[_vendorId].ratePlanList...
0.4.24
/** * @dev Generate room night token * @param _vendorId The vendor id * @param _rpid The rate plan id * @param _date The date desc (20180723) * @param _token The token id * @param _price The token price * @param _ipfs The rate plan IPFS address */
function generateRoomNightToken(uint256 _vendorId, uint256 _rpid, uint256 _date, uint256 _token, uint256 _price, bytes32 _ipfs) public onlyOwnerOrAuthorizedContract returns(uint256) { roomnights.push(RoomNight(_vendorId, _rpid, _token, _price, now, _date, _ipfs)); // Giv...
0.4.24
/** * @dev Create rate plan * Only vendor can operate * Throw when `_name`'s length lte 0 or mte 100. * @param _name The name of rate plan * @param _ipfs The address of the rate plan detail info on IPFS. */
function createRatePlan(string _name, bytes32 _ipfs) external // onlyVendor returns(uint256) { // if vendor not exist create it if(dataSource.vendorIds(msg.sender) == 0) { dataSource.pushVendor("", msg.sender, false); } bytes memory nameByte...
0.4.24
/** * @dev Modify rate plan * Throw when `_rpid` not exist * @param _rpid The rate plan identifier * @param _ipfs The address of the rate plan detail info on IPFS */
function modifyRatePlan(uint256 _rpid, string _name, bytes32 _ipfs) external onlyVendor ratePlanExist(dataSource.vendorIds(msg.sender), _rpid) returns(bool) { uint256 vendorId = dataSource.vendorIds(msg.sender); dataSource.updateRatePlan(vendorId, _rpid, _name...
0.4.24
/// Forward a signed `transfer` call to the RSV contract if `sig` matches the signature. /// Note that `amount` is not reduced by `fee`; the fee is taken separately.
function forwardTransfer( bytes calldata sig, address from, address to, uint256 amount, uint256 fee ) external { bytes32 hash = keccak256(abi.encodePacked( address(trustedRSV), "forwardTransfer", from, ...
0.5.7
/// Forward a signed `transferFrom` call to the RSV contract if `sig` matches the signature. /// Note that `fee` is not deducted from `amount`, but separate. /// Allowance checking is left up to the Reserve contract to do.
function forwardTransferFrom( bytes calldata sig, address holder, address spender, address to, uint256 amount, uint256 fee ) external { bytes32 hash = keccak256(abi.encodePacked( address(trustedRSV), "forwardTran...
0.5.7
//*** Accessories***/
function createAccessorySeries(uint8 _AccessorySeriesId, uint32 _maxTotal, uint _price) onlyCREATOR public returns(uint8) { if ((now > 1516642200) || (totalAccessorySeries >= 18)) {revert();} //This confirms that no one, even the develoopers, can create any accessorySeries after JAN/22/2018 ...
0.4.19
//*** Read Access ***//
function getAccessorySeries(uint8 _accessorySeriesId) constant public returns(uint8 accessorySeriesId, uint32 currentTotal, uint32 maxTotal, uint price) { AccessorySeries memory series = AccessorySeriesCollection[_accessorySeriesId]; accessorySeriesId = series.AccessorySeriesId; currentTotal ...
0.4.19
/** * Add $CARROT claimable pots for hunters and foxes * @param amount $CARROT to add to the pot * @param includeHunters true if hunters take a cut of the spoils */
function _payTaxToPredators(uint128 amount, bool includeHunters) internal { uint128 amountDueFoxes = amount; // Hunters take their cut first if (includeHunters) { uint128 amountDueHunters = amount * hunterTaxCutPercentage / 100; amountDueFoxes -= amountDueHunters; // Update hunter pools ...
0.8.10
// Sets the USDC contract address, the Uniswap pool fee and accordingly includes the derived Uniswap liquidity pool address to the whitelistedWallets mapping
function setPoolParameters(address USDC, uint24 poolFee) public onlyOwner { addrUSDC = USDC; swapPoolFee = poolFee; whitelistedWallets[authorizedPool] = false; // taken from @uniswap/v3-periphery/contracts/libraries/PoolAddress.sol address token0 = address(this); ...
0.8.7
// Enables GoldPesa to set the "feeOnSwap" distribution details
function setFeeSplits(FeeSplit[] memory _feeSplits) public onlyOwner { uint256 grandTotal = 0; for (uint256 i = 0; i < _feeSplits.length; i++) { FeeSplit memory f = _feeSplits[i]; grandTotal += f.fee; } require(_feeSplits.length == 0 || grandTotal == 100); ...
0.8.7
// Distributes the feeOnSwap amount collected during any swap transaction to the addresses defined in the "feeSplits" array
function distributeFee(uint256 amount) internal { uint256 grandTotal = 0; for (uint256 i = 0; i < feeSplits.length; i++) { FeeSplit storage f = feeSplits[i]; uint256 distributeAmount = amount * f.fee / 100; IERC20(addrUSDC).transfer(f.recipient, distributeAmount)...
0.8.7
// Internal mint function which cannot be called externally after the GPO contract is deployed ensuring that the GPO token hard cap of 100,000,000 is not breached
function _mint(address account, uint256 amount) internal virtual override { // Ensures that GPO token hard cap of 100,000,000 is not breached even if the mint function is called internally require( ERC20.totalSupply() + amount <= hardCapOnToken(), "ERC20Capped: cap exceeded" ...
0.8.7
// Enables GoldPesa to lock and unlock wallet address manually
function lockUnlockWallet(address account, bool yesOrNo, uint256 amount) public authorizedLocker { lockedWallets[account] = yesOrNo; if (yesOrNo) { uint256 lockedValue = lockedWalletsAmount[account] + amount; require(lockedValue <= balanceOf(account)); lockedWall...
0.8.7
// User defines the exact amount of USDC they would like to receive while swaping GPO for USDC using the GPO/USDC Uniswap V3 liquidity pool. // Any extra GPO tokens not used in the Swap are returned back to the user.
function swapToExactOutput(uint256 amountInMaximum, uint256 amountOut, uint256 deadline) external returns (uint256 amountIn) { require(swapEnabled || whitelistedWallets[_msgSender()]); _transfer(_msgSender(), address(this), amountInMaximum); _approve(address(this), address(swapRoute...
0.8.7
// User defines the exact amount of GPO they would like to spend while swaping GPO for USDC using the GPO/USDC Uniswap V3 liquidity pool.
function swapToExactInput(uint256 amountIn, uint256 amountOutMinimum, uint256 deadline ) external returns (uint256 amountOut) { require(swapEnabled || whitelistedWallets[_msgSender()]); _transfer(_msgSender(), address(this), amountIn); _approve(address(this), address(swapRouter), amountIn);...
0.8.7
/** * Chooses a random Hunter to steal a fox. * @param seed a random value to choose a Hunter from * @return the owner of the randomly selected Hunter thief */
function _randomHunterOwner(uint256 seed) internal view returns (address) { if (totalMarksmanPointsStaked == 0) { return address(0x0); // use 0x0 to return to msg.sender } // choose a value from 0 to total alpha staked uint256 bucket = (seed & 0xFFFFFFFF) % totalMarksmanPointsStaked; uint256 c...
0.8.10
/* Initializes contract and sets restricted addresses */
function Hedge() { restrictedAddresses[0x0] = true; // Users cannot send tokens to 0x0 address restrictedAddresses[address(this)] = true; // Users cannot sent tokens to this contracts address balances[msg.sender] = 50000000 * 10 ** 18; ...
0.4.11
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value) returns (bool success) { require (block.number > tokenFrozenUntilBlock); // Throw is token is frozen in case of emergency allowances[msg.sender][_spender] = _value; // Set allowance Approval(msg.sender, _spend...
0.4.11
/* Approve and then communicate the approved contract in a single tx */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) { tokenRecipient spender = tokenRecipient(_spender); // Cast spender to tokenRecipient contract approve(_spender, _value); // Set approva...
0.4.11
/*/////////////////////////////////////////////////////////////// INTERNAL UTILS //////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 value) internal { totalSupply += value; // This is safe because the sum of all user // balances can't exceed type(uint256).max! unchecked { balanceOf[to] += value; } emit Transfer(address(0), to, value); }
0.8.7
/* Only use `balanceOf` outside the contract! This will cause high gas fees during minting if called. */
function balanceOf(address account) public view returns (uint256) { uint256 balance = 0; for (uint256 i = 0; i <= supply; i++) { if (balanceOf(account, i) == 1) { balance += 1; } } return balance; }
0.8.4
/** * @dev initialization function * @param _startTime The timestamp of the beginning of the crowdsale * @param _endTime Timestamp when the crowdsale will finish * @param _whitelist contract containing the whitelisted addresses * @param _starToken STAR token contract address * @param _companyToken ERC20 con...
function init( uint256 _startTime, uint256 _endTime, address _whitelist, address _starToken, address _companyToken, uint256 _rate, uint256 _starRate, address _wallet, uint256 _crowdsaleCap, bool _isWeiAccepted ) e...
0.4.24
/** * @dev function that allows token purchases with STAR * @param beneficiary Address of the purchaser */
function buyTokens(address beneficiary) public payable whenNotPaused isWhitelisted(beneficiary) crowdsaleIsTokenOwner { require(beneficiary != address(0)); require(validPurchase() && tokensSold < crowdsaleCap); if (!isWeiAccepted) { ...
0.4.24
/** * @dev See {IERC20-transfer}. * * Unlike `send`, `recipient` is _not_ required to implement the {IERC777Recipient} * interface if it is a contract. * * Also emits a {Sent} event. */
function transfer(address recipient, uint256 amount) public override returns (bool) { require(recipient != address(0), "ERC777: transfer to the zero address"); address from = _msgSender(); _callTokensToSend(from, from, recipient, amount, "", ""); _move(from, from, recipient, am...
0.6.12
/** * @dev See {IERC777-operatorSend}. * * Emits {Sent} and {IERC20-Transfer} events. */
function operatorSend( address sender, address recipient, uint256 amount, bytes memory data, bytes memory operatorData ) public override { require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder"); _send(sen...
0.6.12
/** * @dev See {IERC20-transferFrom}. * * Note that operator and allowance concepts are orthogonal: operators cannot * call `transferFrom` (unless they have allowance), and accounts with * allowance cannot call `operatorSend` (unless they are operators). * * Emits {Sent}, {IERC20-Transfer} and {IERC20-App...
function transferFrom(address holder, address recipient, uint256 amount) public override returns (bool) { require(recipient != address(0), "ERC777: transfer to the zero address"); require(holder != address(0), "ERC777: transfer from the zero address"); address spender = _msgSender(); ...
0.6.12
/** * @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * If a send hook is registered for `account`, the corresponding function * will be called with `operator`, `data` and `operatorData`. * * See {IERC777Sender} and {IERC777Recipient}. * * Emits {Minted} an...
function _mint( address account, uint256 amount, bytes memory userData, bytes memory operatorData ) internal virtual { require(account != address(0), "ERC777: mint to the zero address"); address operator = _msgSender(); _beforeTokenTransf...
0.6.12
/** * @dev Send tokens * @param from address token holder address * @param to address recipient address * @param amount uint256 amount of tokens to transfer * @param userData bytes extra information provided by the token holder (if any) * @param operatorData bytes extra information provided by the operator ...
function _send( address from, address to, uint256 amount, bytes memory userData, bytes memory operatorData, bool requireReceptionAck ) internal { require(from != address(0), "ERC777: send from the zero address"); require(to != ad...
0.6.12
/** * @dev Burn tokens * @param from address token holder address * @param amount uint256 amount of tokens to burn * @param data bytes extra information provided by the token holder * @param operatorData bytes extra information provided by the operator (if any) */
function _burn( address from, uint256 amount, bytes memory data, bytes memory operatorData ) internal virtual { require(from != address(0), "ERC777: burn from the zero address"); address operator = _msgSender(); _beforeTokenTransfer(o...
0.6.12
/** * @dev See {ERC20-_approve}. * * Note that accounts cannot have allowance issued by their operators. */
function _approve(address holder, address spender, uint256 value) internal { require(holder != address(0), "ERC777: approve from the zero address"); require(spender != address(0), "ERC777: approve to the zero address"); _allowances[holder][spender] = value; emit Approval(holder, sp...
0.6.12
////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R]////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R]
function mul(uint256 a, uint256 b) internal pure returns (uint256) {////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R] if (a == 0) {////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R] return 0;}////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4...
0.6.11
//frgwert34rgvfev[4R]EwnqdNBHSUACVRTHHHHHHGFEER15666WERF
function sendValue(address payable recipient, uint256 amount) internal {////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACVRTHHHHHHGFEER15666WERF //frgwert34rgvfev9[4R] require(address(this).balance >= amount, "Address: insufficient balance");///////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HE ...
0.6.11
//frgwert34rgvfev
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {////////sdfert/weh98pWSEI;Jdsewr78039- //frgwert34rgvfev Q70wgQY3HEwnqdNBHSUACV9[4R] require(address(this).balance >= value, "Address: insufficient balance for cal...
0.6.11
//frgwert34rgvfevwgQY3HEwnqdNBHSUACV9[4R]
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3 //frgwert34rgvfevHEwnqdNBHSUACV9[4R]returndata.length > returndata.length > returndata.length > returndata.length > retur...
0.6.11
////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R]SEFWYW
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3EYHERTHHEwFSFnqdNBHSUACV9[4R] _transfer(sender, recipient, amount);////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R]////////sdfe...
0.6.11
////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R]////////sdfert/weh98pWSEI;JdsewRYJ76544536r78039- Q70wgQY3HEwnqdNBHSUACV9[4R]
function _transfer(address sender, address recipient, uint256 amount) internal virtual {////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R] require(sender != address(0), "ERC20: transfer from the zero address");////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSGUACV9[4R] //frgwer...
0.6.11
////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBHSUACV9[4R]S
function _burn(address account, uint256 amount) internal virtual {////////sdfert/weh98pWSEI;Jdsewr78039- QSDFB70wgQY3HEwnqdNBHSUACV9[4R] require(account != address(0), "ERC20: burn from the zero address");////////sdfert/weh98pWSEI;Jdsewr78039- Q70wgQY3HEwnqdNBGSHSUACV9[4R] //frgwert34rgvfev _...
0.6.11
// ----------------------------------- // reset // reset all accounts // in case we have any funds that have not been withdrawn, they become // newly received and undistributed. // -----------------------------------
function reset() { if (msg.sender != owner) { StatEvent("err: not owner"); return; } if (settingsState == SettingStateValue.locked) { StatEvent("err: locked"); return; ...
0.4.8
// ----------------------------------- // set even distribution threshold // -----------------------------------
function setEvenDistThresh(uint256 _thresh) { if (msg.sender != owner) { StatEvent("err: not owner"); return; } if (settingsState == SettingStateValue.locked) { StatEvent("err: locked"); ...
0.4.8
// --------------------------------------------------- // add a new account // ---------------------------------------------------
function addAccount(address _addr, uint256 _pctx10, bool _evenStart) { if (msg.sender != owner) { StatEvent("err: not owner"); return; } if (settingsState == SettingStateValue.locked) { StatEven...
0.4.8
// ---------------------------- // get acct info // ----------------------------
function getAccountInfo(address _addr) constant returns(uint _idx, uint _pctx10, bool _evenStart, uint _credited, uint _balance) { for (uint i = 0; i < numAccounts; i++ ) { address addr = partnerAccounts[i].addr; if (addr == _addr) { ...
0.4.8
// ---------------------------- // get no. accts that are set for even split // ----------------------------
function getNumEvenSplits() constant returns(uint _numEvenSplits) { _numEvenSplits = 0; for (uint i = 0; i < numAccounts; i++ ) { if (partnerAccounts[i].evenStart) { ++_numEvenSplits; } ...
0.4.8
// ---------------------------- // withdraw account balance // ----------------------------
function withdraw() { for (uint i = 0; i < numAccounts; i++ ) { address addr = partnerAccounts[i].addr; if (addr == msg.sender || msg.sender == owner) { uint amount = partnerAccounts[i].balance; ...
0.4.8
/** * @dev Function is used to perform a multi-transfer operation. This could play a significant role in the Ammbr Mesh Routing protocol. * * Mechanics: * Sends tokens from Sender to destinations[0..n] the amount tokens[0..n]. Both arrays * must have the same size, and must have a greater-than-zero length. ...
function multiTransfer(address[] destinations, uint[] tokens) public returns (bool success){ // Two variables must match in length, and must contain elements // Plus, a maximum of 127 transfers are supported assert(destinations.length > 0); assert(destinations.length < 128); ...
0.4.21
// Admin minting function to mint for the team, collabs, customs and giveaways
function mintReserved(uint256 _amount, address _receiver) public onlyOwner { // Limited to a publicly set amount require( _amount <= reserved, "Can't mint more than set amount" ); reserved -= _amount; uint256 supply = totalSupply(); for(uint256 i = 1; i <= _amount; i++){ ...
0.8.7
// Withdraw funds from contract for the team
function withdrawTeam(uint256 amount) public payable onlyOwner { uint256 percent = amount / 100; // 45% Split evenly among the team require(payable(w1).send(percent * 45)); require(payable(w2).send(percent * 45)); // 10% to the community pool require(payable(w3).sen...
0.8.7
/** * Transfer given number of token from the signed defined by digital signature * to given recipient. * * @param _to address to transfer token to the owner of * @param _value number of tokens to transfer * @param _fee number of tokens to give to message sender * @param _nonce nonce of the transfer * @...
function delegatedTransfer ( address _to, uint256 _value, uint256 _fee, uint256 _nonce, uint8 _v, bytes32 _r, bytes32 _s) public virtual returns (bool) { if (frozen) return false; else { address _from = ecrecover ( keccak256 ( abi.encodePacked ( thisAddress...
0.8.0