Unnamed: 0
int64
0
7.36k
comments
stringlengths
3
35.2k
code_string
stringlengths
1
527k
code
stringlengths
1
527k
__index_level_0__
int64
0
88.6k
112
// check if the user receiver the
require(tokenContract.ownerOf(_tokenId) == buyer);
require(tokenContract.ownerOf(_tokenId) == buyer);
30,961
2
// Sets whether a specific address can call a method/_selector The method selector to set access for/_executor The address to set method access for/_canExecute Whether or not the address can execute the specified method
function setCanExecute( bytes4 _selector, address _executor, bool _canExecute ) external { if (_executor == address(this)) { revert CannotAuthoriseSelf(); }
function setCanExecute( bytes4 _selector, address _executor, bool _canExecute ) external { if (_executor == address(this)) { revert CannotAuthoriseSelf(); }
24,011
387
// New combination of mobs.The combination is personalized by players, and refreshed when the dungeon cleared.
function createNewCombination(address _playerAddress) private
function createNewCombination(address _playerAddress) private
73,730
19
// @info options on term `uint options` term_t `uint32 ct` issue_t `uint32 issueDate`
assertEq(options, divRound(3 * maxopts, 4), "2 susp + term");
assertEq(options, divRound(3 * maxopts, 4), "2 susp + term");
17,299
186
// Ensure that the request has had its tokens unlocked.
(bool tokensUnlocked, ) = areTokensUnlocked(execHash); require(tokensUnlocked, "NOT_UNLOCKED");
(bool tokensUnlocked, ) = areTokensUnlocked(execHash); require(tokensUnlocked, "NOT_UNLOCKED");
65,258
454
// Sets the mint states _isPublicMintOpen The public mint is open /
function setMintStates(bool _isPublicMintOpen) external onlyOwner { isPublicOpen = _isPublicMintOpen; }
function setMintStates(bool _isPublicMintOpen) external onlyOwner { isPublicOpen = _isPublicMintOpen; }
25,124
0
// event DebugAddress(address _address);event DebugString(string _string);event DebugUInt(uint _value);event DebugBytes4(bytes4 _signature);
10,553
96
// feeRate(0.1 + 0.9min(1, discountBase / bifiAmount))
feeRateParams.unifiedPoint = 10 ** 18; feeRateParams.minimum = 10 ** 17; feeRateParams.slope = feeRateParams.unifiedPoint - feeRateParams.minimum; feeRateParams.discountRate = _min(feeRateParams.unifiedPoint, handlerFlashloan[handlerID].discountBase.unifiedDiv(bifiBalance)); flashloanFeeRate = flashloanFeeRate.unifiedMul( feeRateParams.minimum.add(feeRateParams.slope.unifiedMul(feeRateParams.discountRate)) );
feeRateParams.unifiedPoint = 10 ** 18; feeRateParams.minimum = 10 ** 17; feeRateParams.slope = feeRateParams.unifiedPoint - feeRateParams.minimum; feeRateParams.discountRate = _min(feeRateParams.unifiedPoint, handlerFlashloan[handlerID].discountBase.unifiedDiv(bifiBalance)); flashloanFeeRate = flashloanFeeRate.unifiedMul( feeRateParams.minimum.add(feeRateParams.slope.unifiedMul(feeRateParams.discountRate)) );
35,591
289
// ========== RESTRICTED GOVERNANCE FUNCTIONS ========== / Adds an AMO
function addAMO(address amo_address, bool sync_too) public onlyByOwnGov { require(amo_address != address(0), "Zero address detected"); (uint256 frax_val_e18, uint256 collat_val_e18) = IAMO(amo_address).dollarBalances(); require(frax_val_e18 >= 0 && collat_val_e18 >= 0, "Invalid AMO"); require(amos[amo_address] == false, "Address already exists"); amos[amo_address] = true; amos_array.push(amo_address); mint_balances[amo_address] = 0; collat_borrowed_balances[amo_address] = 0; if (sync_too) syncDollarBalances(); emit AMOAdded(amo_address); }
function addAMO(address amo_address, bool sync_too) public onlyByOwnGov { require(amo_address != address(0), "Zero address detected"); (uint256 frax_val_e18, uint256 collat_val_e18) = IAMO(amo_address).dollarBalances(); require(frax_val_e18 >= 0 && collat_val_e18 >= 0, "Invalid AMO"); require(amos[amo_address] == false, "Address already exists"); amos[amo_address] = true; amos_array.push(amo_address); mint_balances[amo_address] = 0; collat_borrowed_balances[amo_address] = 0; if (sync_too) syncDollarBalances(); emit AMOAdded(amo_address); }
2,997
105
// Contract constructor/As this contract inherits ownable, msg.sender will become the contract owner/_totlePrimary the address of the contract to be set as totlePrimary
constructor(address _totlePrimary) public { authorizedPrimaries[_totlePrimary] = true; }
constructor(address _totlePrimary) public { authorizedPrimaries[_totlePrimary] = true; }
16,067
17
// getAddresses returns all addresses and fee BPS details. These state variables are private to reduce contract file sizeand to make it more efficient to check all addresses. /
function getAddresses() external view returns (string memory) { return string( abi.encodePacked(
function getAddresses() external view returns (string memory) { return string( abi.encodePacked(
25,231
1
// the owner role is used to set the values in the store.
bytes32 public constant ROLE_OWNER = keccak256("ROLE_OWNER");
bytes32 public constant ROLE_OWNER = keccak256("ROLE_OWNER");
34,665
21
// Awards all external tokens with non-zero balances to the given user.The external tokens must be held by the PrizePool contract./winner The user to transfer the tokens to
function _awardAllExternalTokens(address winner) internal { _awardExternalErc20s(winner); _awardExternalErc721s(winner); }
function _awardAllExternalTokens(address winner) internal { _awardExternalErc20s(winner); _awardExternalErc721s(winner); }
20,980
6
// Redeem the generated interests of an invertible token from thecToken contract. This function will withdraw the generated interests of the cToken, andwill remove the minted amount from the cToken balance of the investor.For more information about the calculation of the generated interests,
* see the {_getTokenGeneratedInterests} function. * * @param _investor The address of the investor. * @param _symbol The symbol of the invertible token. */ function redeemTokenGeneratedInterests(address _investor, bytes32 _symbol) external onlyOwner returns (uint256) { InvertibleToken memory invertibleToken = invertibleTokens[_symbol]; require( address(invertibleToken.token) != address(0), "Invalid token symbol" ); uint256 exchangeRateCurrent = invertibleToken .cToken .exchangeRateCurrent(); uint256 generatedInterests = _getTokenGeneratedInterests( _investor, _symbol, exchangeRateCurrent ); if (generatedInterests == 0) { return 0; } tokenPools[_investor][_symbol].cTokenBalance -= (generatedInterests * 1e18) / exchangeRateCurrent; invertibleToken.cToken.redeemUnderlying(generatedInterests); return generatedInterests; }
* see the {_getTokenGeneratedInterests} function. * * @param _investor The address of the investor. * @param _symbol The symbol of the invertible token. */ function redeemTokenGeneratedInterests(address _investor, bytes32 _symbol) external onlyOwner returns (uint256) { InvertibleToken memory invertibleToken = invertibleTokens[_symbol]; require( address(invertibleToken.token) != address(0), "Invalid token symbol" ); uint256 exchangeRateCurrent = invertibleToken .cToken .exchangeRateCurrent(); uint256 generatedInterests = _getTokenGeneratedInterests( _investor, _symbol, exchangeRateCurrent ); if (generatedInterests == 0) { return 0; } tokenPools[_investor][_symbol].cTokenBalance -= (generatedInterests * 1e18) / exchangeRateCurrent; invertibleToken.cToken.redeemUnderlying(generatedInterests); return generatedInterests; }
27,015
109
// solhint-disable-next-line no-inline-assembly
assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) }
assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) }
57,649
170
// Returns the number of seconds remaining until the beacon period can be complete.return The number of seconds remaining until the beacon period can be complete. /
function beaconPeriodRemainingSeconds() external view returns (uint64);
function beaconPeriodRemainingSeconds() external view returns (uint64);
84,560
33
// Returns the address that signed a hashed message (`hash`) with`signature`. This address can then be used for verification purposes. The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:this function rejects them by requiring the `s` value to be in the lowerhalf order, and the `v` value to be either 27 or 28. IMPORTANT: `hash` _must_ be the result of a hash operation for theverification to be secure: it is possible to craft signatures thatrecover to arbitrary addresses for non-hashed data. A safe way to ensurethis is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; }
* be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; }
1,656
14
// prettier-ignore
if iszero(temp) { break }
if iszero(temp) { break }
1,824
136
// Calculate 2^x.x quadruple precision numberreturn quadruple precision number /
function pow_2 (bytes16 x) internal pure returns (bytes16) { bool xNegative = uint128 (x) > 0x80000000000000000000000000000000; uint256 xExponent = uint128 (x) >> 112 & 0x7FFF; uint256 xSignifier = uint128 (x) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF; if (xExponent == 0x7FFF && xSignifier != 0) return NaN; else if (xExponent > 16397) return xNegative ? POSITIVE_ZERO : POSITIVE_INFINITY; else if (xExponent < 16255) return 0x3FFF0000000000000000000000000000; else { if (xExponent == 0) xExponent = 1; else xSignifier |= 0x10000000000000000000000000000; if (xExponent > 16367) xSignifier <<= xExponent - 16367; else if (xExponent < 16367) xSignifier >>= 16367 - xExponent; if (xNegative && xSignifier > 0x406E00000000000000000000000000000000) return POSITIVE_ZERO; if (!xNegative && xSignifier > 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) return POSITIVE_INFINITY; uint256 resultExponent = xSignifier >> 128; xSignifier &= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; if (xNegative && xSignifier != 0) { xSignifier = ~xSignifier; resultExponent += 1; } uint256 resultSignifier = 0x80000000000000000000000000000000; if (xSignifier & 0x80000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128; if (xSignifier & 0x40000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128; if (xSignifier & 0x20000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128; if (xSignifier & 0x10000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10B5586CF9890F6298B92B71842A98363 >> 128; if (xSignifier & 0x8000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1059B0D31585743AE7C548EB68CA417FD >> 128; if (xSignifier & 0x4000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128; if (xSignifier & 0x2000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128; if (xSignifier & 0x1000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128; if (xSignifier & 0x800000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128; if (xSignifier & 0x400000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128; if (xSignifier & 0x200000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100162F3904051FA128BCA9C55C31E5DF >> 128; if (xSignifier & 0x100000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000B175EFFDC76BA38E31671CA939725 >> 128; if (xSignifier & 0x80000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128; if (xSignifier & 0x40000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128; if (xSignifier & 0x20000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000162E525EE054754457D5995292026 >> 128; if (xSignifier & 0x10000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000B17255775C040618BF4A4ADE83FC >> 128; if (xSignifier & 0x8000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128; if (xSignifier & 0x4000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128; if (xSignifier & 0x2000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000162E43F4F831060E02D839A9D16D >> 128; if (xSignifier & 0x1000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000B1721BCFC99D9F890EA06911763 >> 128; if (xSignifier & 0x800000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128; if (xSignifier & 0x400000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128; if (xSignifier & 0x200000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000162E430E5A18F6119E3C02282A5 >> 128; if (xSignifier & 0x100000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000B1721835514B86E6D96EFD1BFE >> 128; if (xSignifier & 0x80000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128; if (xSignifier & 0x40000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000002C5C8601CC6B9E94213C72737A >> 128; if (xSignifier & 0x20000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000162E42FFF037DF38AA2B219F06 >> 128; if (xSignifier & 0x10000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000B17217FBA9C739AA5819F44F9 >> 128; if (xSignifier & 0x8000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128; if (xSignifier & 0x4000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128; if (xSignifier & 0x2000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000162E42FF0999CE3541B9FFFCF >> 128; if (xSignifier & 0x1000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000B17217F80F4EF5AADDA45554 >> 128; if (xSignifier & 0x800000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000058B90BFBF8479BD5A81B51AD >> 128; if (xSignifier & 0x400000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128; if (xSignifier & 0x200000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000162E42FEFB2FED257559BDAA >> 128; if (xSignifier & 0x100000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128; if (xSignifier & 0x80000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128; if (xSignifier & 0x40000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128; if (xSignifier & 0x20000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000162E42FEFA494F1478FDE05 >> 128; if (xSignifier & 0x10000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000B17217F7D20CF927C8E94C >> 128; if (xSignifier & 0x8000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128; if (xSignifier & 0x4000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000002C5C85FDF477B662B26945 >> 128; if (xSignifier & 0x2000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000162E42FEFA3AE53369388C >> 128; if (xSignifier & 0x1000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000B17217F7D1D351A389D40 >> 128; if (xSignifier & 0x800000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128; if (xSignifier & 0x400000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000002C5C85FDF4741BEA6E77E >> 128; if (xSignifier & 0x200000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000162E42FEFA39FE95583C2 >> 128; if (xSignifier & 0x100000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000B17217F7D1CFB72B45E1 >> 128; if (xSignifier & 0x80000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128; if (xSignifier & 0x40000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000002C5C85FDF473E242EA38 >> 128; if (xSignifier & 0x20000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000162E42FEFA39F02B772C >> 128; if (xSignifier & 0x10000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000B17217F7D1CF7D83C1A >> 128; if (xSignifier & 0x8000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128; if (xSignifier & 0x4000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000002C5C85FDF473DEA871F >> 128; if (xSignifier & 0x2000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000162E42FEFA39EF44D91 >> 128; if (xSignifier & 0x1000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000B17217F7D1CF79E949 >> 128; if (xSignifier & 0x800000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000058B90BFBE8E7BCE544 >> 128; if (xSignifier & 0x400000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000002C5C85FDF473DE6ECA >> 128; if (xSignifier & 0x200000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000162E42FEFA39EF366F >> 128; if (xSignifier & 0x100000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000B17217F7D1CF79AFA >> 128; if (xSignifier & 0x80000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000058B90BFBE8E7BCD6D >> 128; if (xSignifier & 0x40000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000002C5C85FDF473DE6B2 >> 128; if (xSignifier & 0x20000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000162E42FEFA39EF358 >> 128; if (xSignifier & 0x10000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000B17217F7D1CF79AB >> 128; if (xSignifier & 0x8000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000058B90BFBE8E7BCD5 >> 128; if (xSignifier & 0x4000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000002C5C85FDF473DE6A >> 128; if (xSignifier & 0x2000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000162E42FEFA39EF34 >> 128; if (xSignifier & 0x1000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000B17217F7D1CF799 >> 128; if (xSignifier & 0x800000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000058B90BFBE8E7BCC >> 128; if (xSignifier & 0x400000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000002C5C85FDF473DE5 >> 128; if (xSignifier & 0x200000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000162E42FEFA39EF2 >> 128; if (xSignifier & 0x100000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000B17217F7D1CF78 >> 128; if (xSignifier & 0x80000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000058B90BFBE8E7BB >> 128; if (xSignifier & 0x40000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000002C5C85FDF473DD >> 128; if (xSignifier & 0x20000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000162E42FEFA39EE >> 128; if (xSignifier & 0x10000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000B17217F7D1CF6 >> 128; if (xSignifier & 0x8000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000058B90BFBE8E7A >> 128; if (xSignifier & 0x4000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000002C5C85FDF473C >> 128; if (xSignifier & 0x2000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000162E42FEFA39D >> 128; if (xSignifier & 0x1000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000B17217F7D1CE >> 128; if (xSignifier & 0x800000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000058B90BFBE8E6 >> 128; if (xSignifier & 0x400000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000002C5C85FDF472 >> 128; if (xSignifier & 0x200000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000162E42FEFA38 >> 128; if (xSignifier & 0x100000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000B17217F7D1B >> 128; if (xSignifier & 0x80000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000058B90BFBE8D >> 128; if (xSignifier & 0x40000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000002C5C85FDF46 >> 128; if (xSignifier & 0x20000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000162E42FEFA2 >> 128; if (xSignifier & 0x10000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000B17217F7D0 >> 128; if (xSignifier & 0x8000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000058B90BFBE7 >> 128; if (xSignifier & 0x4000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000002C5C85FDF3 >> 128; if (xSignifier & 0x2000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000162E42FEF9 >> 128; if (xSignifier & 0x1000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000B17217F7C >> 128; if (xSignifier & 0x800000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000058B90BFBD >> 128; if (xSignifier & 0x400000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000002C5C85FDE >> 128; if (xSignifier & 0x200000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000162E42FEE >> 128; if (xSignifier & 0x100000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000B17217F6 >> 128; if (xSignifier & 0x80000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000058B90BFA >> 128; if (xSignifier & 0x40000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000002C5C85FC >> 128; if (xSignifier & 0x20000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000162E42FD >> 128; if (xSignifier & 0x10000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000B17217E >> 128; if (xSignifier & 0x8000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000058B90BE >> 128; if (xSignifier & 0x4000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000002C5C85E >> 128; if (xSignifier & 0x2000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000162E42E >> 128; if (xSignifier & 0x1000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000B17216 >> 128; if (xSignifier & 0x800000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000058B90A >> 128; if (xSignifier & 0x400000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000002C5C84 >> 128; if (xSignifier & 0x200000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000162E41 >> 128; if (xSignifier & 0x100000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000B1720 >> 128; if (xSignifier & 0x80000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000058B8F >> 128; if (xSignifier & 0x40000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000002C5C7 >> 128; if (xSignifier & 0x20000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000162E3 >> 128; if (xSignifier & 0x10000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000B171 >> 128; if (xSignifier & 0x8000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000058B8 >> 128; if (xSignifier & 0x4000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000002C5B >> 128; if (xSignifier & 0x2000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000162D >> 128; if (xSignifier & 0x1000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000B16 >> 128; if (xSignifier & 0x800 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000058A >> 128; if (xSignifier & 0x400 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000002C4 >> 128; if (xSignifier & 0x200 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000161 >> 128; if (xSignifier & 0x100 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000000B0 >> 128; if (xSignifier & 0x80 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000057 >> 128; if (xSignifier & 0x40 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000002B >> 128; if (xSignifier & 0x20 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000015 >> 128; if (xSignifier & 0x10 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000000A >> 128; if (xSignifier & 0x8 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000004 >> 128; if (xSignifier & 0x4 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000001 >> 128; if (!xNegative) { resultSignifier = resultSignifier >> 15 & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF; resultExponent += 0x3FFF; } else if (resultExponent <= 0x3FFE) { resultSignifier = resultSignifier >> 15 & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF; resultExponent = 0x3FFF - resultExponent; } else { resultSignifier = resultSignifier >> resultExponent - 16367; resultExponent = 0; } return bytes16 (uint128 (resultExponent << 112 | resultSignifier)); } }
function pow_2 (bytes16 x) internal pure returns (bytes16) { bool xNegative = uint128 (x) > 0x80000000000000000000000000000000; uint256 xExponent = uint128 (x) >> 112 & 0x7FFF; uint256 xSignifier = uint128 (x) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF; if (xExponent == 0x7FFF && xSignifier != 0) return NaN; else if (xExponent > 16397) return xNegative ? POSITIVE_ZERO : POSITIVE_INFINITY; else if (xExponent < 16255) return 0x3FFF0000000000000000000000000000; else { if (xExponent == 0) xExponent = 1; else xSignifier |= 0x10000000000000000000000000000; if (xExponent > 16367) xSignifier <<= xExponent - 16367; else if (xExponent < 16367) xSignifier >>= 16367 - xExponent; if (xNegative && xSignifier > 0x406E00000000000000000000000000000000) return POSITIVE_ZERO; if (!xNegative && xSignifier > 0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) return POSITIVE_INFINITY; uint256 resultExponent = xSignifier >> 128; xSignifier &= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; if (xNegative && xSignifier != 0) { xSignifier = ~xSignifier; resultExponent += 1; } uint256 resultSignifier = 0x80000000000000000000000000000000; if (xSignifier & 0x80000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128; if (xSignifier & 0x40000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128; if (xSignifier & 0x20000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128; if (xSignifier & 0x10000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10B5586CF9890F6298B92B71842A98363 >> 128; if (xSignifier & 0x8000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1059B0D31585743AE7C548EB68CA417FD >> 128; if (xSignifier & 0x4000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128; if (xSignifier & 0x2000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128; if (xSignifier & 0x1000000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128; if (xSignifier & 0x800000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128; if (xSignifier & 0x400000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128; if (xSignifier & 0x200000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100162F3904051FA128BCA9C55C31E5DF >> 128; if (xSignifier & 0x100000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000B175EFFDC76BA38E31671CA939725 >> 128; if (xSignifier & 0x80000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128; if (xSignifier & 0x40000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128; if (xSignifier & 0x20000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000162E525EE054754457D5995292026 >> 128; if (xSignifier & 0x10000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000B17255775C040618BF4A4ADE83FC >> 128; if (xSignifier & 0x8000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128; if (xSignifier & 0x4000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128; if (xSignifier & 0x2000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000162E43F4F831060E02D839A9D16D >> 128; if (xSignifier & 0x1000000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000B1721BCFC99D9F890EA06911763 >> 128; if (xSignifier & 0x800000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128; if (xSignifier & 0x400000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128; if (xSignifier & 0x200000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000162E430E5A18F6119E3C02282A5 >> 128; if (xSignifier & 0x100000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000B1721835514B86E6D96EFD1BFE >> 128; if (xSignifier & 0x80000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128; if (xSignifier & 0x40000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000002C5C8601CC6B9E94213C72737A >> 128; if (xSignifier & 0x20000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000162E42FFF037DF38AA2B219F06 >> 128; if (xSignifier & 0x10000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000B17217FBA9C739AA5819F44F9 >> 128; if (xSignifier & 0x8000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128; if (xSignifier & 0x4000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128; if (xSignifier & 0x2000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000162E42FF0999CE3541B9FFFCF >> 128; if (xSignifier & 0x1000000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000B17217F80F4EF5AADDA45554 >> 128; if (xSignifier & 0x800000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000058B90BFBF8479BD5A81B51AD >> 128; if (xSignifier & 0x400000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128; if (xSignifier & 0x200000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000162E42FEFB2FED257559BDAA >> 128; if (xSignifier & 0x100000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128; if (xSignifier & 0x80000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128; if (xSignifier & 0x40000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128; if (xSignifier & 0x20000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000162E42FEFA494F1478FDE05 >> 128; if (xSignifier & 0x10000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000B17217F7D20CF927C8E94C >> 128; if (xSignifier & 0x8000000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128; if (xSignifier & 0x4000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000002C5C85FDF477B662B26945 >> 128; if (xSignifier & 0x2000000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000162E42FEFA3AE53369388C >> 128; if (xSignifier & 0x1000000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000B17217F7D1D351A389D40 >> 128; if (xSignifier & 0x800000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128; if (xSignifier & 0x400000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000002C5C85FDF4741BEA6E77E >> 128; if (xSignifier & 0x200000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000162E42FEFA39FE95583C2 >> 128; if (xSignifier & 0x100000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000B17217F7D1CFB72B45E1 >> 128; if (xSignifier & 0x80000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128; if (xSignifier & 0x40000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000002C5C85FDF473E242EA38 >> 128; if (xSignifier & 0x20000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000162E42FEFA39F02B772C >> 128; if (xSignifier & 0x10000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000B17217F7D1CF7D83C1A >> 128; if (xSignifier & 0x8000000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128; if (xSignifier & 0x4000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000002C5C85FDF473DEA871F >> 128; if (xSignifier & 0x2000000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000162E42FEFA39EF44D91 >> 128; if (xSignifier & 0x1000000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000B17217F7D1CF79E949 >> 128; if (xSignifier & 0x800000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000058B90BFBE8E7BCE544 >> 128; if (xSignifier & 0x400000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000002C5C85FDF473DE6ECA >> 128; if (xSignifier & 0x200000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000162E42FEFA39EF366F >> 128; if (xSignifier & 0x100000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000B17217F7D1CF79AFA >> 128; if (xSignifier & 0x80000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000058B90BFBE8E7BCD6D >> 128; if (xSignifier & 0x40000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000002C5C85FDF473DE6B2 >> 128; if (xSignifier & 0x20000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000162E42FEFA39EF358 >> 128; if (xSignifier & 0x10000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000B17217F7D1CF79AB >> 128; if (xSignifier & 0x8000000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000058B90BFBE8E7BCD5 >> 128; if (xSignifier & 0x4000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000002C5C85FDF473DE6A >> 128; if (xSignifier & 0x2000000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000162E42FEFA39EF34 >> 128; if (xSignifier & 0x1000000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000B17217F7D1CF799 >> 128; if (xSignifier & 0x800000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000058B90BFBE8E7BCC >> 128; if (xSignifier & 0x400000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000002C5C85FDF473DE5 >> 128; if (xSignifier & 0x200000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000162E42FEFA39EF2 >> 128; if (xSignifier & 0x100000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000B17217F7D1CF78 >> 128; if (xSignifier & 0x80000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000058B90BFBE8E7BB >> 128; if (xSignifier & 0x40000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000002C5C85FDF473DD >> 128; if (xSignifier & 0x20000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000162E42FEFA39EE >> 128; if (xSignifier & 0x10000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000B17217F7D1CF6 >> 128; if (xSignifier & 0x8000000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000058B90BFBE8E7A >> 128; if (xSignifier & 0x4000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000002C5C85FDF473C >> 128; if (xSignifier & 0x2000000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000162E42FEFA39D >> 128; if (xSignifier & 0x1000000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000B17217F7D1CE >> 128; if (xSignifier & 0x800000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000058B90BFBE8E6 >> 128; if (xSignifier & 0x400000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000002C5C85FDF472 >> 128; if (xSignifier & 0x200000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000162E42FEFA38 >> 128; if (xSignifier & 0x100000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000B17217F7D1B >> 128; if (xSignifier & 0x80000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000058B90BFBE8D >> 128; if (xSignifier & 0x40000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000002C5C85FDF46 >> 128; if (xSignifier & 0x20000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000162E42FEFA2 >> 128; if (xSignifier & 0x10000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000B17217F7D0 >> 128; if (xSignifier & 0x8000000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000058B90BFBE7 >> 128; if (xSignifier & 0x4000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000002C5C85FDF3 >> 128; if (xSignifier & 0x2000000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000162E42FEF9 >> 128; if (xSignifier & 0x1000000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000B17217F7C >> 128; if (xSignifier & 0x800000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000058B90BFBD >> 128; if (xSignifier & 0x400000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000002C5C85FDE >> 128; if (xSignifier & 0x200000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000162E42FEE >> 128; if (xSignifier & 0x100000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000B17217F6 >> 128; if (xSignifier & 0x80000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000058B90BFA >> 128; if (xSignifier & 0x40000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000002C5C85FC >> 128; if (xSignifier & 0x20000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000162E42FD >> 128; if (xSignifier & 0x10000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000B17217E >> 128; if (xSignifier & 0x8000000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000058B90BE >> 128; if (xSignifier & 0x4000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000002C5C85E >> 128; if (xSignifier & 0x2000000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000162E42E >> 128; if (xSignifier & 0x1000000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000B17216 >> 128; if (xSignifier & 0x800000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000058B90A >> 128; if (xSignifier & 0x400000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000002C5C84 >> 128; if (xSignifier & 0x200000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000162E41 >> 128; if (xSignifier & 0x100000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000B1720 >> 128; if (xSignifier & 0x80000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000058B8F >> 128; if (xSignifier & 0x40000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000002C5C7 >> 128; if (xSignifier & 0x20000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000162E3 >> 128; if (xSignifier & 0x10000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000B171 >> 128; if (xSignifier & 0x8000 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000058B8 >> 128; if (xSignifier & 0x4000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000002C5B >> 128; if (xSignifier & 0x2000 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000162D >> 128; if (xSignifier & 0x1000 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000B16 >> 128; if (xSignifier & 0x800 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000058A >> 128; if (xSignifier & 0x400 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000002C4 >> 128; if (xSignifier & 0x200 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000161 >> 128; if (xSignifier & 0x100 > 0) resultSignifier = resultSignifier * 0x1000000000000000000000000000000B0 >> 128; if (xSignifier & 0x80 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000057 >> 128; if (xSignifier & 0x40 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000002B >> 128; if (xSignifier & 0x20 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000015 >> 128; if (xSignifier & 0x10 > 0) resultSignifier = resultSignifier * 0x10000000000000000000000000000000A >> 128; if (xSignifier & 0x8 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000004 >> 128; if (xSignifier & 0x4 > 0) resultSignifier = resultSignifier * 0x100000000000000000000000000000001 >> 128; if (!xNegative) { resultSignifier = resultSignifier >> 15 & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF; resultExponent += 0x3FFF; } else if (resultExponent <= 0x3FFE) { resultSignifier = resultSignifier >> 15 & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF; resultExponent = 0x3FFF - resultExponent; } else { resultSignifier = resultSignifier >> resultExponent - 16367; resultExponent = 0; } return bytes16 (uint128 (resultExponent << 112 | resultSignifier)); } }
20,250
26
// 从某个指定的帐户中,向另一个帐户发送代币调用过程,会检查设置的允许最大交易额_from address 发送者地址_to address 接受者地址_value uint256 要转移的代币数量return success是否交易成功 /
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool success) { //检查发送者是否拥有足够余额 require(_value <= allowance[_from][msg.sender]); allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; }
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool success) { //检查发送者是否拥有足够余额 require(_value <= allowance[_from][msg.sender]); allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; }
41,132
151
// simplistic. not accurate
change = asset;
change = asset;
20,634
6
// Data is pasted in FileOutput Order. Blockchain date is skipped because it will be added when the block is mined. 8 Items in total
string memory _file_number = metadata[0]; string memory _title = metadata[1]; string memory _album = metadata[2]; string memory _website = metadata[3]; string memory _ipfs_hash = metadata[4]; string memory _comment = metadata[5]; string memory _copyright = metadata[6]; string memory _submission_date = metadata[7]; string memory _md_hash = metadata[8];
string memory _file_number = metadata[0]; string memory _title = metadata[1]; string memory _album = metadata[2]; string memory _website = metadata[3]; string memory _ipfs_hash = metadata[4]; string memory _comment = metadata[5]; string memory _copyright = metadata[6]; string memory _submission_date = metadata[7]; string memory _md_hash = metadata[8];
56,546
33
// Have to split on the initialization case and negative interest case
if (_valueSupplied > 0 && holdingsValue > _valueSupplied) { adjustedAmount = usedUnderlying - ((holdingsValue - _valueSupplied) * usedUnderlying) / _interestSupply; } else {
if (_valueSupplied > 0 && holdingsValue > _valueSupplied) { adjustedAmount = usedUnderlying - ((holdingsValue - _valueSupplied) * usedUnderlying) / _interestSupply; } else {
24,263
0
// Strings
string public baseURI; string private baseExtension = ".json";
string public baseURI; string private baseExtension = ".json";
25,026
174
// withdraw collateral from existing loan/loanId existing lona id/receiver address of withdrawn tokens/withdrawAmount amount to withdraw/ return actualWithdrawAmount actual amount withdrawn
function withdrawCollateral( bytes32 loanId, address receiver, uint256 withdrawAmount ) external returns (uint256 actualWithdrawAmount);
function withdrawCollateral( bytes32 loanId, address receiver, uint256 withdrawAmount ) external returns (uint256 actualWithdrawAmount);
8,399
4
// sortOrders function should sort BUY Orders from highest price at [0] to lowest at [length -1] should sort SELL orders from lowest price at [0] to highest at [length -1] use bubble sort algorithm. assume pre-ordered array, only one loop of bubble is necessary, new element always at position length -1/
function _sortOrders(Order[] storage _orders, Side _side) private { if (_side == Side.BUY){ // sort BUY Orders from highest price at [0] to lowest at [length -1] uint i = _orders.length > 0 ?_orders.length - 1 : 0; while(i > 0){ if(_orders[i-1].price < _orders[i].price) { // swap if bigger Order memory swap = _orders[i-1]; _orders[i-1] = _orders [i]; _orders[i] = swap; i--; // on to the next } else { // found the right place in the array break; // stop sort } } } if (_side == Side.SELL){ // sort SELL Orders from lowest price at [0] to highest at [length -1] bool sorting = true; uint i = _orders.length > 0 ?_orders.length - 1 : 0; while(sorting && i > 0){ if(_orders[i-1].price > _orders[i].price) { // swap if smaller Order memory swap = _orders[i-1]; _orders[i-1] = _orders [i]; _orders[i] = swap; i--; // on to the next } else { // found the right place in the array sorting = false; // stop sort } } } }
function _sortOrders(Order[] storage _orders, Side _side) private { if (_side == Side.BUY){ // sort BUY Orders from highest price at [0] to lowest at [length -1] uint i = _orders.length > 0 ?_orders.length - 1 : 0; while(i > 0){ if(_orders[i-1].price < _orders[i].price) { // swap if bigger Order memory swap = _orders[i-1]; _orders[i-1] = _orders [i]; _orders[i] = swap; i--; // on to the next } else { // found the right place in the array break; // stop sort } } } if (_side == Side.SELL){ // sort SELL Orders from lowest price at [0] to highest at [length -1] bool sorting = true; uint i = _orders.length > 0 ?_orders.length - 1 : 0; while(sorting && i > 0){ if(_orders[i-1].price > _orders[i].price) { // swap if smaller Order memory swap = _orders[i-1]; _orders[i-1] = _orders [i]; _orders[i] = swap; i--; // on to the next } else { // found the right place in the array sorting = false; // stop sort } } } }
17,260
102
// Send the funds to gambler.
sendFunds(bet.gambler, winAmount == 0 ? 1 wei : winAmount, winAmount, randomNumber.playerNum1, randomNumber.playerNum2, randomNumber.npcNum1, randomNumber.npcNum2, amount);
sendFunds(bet.gambler, winAmount == 0 ? 1 wei : winAmount, winAmount, randomNumber.playerNum1, randomNumber.playerNum2, randomNumber.npcNum1, randomNumber.npcNum2, amount);
49,368
320
// Burn all liquidity from pool to rerange for Sorbetto's balances.
pool.burnAllLiquidity(tickLower, tickUpper);
pool.burnAllLiquidity(tickLower, tickUpper);
14,903
270
// Prevents a contract from calling itself, directly or indirectly.Calling a `nonReentrant` function from another `nonReentrant`function is not supported. It is possible to prevent this from happeningby making the `nonReentrant` function external, and make it call a`private` function that does the actual work. /
modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "RC"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; }
modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "RC"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; }
1,125
45
// setting anyAuth to true allows anyone to call functions protected by onlyAuth
function setAnyAuth(bool access) external onlyOwner { anyAuth = access; }
function setAnyAuth(bool access) external onlyOwner { anyAuth = access; }
46,297
234
// app
ids.appHash = _apporder.hash().toEthTypedStructHash(EIP712DOMAIN_SEPARATOR); ids.appOwner = App(_apporder.app).owner(); require(m_presigned[ids.appHash] || verifySignature(ids.appOwner, ids.appHash, _apporder.sign));
ids.appHash = _apporder.hash().toEthTypedStructHash(EIP712DOMAIN_SEPARATOR); ids.appOwner = App(_apporder.app).owner(); require(m_presigned[ids.appHash] || verifySignature(ids.appOwner, ids.appHash, _apporder.sign));
56,766
26
// populate return array
uint256 index = 0; address currentOwner = owners[SENTINEL_OWNERS]; while (currentOwner != SENTINEL_OWNERS) { array[index] = currentOwner; currentOwner = owners[currentOwner]; index++; }
uint256 index = 0; address currentOwner = owners[SENTINEL_OWNERS]; while (currentOwner != SENTINEL_OWNERS) { array[index] = currentOwner; currentOwner = owners[currentOwner]; index++; }
8,437
298
// A library for validating signatures.
library LibSignature { /// @dev Allowed signature types. enum SignatureType { EIP712, PRESIGNED } /// @dev Encoded EC signature. struct Signature { // How to validate the signature. SignatureType signatureType; // EC Signature data. uint8 v; // EC Signature data. bytes32 r; // EC Signature data. bytes32 s; } }
library LibSignature { /// @dev Allowed signature types. enum SignatureType { EIP712, PRESIGNED } /// @dev Encoded EC signature. struct Signature { // How to validate the signature. SignatureType signatureType; // EC Signature data. uint8 v; // EC Signature data. bytes32 r; // EC Signature data. bytes32 s; } }
43,296
115
// Manually Excluded adresses are transfering tax and lock free
bool isExcluded = (_excluded.contains(sender) || _excluded.contains(recipient));
bool isExcluded = (_excluded.contains(sender) || _excluded.contains(recipient));
29,439
41
// Allow _spender to withdraw from your account, multiple times, up to the _value amount./If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _value) returns (bool success) { require(!frozenAccount[msg.sender]); assert(_spender != address(0)); require(_value >= 0); allowed[msg.sender][_spender] = _value; return true; }
function approve(address _spender, uint256 _value) returns (bool success) { require(!frozenAccount[msg.sender]); assert(_spender != address(0)); require(_value >= 0); allowed[msg.sender][_spender] = _value; return true; }
35,022
37
// first, check the sender credential
assert(msg.sender == uni_pair); // ensure that msg.sender is actually a V2 pair require(sender == address(this), "only this contract may initiate"); assert(amount0 == 0 || amount1 == 0); // this strategy is unidirectional
assert(msg.sender == uni_pair); // ensure that msg.sender is actually a V2 pair require(sender == address(this), "only this contract may initiate"); assert(amount0 == 0 || amount1 == 0); // this strategy is unidirectional
5,642
86
// credit an affiliate for a purchase credit accepts eth and credits the affiliate's balance for the amount_affiliate - the address of the affiliate to credit _purchaseId - the purchaseId of the sale /
function credit( address _affiliate, uint256 _purchaseId) public onlyStoreOrOwner whenNotPaused payable
function credit( address _affiliate, uint256 _purchaseId) public onlyStoreOrOwner whenNotPaused payable
65,800
17
// Deposit to yield pool based on strategy and mint internal asset /
function _depositToYieldPool(address _asset, uint256 _amount) internal override returns (address, uint256)
function _depositToYieldPool(address _asset, uint256 _amount) internal override returns (address, uint256)
20,504
0
// for limit orders
enum Side { BUY, SELL }
enum Side { BUY, SELL }
8,094
126
// Add a new vesting entry at a given time and quantity to an account's schedule. A call to this should accompany a previous successful call to synthetix.transfer(rewardEscrow, amount),to ensure that when the funds are withdrawn, there is enough balance. account The account to append a new vesting entry to. quantity The quantity of SNX that will be escrowed. duration The duration that SNX will be emitted. /
function appendVestingEntry( address account, uint256 quantity, uint256 duration
function appendVestingEntry( address account, uint256 quantity, uint256 duration
31,217
235
// Set allowed minter addresses/to Address to set allowed token minter status/canMint Boolean to set status to for given address
function updateAllowedMinter(address to, bool canMint) external { allowedMinters[to] = canMint; }
function updateAllowedMinter(address to, bool canMint) external { allowedMinters[to] = canMint; }
73,755
48
// Treasury/
contract Treasury is Authorizable { using SafeMath for uint; IVoting voting; KosuToken public kosuToken; struct TokenLock { uint value; uint pollId; uint tokenLockEnd; uint pollEarlyUnlock; } struct Account { uint currentBalance; uint systemBalance; TokenLock[] tokenLocks; mapping(address => bool) proxies; } mapping(address => Account) private accounts; /** @dev Initializes the treasury with the kosuToken and authorizedAddresses contracts. @notice Initializes the treasury with the kosuToken and authorizedAddresses contracts. @param kosuTokenAddress The deployed KosuToken contract address. @param auth AuthorizedAddresses deployed address. */ constructor(address payable kosuTokenAddress, address auth) Authorizable(auth) public { kosuToken = KosuToken(kosuTokenAddress); } /** @dev Set the voting contract after post deployment of the Treasury contract. @notice Set the voting contract after post deployment of the Treasury contract. @param votingAddress address of the deployed Voting contract. */ function setVoting(address votingAddress) isAuthorized public { voting = IVoting(votingAddress); } /** @dev Fallback payable function to allow ether but be bonded and directly deposit tokens into the Treasury. @notice Fallback payable function to allow ether but be bonded and directly deposit tokens into the Treasury. */ function () external payable { _bond(msg.sender); } /** @dev Allows Kosu contracts to bond ether on on the accounts behalf. @notice Allows Kosu contracts to bond ether on on the accounts behalf. @param account The address the calling contract is acting on behalf of. */ function contractBond(address account) isAuthorized payable public returns (uint) { return _bond(account); } /** @dev Deposits tokens into the treasury. @notice Deposits tokens into the treasury. @param amount Number of tokens to deposit. */ function deposit(uint amount) public { _deposit(msg.sender, amount); } /** @dev Allows contracts to deposit tokens from an accounts balance. @notice Allows contracts to deposit tokens from an accounts balance. @param account Account address the tokens will be deposited from. @param amount Number of tokens to deposit. */ function contractDeposit(address account, uint amount) isAuthorized public { _deposit(account, amount); } /** @dev Withdraw tokens from the treasury. @notice Withdraw tokens from the treasury. @param amount Number of tokens to withdraw. */ function withdraw(uint amount) public { require(getCurrentBalance(msg.sender).sub(amount) >= _getLockedTokens(msg.sender), "tokens are locked"); _withdraw(msg.sender, amount); } /** @dev Allows contracts to withdraw tokens back to an account address. @notice Allows contracts to withdraw tokens back to an account address. @param account Address to withdraw tokens for. @param amount Number of tokens to withdraw. */ function contractWithdraw(address account, uint amount) isAuthorized public { _withdraw(account, amount); } /** @dev Allows contracts to claim tokens. Claimed tokens are not available for other system contract and leave the treasury under control of the calling contract. These tokens are still available for voting. @notice Allows contracts to claim tokens. Claimed tokens are not available for other system contract and leave the treasury under control of the calling contract. These tokens are still available for voting. @param account Account to claim tokens from. @param amount Number of tokens to claim. */ function claimTokens(address account, uint amount) isAuthorized public { //Attempt to get more balance if balance is insufficient if(getCurrentBalance(account) < amount) { uint currentBalance = getCurrentBalance(account); uint amountToDeposit = amount.sub(currentBalance); _deposit(account, amountToDeposit); } //Transfer to requesting contract and update balance held in contract require(kosuToken.transfer(msg.sender, amount)); setCurrentBalance(account, getCurrentBalance(account).sub(amount)); } /** @dev Allows contracts to release claimed tokens. Allowing them to be used elsewhere by the user again. @notice Allows contracts to release claimed tokens. Allowing them to be used elsewhere by the user again. @param account Account to release tokens to. @param amount Number of tokens to release. */ function releaseTokens(address account, uint amount) isAuthorized public { //Transfer from requesting contract and update balance held in contract require(kosuToken.transferFrom(msg.sender, address(this), amount)); setCurrentBalance(account, getCurrentBalance(account).add(amount)); } /** @dev Allows contracts to confiscate tokens the account has lost access to. These previously claimed tokens are no longer owned by the account. @notice Allows contracts to confiscate tokens the account has lost access to. These previously claimed tokens are no longer owned by the account. @param account Account to confiscate tokens from. @param amount Number of tokens to confiscate. */ function confiscate(address account, uint amount) isAuthorized public { //Remove the system balance setSystemBalance(account, getSystemBalance(account).sub(amount)); // Require the tokens being confiscated are only tokens already in kosu system contract control require(getSystemBalance(account) >= getCurrentBalance(account), "system balance overburn"); } /** @dev Allows accounts to be rewarded with tokens. These tokens were previously obtained by the calling contract and are now being redistributed to the provided account. @notice Allows accounts to be rewarded with tokens. These tokens were previously obtained by the calling contract and are now being redistributed to the provided account. @param account Account to award tokens to. @param amount Number of tokens to award. */ function award(address account, uint amount) isAuthorized public { //Transfer from requesting contract and update balance held in contract require(kosuToken.transferFrom(msg.sender, address(this), amount)); //Increase current balance setCurrentBalance(account, getCurrentBalance(account).add(amount)); //Increase systemBalance these tokens are new to the account setSystemBalance(account, getSystemBalance(account).add(amount)); } /** @dev Allows contracts to burn an accounts held tokens. @notice Allows contracts to burn an accounts held tokens. @param account Account to burn tokens for. @param amount Number of tokens to burn. */ function burnFrom(address account, uint amount) isAuthorized public { require(getCurrentBalance(account) >= amount, "insufficient current balance"); kosuToken.burn(amount); setCurrentBalance(account, getCurrentBalance(account).sub(amount)); setSystemBalance(account, getSystemBalance(account).sub(amount)); } /** @dev Allows voting contract to register a vote in a poll to ensure tokens aren't removed. @notice Allows voting contract to register a vote in a poll to ensure tokens aren't removed. @param account The account voting. @param pollId The poll the account is voting on. @param amount Number of tokens contributed. @param endBlock Block number vote token lock should expire. @param losingEndBlock Block number vote token lock should expire if vote was in support of a losing option. */ function registerVote(address account, uint pollId, uint amount, uint endBlock, uint losingEndBlock) isAuthorized public returns (bool) { if(getSystemBalance(account) < amount) { return false; } accounts[account].tokenLocks.push(TokenLock(amount, pollId, endBlock, losingEndBlock)); return true; } /** @dev Allows voting contract to register a vote in a poll from a proxy to ensure tokens aren't removed. @notice Allows voting contract to register a vote in a poll from a proxy to ensure tokens aren't removed. @param account The account voting. @param pollId The poll the account is voting on. @param amount Number of tokens contributed. @param endBlock Block number vote token lock should expire. @param losingEndBlock Block number vote token lock should expire if vote was in support of a losing option. */ function registerProxyVote(address proxy, address account, uint pollId, uint amount, uint endBlock, uint losingEndBlock) isAuthorized public returns (bool) { if(getSystemBalance(account) < amount) { return false; } require(isProxyFor(account, proxy), "not valid proxy"); accounts[account].tokenLocks.push(TokenLock(amount, pollId, endBlock, losingEndBlock)); return true; } /** @dev Allows validator registry to lock tokens in treasury after an exit. @notice Allows validator registry to lock tokens in treasury after an exit. @param account The account validator is locking. @param amount Number of tokens to lock. @param endBlock The end of the lock. */ function validatorLock(address account, uint amount, uint endBlock) isAuthorized public { accounts[account].tokenLocks.push(TokenLock( amount, 0, endBlock, 0 )); } /** @dev Allows tokens to determine when all tokens are unlocked for a given account. @notice Allows tokens to determine when all tokens are unlocked for a given account. @param account The account to look at locks for. @return Final block of the last lock to expire. */ function tokenLocksExpire(address account) public returns (uint lastBlock) { _removeInactiveTokenLocks(msg.sender); for(uint i = accounts[account].tokenLocks.length; i > 0; i--) { if(accounts[account].tokenLocks[i - 1].tokenLockEnd > lastBlock) { lastBlock = accounts[account].tokenLocks[i - 1].tokenLockEnd; } } return lastBlock; } /** @dev Reports the total balance within the entire contract system for an account. @notice Reports the total balance within the entire contract system for an account. @param account Account to report balance on. @return The number of tokens within the entire contract system. */ function systemBalance(address account) public view returns (uint) { return getSystemBalance(account); } /** @dev Reports the available balance held within the treasury for an account. @notice Reports the available balance held within the treasury for an account. @param account Account to report balance on. @return Number of available tokens the treasury holds for the account. */ function currentBalance(address account) public view returns (uint) { return getCurrentBalance(account); } /** @dev Authorize voting proxy for treasury balances. @notice Authorize voting proxy for treasury balances. @param proxy Address to allow to vote in proxy. */ function authorizeProxy(address proxy) public { accounts[msg.sender].proxies[proxy] = true; } /** @dev Remove authorization of voting proxy for treasury balance. @notice Remove authorization of voting proxy for treasury balance. @param proxy Address to remove permission to vote in proxy. */ function deauthorizeProxy(address proxy) public { accounts[msg.sender].proxies[proxy] = false; } /** @dev Check proxy authorization for account and proxy addresses. @notice Check proxy authorization for account and proxy addresses. @param account User account with tokens. @param proxy Address to check proxy status. */ function isProxyFor(address account, address proxy) public view returns (bool) { return accounts[account].proxies[proxy]; } // INTERNAL /** @dev Bonds tokens by passing the transaction value to the bonding functions of the KosuToken then provides the added balance to the provided account address. */ function _bond(address account) internal returns (uint) { uint initialBalance = kosuToken.balanceOf(address(this)); uint minted = kosuToken.bondTokens.value(msg.value)(0); require(initialBalance + minted == kosuToken.balanceOf(address(this)), "tokens not minted"); setSystemBalance(account, getSystemBalance(account).add(minted)); setCurrentBalance(account, getCurrentBalance(account).add(minted)); return minted; } /** @dev Transfers tokens from the account address to the treasury. Increases the available and total system balance by the added amount. */ function _deposit(address account, uint amount) internal { //Pulls token from the account and increases both internal ans system balances by the value. require(kosuToken.transferFrom(account, address(this), amount)); setSystemBalance(account, getSystemBalance(account).add(amount)); setCurrentBalance(account, getCurrentBalance(account).add(amount)); } /** @dev Transfers tokens held within the treasury to the provided account address and removes the amount from the accounts available and system balances. */ function _withdraw(address account, uint amount) internal { //Sends tokens to the account reduce the values of internal and system balances by the value. require(getCurrentBalance(account) >= amount, "insufficient tokens"); require(kosuToken.transfer(account, amount)); setSystemBalance(account, getSystemBalance(account).sub(amount)); setCurrentBalance(account, getCurrentBalance(account).sub(amount)); } /** @dev Removes expired locks. */ function _removeInactiveTokenLocks(address account) internal { for(uint i = accounts[account].tokenLocks.length; i > 0; i--) { TokenLock storage v = accounts[account].tokenLocks[i - 1]; (bool finished, uint winningTokens) = voting.userWinningTokens(v.pollId, msg.sender); if(v.pollId > 0 && finished && winningTokens == 0) { v.tokenLockEnd = v.pollEarlyUnlock; } if(v.tokenLockEnd < block.number) { if(i == accounts[account].tokenLocks.length) { delete accounts[account].tokenLocks[i - 1]; accounts[account].tokenLocks.length = accounts[account].tokenLocks.length - 1; } else { accounts[account].tokenLocks[i - 1] = accounts[account].tokenLocks[accounts[account].tokenLocks.length - 1]; delete accounts[account].tokenLocks[accounts[account].tokenLocks.length - 1]; accounts[account].tokenLocks.length = accounts[account].tokenLocks.length - 1; } } } } /** @dev Calculates addresses total locked tokens */ function _getLockedTokens(address account) internal returns (uint) { //cleanup _removeInactiveTokenLocks(account); //Updates the systemBalance for the account uint totalLocked; uint maxVoteLock; for(uint i = 0; i < accounts[account].tokenLocks.length; i++) { TokenLock storage lock = accounts[account].tokenLocks[i]; if(lock.pollId == 0) { totalLocked = totalLocked.add(accounts[account].tokenLocks[i].value); } else { if (lock.value > maxVoteLock) { maxVoteLock = lock.value; } } } return totalLocked + maxVoteLock; } /** @dev Reads the account addresses system balance. */ function getSystemBalance(address account) internal view returns (uint) { //Reports the systemBalance for the account return accounts[account].systemBalance; } /** @dev Sets the accounts system balance. */ function setSystemBalance(address account, uint amount) internal { accounts[account].systemBalance = amount; } /** @dev Reads the accounts current balance. */ function getCurrentBalance(address account) internal view returns (uint) { //Reports the held balance for the account return accounts[account].currentBalance; } /** @dev Sets the accounts current balance. */ function setCurrentBalance(address account, uint amount) internal { //Updates the held balance for the account accounts[account].currentBalance = amount; } }
contract Treasury is Authorizable { using SafeMath for uint; IVoting voting; KosuToken public kosuToken; struct TokenLock { uint value; uint pollId; uint tokenLockEnd; uint pollEarlyUnlock; } struct Account { uint currentBalance; uint systemBalance; TokenLock[] tokenLocks; mapping(address => bool) proxies; } mapping(address => Account) private accounts; /** @dev Initializes the treasury with the kosuToken and authorizedAddresses contracts. @notice Initializes the treasury with the kosuToken and authorizedAddresses contracts. @param kosuTokenAddress The deployed KosuToken contract address. @param auth AuthorizedAddresses deployed address. */ constructor(address payable kosuTokenAddress, address auth) Authorizable(auth) public { kosuToken = KosuToken(kosuTokenAddress); } /** @dev Set the voting contract after post deployment of the Treasury contract. @notice Set the voting contract after post deployment of the Treasury contract. @param votingAddress address of the deployed Voting contract. */ function setVoting(address votingAddress) isAuthorized public { voting = IVoting(votingAddress); } /** @dev Fallback payable function to allow ether but be bonded and directly deposit tokens into the Treasury. @notice Fallback payable function to allow ether but be bonded and directly deposit tokens into the Treasury. */ function () external payable { _bond(msg.sender); } /** @dev Allows Kosu contracts to bond ether on on the accounts behalf. @notice Allows Kosu contracts to bond ether on on the accounts behalf. @param account The address the calling contract is acting on behalf of. */ function contractBond(address account) isAuthorized payable public returns (uint) { return _bond(account); } /** @dev Deposits tokens into the treasury. @notice Deposits tokens into the treasury. @param amount Number of tokens to deposit. */ function deposit(uint amount) public { _deposit(msg.sender, amount); } /** @dev Allows contracts to deposit tokens from an accounts balance. @notice Allows contracts to deposit tokens from an accounts balance. @param account Account address the tokens will be deposited from. @param amount Number of tokens to deposit. */ function contractDeposit(address account, uint amount) isAuthorized public { _deposit(account, amount); } /** @dev Withdraw tokens from the treasury. @notice Withdraw tokens from the treasury. @param amount Number of tokens to withdraw. */ function withdraw(uint amount) public { require(getCurrentBalance(msg.sender).sub(amount) >= _getLockedTokens(msg.sender), "tokens are locked"); _withdraw(msg.sender, amount); } /** @dev Allows contracts to withdraw tokens back to an account address. @notice Allows contracts to withdraw tokens back to an account address. @param account Address to withdraw tokens for. @param amount Number of tokens to withdraw. */ function contractWithdraw(address account, uint amount) isAuthorized public { _withdraw(account, amount); } /** @dev Allows contracts to claim tokens. Claimed tokens are not available for other system contract and leave the treasury under control of the calling contract. These tokens are still available for voting. @notice Allows contracts to claim tokens. Claimed tokens are not available for other system contract and leave the treasury under control of the calling contract. These tokens are still available for voting. @param account Account to claim tokens from. @param amount Number of tokens to claim. */ function claimTokens(address account, uint amount) isAuthorized public { //Attempt to get more balance if balance is insufficient if(getCurrentBalance(account) < amount) { uint currentBalance = getCurrentBalance(account); uint amountToDeposit = amount.sub(currentBalance); _deposit(account, amountToDeposit); } //Transfer to requesting contract and update balance held in contract require(kosuToken.transfer(msg.sender, amount)); setCurrentBalance(account, getCurrentBalance(account).sub(amount)); } /** @dev Allows contracts to release claimed tokens. Allowing them to be used elsewhere by the user again. @notice Allows contracts to release claimed tokens. Allowing them to be used elsewhere by the user again. @param account Account to release tokens to. @param amount Number of tokens to release. */ function releaseTokens(address account, uint amount) isAuthorized public { //Transfer from requesting contract and update balance held in contract require(kosuToken.transferFrom(msg.sender, address(this), amount)); setCurrentBalance(account, getCurrentBalance(account).add(amount)); } /** @dev Allows contracts to confiscate tokens the account has lost access to. These previously claimed tokens are no longer owned by the account. @notice Allows contracts to confiscate tokens the account has lost access to. These previously claimed tokens are no longer owned by the account. @param account Account to confiscate tokens from. @param amount Number of tokens to confiscate. */ function confiscate(address account, uint amount) isAuthorized public { //Remove the system balance setSystemBalance(account, getSystemBalance(account).sub(amount)); // Require the tokens being confiscated are only tokens already in kosu system contract control require(getSystemBalance(account) >= getCurrentBalance(account), "system balance overburn"); } /** @dev Allows accounts to be rewarded with tokens. These tokens were previously obtained by the calling contract and are now being redistributed to the provided account. @notice Allows accounts to be rewarded with tokens. These tokens were previously obtained by the calling contract and are now being redistributed to the provided account. @param account Account to award tokens to. @param amount Number of tokens to award. */ function award(address account, uint amount) isAuthorized public { //Transfer from requesting contract and update balance held in contract require(kosuToken.transferFrom(msg.sender, address(this), amount)); //Increase current balance setCurrentBalance(account, getCurrentBalance(account).add(amount)); //Increase systemBalance these tokens are new to the account setSystemBalance(account, getSystemBalance(account).add(amount)); } /** @dev Allows contracts to burn an accounts held tokens. @notice Allows contracts to burn an accounts held tokens. @param account Account to burn tokens for. @param amount Number of tokens to burn. */ function burnFrom(address account, uint amount) isAuthorized public { require(getCurrentBalance(account) >= amount, "insufficient current balance"); kosuToken.burn(amount); setCurrentBalance(account, getCurrentBalance(account).sub(amount)); setSystemBalance(account, getSystemBalance(account).sub(amount)); } /** @dev Allows voting contract to register a vote in a poll to ensure tokens aren't removed. @notice Allows voting contract to register a vote in a poll to ensure tokens aren't removed. @param account The account voting. @param pollId The poll the account is voting on. @param amount Number of tokens contributed. @param endBlock Block number vote token lock should expire. @param losingEndBlock Block number vote token lock should expire if vote was in support of a losing option. */ function registerVote(address account, uint pollId, uint amount, uint endBlock, uint losingEndBlock) isAuthorized public returns (bool) { if(getSystemBalance(account) < amount) { return false; } accounts[account].tokenLocks.push(TokenLock(amount, pollId, endBlock, losingEndBlock)); return true; } /** @dev Allows voting contract to register a vote in a poll from a proxy to ensure tokens aren't removed. @notice Allows voting contract to register a vote in a poll from a proxy to ensure tokens aren't removed. @param account The account voting. @param pollId The poll the account is voting on. @param amount Number of tokens contributed. @param endBlock Block number vote token lock should expire. @param losingEndBlock Block number vote token lock should expire if vote was in support of a losing option. */ function registerProxyVote(address proxy, address account, uint pollId, uint amount, uint endBlock, uint losingEndBlock) isAuthorized public returns (bool) { if(getSystemBalance(account) < amount) { return false; } require(isProxyFor(account, proxy), "not valid proxy"); accounts[account].tokenLocks.push(TokenLock(amount, pollId, endBlock, losingEndBlock)); return true; } /** @dev Allows validator registry to lock tokens in treasury after an exit. @notice Allows validator registry to lock tokens in treasury after an exit. @param account The account validator is locking. @param amount Number of tokens to lock. @param endBlock The end of the lock. */ function validatorLock(address account, uint amount, uint endBlock) isAuthorized public { accounts[account].tokenLocks.push(TokenLock( amount, 0, endBlock, 0 )); } /** @dev Allows tokens to determine when all tokens are unlocked for a given account. @notice Allows tokens to determine when all tokens are unlocked for a given account. @param account The account to look at locks for. @return Final block of the last lock to expire. */ function tokenLocksExpire(address account) public returns (uint lastBlock) { _removeInactiveTokenLocks(msg.sender); for(uint i = accounts[account].tokenLocks.length; i > 0; i--) { if(accounts[account].tokenLocks[i - 1].tokenLockEnd > lastBlock) { lastBlock = accounts[account].tokenLocks[i - 1].tokenLockEnd; } } return lastBlock; } /** @dev Reports the total balance within the entire contract system for an account. @notice Reports the total balance within the entire contract system for an account. @param account Account to report balance on. @return The number of tokens within the entire contract system. */ function systemBalance(address account) public view returns (uint) { return getSystemBalance(account); } /** @dev Reports the available balance held within the treasury for an account. @notice Reports the available balance held within the treasury for an account. @param account Account to report balance on. @return Number of available tokens the treasury holds for the account. */ function currentBalance(address account) public view returns (uint) { return getCurrentBalance(account); } /** @dev Authorize voting proxy for treasury balances. @notice Authorize voting proxy for treasury balances. @param proxy Address to allow to vote in proxy. */ function authorizeProxy(address proxy) public { accounts[msg.sender].proxies[proxy] = true; } /** @dev Remove authorization of voting proxy for treasury balance. @notice Remove authorization of voting proxy for treasury balance. @param proxy Address to remove permission to vote in proxy. */ function deauthorizeProxy(address proxy) public { accounts[msg.sender].proxies[proxy] = false; } /** @dev Check proxy authorization for account and proxy addresses. @notice Check proxy authorization for account and proxy addresses. @param account User account with tokens. @param proxy Address to check proxy status. */ function isProxyFor(address account, address proxy) public view returns (bool) { return accounts[account].proxies[proxy]; } // INTERNAL /** @dev Bonds tokens by passing the transaction value to the bonding functions of the KosuToken then provides the added balance to the provided account address. */ function _bond(address account) internal returns (uint) { uint initialBalance = kosuToken.balanceOf(address(this)); uint minted = kosuToken.bondTokens.value(msg.value)(0); require(initialBalance + minted == kosuToken.balanceOf(address(this)), "tokens not minted"); setSystemBalance(account, getSystemBalance(account).add(minted)); setCurrentBalance(account, getCurrentBalance(account).add(minted)); return minted; } /** @dev Transfers tokens from the account address to the treasury. Increases the available and total system balance by the added amount. */ function _deposit(address account, uint amount) internal { //Pulls token from the account and increases both internal ans system balances by the value. require(kosuToken.transferFrom(account, address(this), amount)); setSystemBalance(account, getSystemBalance(account).add(amount)); setCurrentBalance(account, getCurrentBalance(account).add(amount)); } /** @dev Transfers tokens held within the treasury to the provided account address and removes the amount from the accounts available and system balances. */ function _withdraw(address account, uint amount) internal { //Sends tokens to the account reduce the values of internal and system balances by the value. require(getCurrentBalance(account) >= amount, "insufficient tokens"); require(kosuToken.transfer(account, amount)); setSystemBalance(account, getSystemBalance(account).sub(amount)); setCurrentBalance(account, getCurrentBalance(account).sub(amount)); } /** @dev Removes expired locks. */ function _removeInactiveTokenLocks(address account) internal { for(uint i = accounts[account].tokenLocks.length; i > 0; i--) { TokenLock storage v = accounts[account].tokenLocks[i - 1]; (bool finished, uint winningTokens) = voting.userWinningTokens(v.pollId, msg.sender); if(v.pollId > 0 && finished && winningTokens == 0) { v.tokenLockEnd = v.pollEarlyUnlock; } if(v.tokenLockEnd < block.number) { if(i == accounts[account].tokenLocks.length) { delete accounts[account].tokenLocks[i - 1]; accounts[account].tokenLocks.length = accounts[account].tokenLocks.length - 1; } else { accounts[account].tokenLocks[i - 1] = accounts[account].tokenLocks[accounts[account].tokenLocks.length - 1]; delete accounts[account].tokenLocks[accounts[account].tokenLocks.length - 1]; accounts[account].tokenLocks.length = accounts[account].tokenLocks.length - 1; } } } } /** @dev Calculates addresses total locked tokens */ function _getLockedTokens(address account) internal returns (uint) { //cleanup _removeInactiveTokenLocks(account); //Updates the systemBalance for the account uint totalLocked; uint maxVoteLock; for(uint i = 0; i < accounts[account].tokenLocks.length; i++) { TokenLock storage lock = accounts[account].tokenLocks[i]; if(lock.pollId == 0) { totalLocked = totalLocked.add(accounts[account].tokenLocks[i].value); } else { if (lock.value > maxVoteLock) { maxVoteLock = lock.value; } } } return totalLocked + maxVoteLock; } /** @dev Reads the account addresses system balance. */ function getSystemBalance(address account) internal view returns (uint) { //Reports the systemBalance for the account return accounts[account].systemBalance; } /** @dev Sets the accounts system balance. */ function setSystemBalance(address account, uint amount) internal { accounts[account].systemBalance = amount; } /** @dev Reads the accounts current balance. */ function getCurrentBalance(address account) internal view returns (uint) { //Reports the held balance for the account return accounts[account].currentBalance; } /** @dev Sets the accounts current balance. */ function setCurrentBalance(address account, uint amount) internal { //Updates the held balance for the account accounts[account].currentBalance = amount; } }
49,356
84
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
mapping(uint256 => address) private _tokenApprovals;
61
38
// Calculate the sUSD cost to buy an amount of available position options from AMM for specific market/game/market The address of the SportPositional market of a game/position The position (home/away/draw) quoted to buy from AMM/amount The position amount quoted to buy from AMM/ return _quote The sUSD cost for buying the `amount` of `position` options (tokens) from AMM for `market`.
function buyFromAmmQuote( address market, ISportsAMM.Position position, uint amount
function buyFromAmmQuote( address market, ISportsAMM.Position position, uint amount
12,886
42
// Updates an asset _assetTicker - Ticker _assetInfo - Info to update _newAmount - % of portfolio taken by the assetreturn True if success /
function updateAnAssetQuantity( string memory _assetTicker, string memory _assetInfo, uint8 _newAmount
function updateAnAssetQuantity( string memory _assetTicker, string memory _assetInfo, uint8 _newAmount
41,927
2
// send all ether to claimer
_claimer.send(this.balance); Claimed(_claimer);
_claimer.send(this.balance); Claimed(_claimer);
33,462
232
// 这里奖励分成了三部分 1,已经从旧奖池中cancel了的 2,还在旧奖池中的 3,在新奖池中的
total = mOldReward[_user]; uint256 iMyOldStaking = 0; for ( uint256 i = 0; i < stakingStorage.getStakesdataLength(_user); i++ ) { (uint256 stakingAmount, ) = stakingStorage.getStakesDataByIndex( _user, i
total = mOldReward[_user]; uint256 iMyOldStaking = 0; for ( uint256 i = 0; i < stakingStorage.getStakesdataLength(_user); i++ ) { (uint256 stakingAmount, ) = stakingStorage.getStakesDataByIndex( _user, i
38,153
21
// --- [ERC1155] Single ERC20 listing ---
function acceptERC20ListingERC1155( IZeroExV4.ERC1155Order calldata order, IZeroExV4.Signature calldata signature, uint128 amount, ERC20ListingParams calldata params, Fee[] calldata fees ) external payable
function acceptERC20ListingERC1155( IZeroExV4.ERC1155Order calldata order, IZeroExV4.Signature calldata signature, uint128 amount, ERC20ListingParams calldata params, Fee[] calldata fees ) external payable
21,589
199
// Collect the curation fees for a subgraph deployment from an amount of tokens.This function transfer curation fees to the Curation contract by calling Curation.collect _graphToken Token to collect _subgraphDeploymentID Subgraph deployment to which the curation fees are related _tokens Total tokens received used to calculate the amount of fees to collect _curationPercentage Percentage of tokens to collect as feesreturn Amount of curation fees /
function _collectCurationFees( IGraphToken _graphToken, bytes32 _subgraphDeploymentID, uint256 _tokens, uint256 _curationPercentage
function _collectCurationFees( IGraphToken _graphToken, bytes32 _subgraphDeploymentID, uint256 _tokens, uint256 _curationPercentage
22,936
449
// Ensure component array only includes one address which will be the currentSet
require( _components.length == 1 && _units.length == 1, "Components & units must be len 1" ); require( _units[0] > 0, "UnitShares not > 0" );
require( _components.length == 1 && _units.length == 1, "Components & units must be len 1" ); require( _units[0] > 0, "UnitShares not > 0" );
12,478
240
// Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex;
_allTokensIndex[lastTokenId] = tokenIndex;
15,234
53
// Allow the owner to withdraw all ether from the contract after the crowdsale is over
function withdrawEtherRemaining() public returns (bool)
function withdrawEtherRemaining() public returns (bool)
48,492
31
// require(minimumBid >= 0, "Marketplace: minimum bid is invalid");
Auction memory newAuction = Auction( msg.sender, minimumBid, address(0), 0, block.timestamp + auctionTime ); contractTokensAuction[nftAddress][tokenId] = true; contractAuction[nftAddress][tokenId] = newAuction;
Auction memory newAuction = Auction( msg.sender, minimumBid, address(0), 0, block.timestamp + auctionTime ); contractTokensAuction[nftAddress][tokenId] = true; contractAuction[nftAddress][tokenId] = newAuction;
34,718
1
// versions: - LinkToken 0.0.3: added versioning, update name- LinkToken 0.0.2: upgraded to solc 0.6- LinkToken 0.0.1: initial release solc 0.4 @inheritdoc ITypeAndVersion /
function typeAndVersion() external pure override virtual returns (string memory)
function typeAndVersion() external pure override virtual returns (string memory)
15,256
55
// Destroys `amount` tokens from `account`, reducing thetotal supply.
* Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); }
* Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); }
14,820
12
// Emitted when the BigBoss dies and is reincarnated
event BossUpgraded(uint256 indexed level, address conqueror, uint256 maxHp, uint256 attackDamage);
event BossUpgraded(uint256 indexed level, address conqueror, uint256 maxHp, uint256 attackDamage);
14,059
25
// the same as withdrawAndDistributePendingRewards() but without claiming from binance staking/might be used for emergency distribution
function distributePendingRewards() external payable onlyConsensus nonReentrant
function distributePendingRewards() external payable onlyConsensus nonReentrant
6,779
123
// Automatic swap and liquify enabled
bool private swapAndLiquifyEnabled = false;
bool private swapAndLiquifyEnabled = false;
7,869
7
// sets maps token to its price _tokenId uint256 token ID (token number) _price uint256 token priceRequirements: `tokenId` must exist`owner` must the msg.owner /
function setTokenPrice(uint256 _tokenId, uint256 _price) public { require(_exists(_tokenId), "ERC721Metadata: Price set of nonexistent token"); require(ownerOf(_tokenId) == _msgSender()); _tokenMeta[_tokenId].price = _price; }
function setTokenPrice(uint256 _tokenId, uint256 _price) public { require(_exists(_tokenId), "ERC721Metadata: Price set of nonexistent token"); require(ownerOf(_tokenId) == _msgSender()); _tokenMeta[_tokenId].price = _price; }
23,382
59
// Info of each user that stakes LP tokens.
mapping (uint256 => mapping (address => UserInfo)) public userInfo;
mapping (uint256 => mapping (address => UserInfo)) public userInfo;
39,706
228
// increases the total borrows at a stable rate on a specific reserve and updates the average stable rate consequently_reserve the reserve object_amount the amount to add to the total borrows stable_rate the rate at which the amount has been borrowed/
) internal { uint256 previousTotalBorrowStable = _reserve.totalBorrowsStable; //updating reserve borrows stable _reserve.totalBorrowsStable = _reserve.totalBorrowsStable.add(_amount); //update the average stable rate //weighted average of all the borrows uint256 weightedLastBorrow = _amount.wadToRay().rayMul(_rate); uint256 weightedPreviousTotalBorrows = previousTotalBorrowStable.wadToRay().rayMul( _reserve.currentAverageStableBorrowRate ); _reserve.currentAverageStableBorrowRate = weightedLastBorrow .add(weightedPreviousTotalBorrows) .rayDiv(_reserve.totalBorrowsStable.wadToRay()); }
) internal { uint256 previousTotalBorrowStable = _reserve.totalBorrowsStable; //updating reserve borrows stable _reserve.totalBorrowsStable = _reserve.totalBorrowsStable.add(_amount); //update the average stable rate //weighted average of all the borrows uint256 weightedLastBorrow = _amount.wadToRay().rayMul(_rate); uint256 weightedPreviousTotalBorrows = previousTotalBorrowStable.wadToRay().rayMul( _reserve.currentAverageStableBorrowRate ); _reserve.currentAverageStableBorrowRate = weightedLastBorrow .add(weightedPreviousTotalBorrows) .rayDiv(_reserve.totalBorrowsStable.wadToRay()); }
24,278
49
// See https:www.binance.charity/binance-charity-wallet/donate-anonymously to confirm this is the right Address
IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; event RewardLiquidityProviders(uint256 tokenAmount); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify(
IUniswapV2Router02 public immutable uniswapV2Router; address public immutable uniswapV2Pair; bool inSwapAndLiquify; bool public swapAndLiquifyEnabled = true; event RewardLiquidityProviders(uint256 tokenAmount); event SwapAndLiquifyEnabledUpdated(bool enabled); event SwapAndLiquify(
6,953
137
// last block number where the user withdrew/deposited tokens
mapping(address => uint256) public lastActivity;
mapping(address => uint256) public lastActivity;
19,237
31
// tranfser amount from sender to the channel
balances[msg.sender] = balances[msg.sender].sub (amount); channels[channelId].value = channels[channelId].value.add(amount); emit ChannelAddFunds(channelId, amount); return true;
balances[msg.sender] = balances[msg.sender].sub (amount); channels[channelId].value = channels[channelId].value.add(amount); emit ChannelAddFunds(channelId, amount); return true;
45,691
9
// Define an internal function '_removeMasterjeweler' to remove this role, called by 'removeMasterjeweler'
function _removeMasterjeweler(address account) internal { masterjewelers.remove(account); emit MasterjewelerRemoved(account); }
function _removeMasterjeweler(address account) internal { masterjewelers.remove(account); emit MasterjewelerRemoved(account); }
9,830
3
// Calculates the total quantity of tokens that can be swapped on the AMMcurve until either 1) the limit price is reached or 2) the swap fills its entire remaining quantity.This function does NOT account for the possibility of concentrated liqbeing knocked in/out as the price on the AMM curve moves across tick boundaries.It's the responsibility of the caller to properly check whether the limit priceis within the bounds of the locally stable curve.As long as CurveState's fee accum fields are conservatively lower bounded,and as long as limitPrice is accurate, then this function rounds down from thetrue real value. At most
internal pure returns (uint128) { uint128 limitFlow = calcLimitFlows(curve, inBaseQty, limitPrice); return limitFlow > swapQty ? swapQty : limitFlow; }
internal pure returns (uint128) { uint128 limitFlow = calcLimitFlows(curve, inBaseQty, limitPrice); return limitFlow > swapQty ? swapQty : limitFlow; }
13,515
21
// These are all the places you can go search for loot
enum Places { TOWN, DUNGEON, CRYPT, CASTLE, DRAGONS_LAIR, THE_ETHER, TAINTED_KINGDOM, OOZING_DEN, ANCIENT_CHAMBER, ORC_GODS }
enum Places { TOWN, DUNGEON, CRYPT, CASTLE, DRAGONS_LAIR, THE_ETHER, TAINTED_KINGDOM, OOZING_DEN, ANCIENT_CHAMBER, ORC_GODS }
38,254
1
// assert(b > 0);Solidity automatically throws when dividing by 0 uint256 c = a / b; assert(a == bc + a % b);There is no case in which this doesn't hold
return a / b;
return a / b;
14,998
385
// in PerksRewards
function redeemBattleCrates() external { uint8 count = 0; uint len = pendingRewards[msg.sender].length; require(len > 0); for (uint i = 0; i < len; i++) { Reward memory rewardStruct = pendingRewards[msg.sender][i]; // can't open on the same timestamp require(block.number > rewardStruct.blocknumber); // ensure user has converted all pendingRewards require(rewardStruct.blocknumber != 0); var hash = block.blockhash(rewardStruct.blocknumber); if (uint(hash) != 0) { // different results for all different crates, even on the same block/same user // randomness is already taken care of uint rand = uint(keccak256(hash, msg.sender, i)); _generateBattleReward(rand,rewardStruct.exp); count++; } else { // Do nothing, no second chances to secure integrity of randomness. } } CratesOpened(msg.sender, count); delete pendingRewards[msg.sender]; }
function redeemBattleCrates() external { uint8 count = 0; uint len = pendingRewards[msg.sender].length; require(len > 0); for (uint i = 0; i < len; i++) { Reward memory rewardStruct = pendingRewards[msg.sender][i]; // can't open on the same timestamp require(block.number > rewardStruct.blocknumber); // ensure user has converted all pendingRewards require(rewardStruct.blocknumber != 0); var hash = block.blockhash(rewardStruct.blocknumber); if (uint(hash) != 0) { // different results for all different crates, even on the same block/same user // randomness is already taken care of uint rand = uint(keccak256(hash, msg.sender, i)); _generateBattleReward(rand,rewardStruct.exp); count++; } else { // Do nothing, no second chances to secure integrity of randomness. } } CratesOpened(msg.sender, count); delete pendingRewards[msg.sender]; }
46,329
59
// Limits the exit fee to the maximum as hard-coded into the contract/withdrawalAmount The amount that is attempting to be withdrawn/exitFee The exit fee to check against the limit/ return The passed exit fee if it is less than the maximum, otherwise the maximum fee is returned.
function _limitExitFee(uint256 withdrawalAmount, uint256 exitFee) internal view returns (uint256) { uint256 maxFee = FixedPoint.multiplyUintByMantissa(withdrawalAmount, maxExitFeeMantissa); if (exitFee > maxFee) { exitFee = maxFee; } return exitFee; }
function _limitExitFee(uint256 withdrawalAmount, uint256 exitFee) internal view returns (uint256) { uint256 maxFee = FixedPoint.multiplyUintByMantissa(withdrawalAmount, maxExitFeeMantissa); if (exitFee > maxFee) { exitFee = maxFee; } return exitFee; }
13,594
5
// An event emitted when a proposal has been executed in the Timelock
event ProposalExecuted(uint id);
event ProposalExecuted(uint id);
1,855
52
// This function is not marked as `nonReentrant` because the underlying mechanism relies on reentrancy
function queryBatchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds
function queryBatchSwap( SwapKind kind, BatchSwapStep[] memory swaps, IAsset[] memory assets, FundManagement memory funds
19,436
13
// Array of all active trove addresses - used to to compute an approximate hint off-chain, for the sorted list insertion
address[] public TroveOwners;
address[] public TroveOwners;
15,135
82
// overflow is desired.
FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112( uint224((priceCumulativeEnd - priceCumulativeStart) / timeElapsed) ); amountOut = priceAverage.mul(amountIn).decode144();
FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112( uint224((priceCumulativeEnd - priceCumulativeStart) / timeElapsed) ); amountOut = priceAverage.mul(amountIn).decode144();
7,680
66
// Only append new addresses to the array, never a duplicate
if (whitelist[newElement] == Status.None) { whitelistIndices.push(newElement); }
if (whitelist[newElement] == Status.None) { whitelistIndices.push(newElement); }
46,159
567
// Returns the sample that corresponds to a given `index`. Using this function instead of accessing storage directly results in denser bytecode (since the storage slot isonly computed here). /
function _getSample(uint256 index) internal view returns (bytes32) { return _samples[index]; }
function _getSample(uint256 index) internal view returns (bytes32) { return _samples[index]; }
6,944
0
// Reserved for V2 GT means Governance Token
mapping(address => bool) public isGTMade; mapping(uint256 => address) public gtMadeByKey; mapping(address => uint256) public iTokenKey; mapping(address => bool) public isStrategy; mapping(uint256 => address) public strategyByKey; mapping(address => bool) public isCalculator; mapping(uint256 => address) public calculatorByKey;
mapping(address => bool) public isGTMade; mapping(uint256 => address) public gtMadeByKey; mapping(address => uint256) public iTokenKey; mapping(address => bool) public isStrategy; mapping(uint256 => address) public strategyByKey; mapping(address => bool) public isCalculator; mapping(uint256 => address) public calculatorByKey;
14,076
37
// Treasury /
function treasuryFunds() public view returns (uint) { return address(this).balance - totalRewardFund(); }
function treasuryFunds() public view returns (uint) { return address(this).balance - totalRewardFund(); }
1,172
143
// Add some extra buffer at the end
result := mload(0x40) mstore(0x40, add(add(result, encodedLen), add(0x20, add(bytesBefore, bytesAfter)))) let tablePtr := mload(0x40) mstore(add(tablePtr, 0x1f), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef') mstore(add(tablePtr, 0x3f), 'ghijklmnopqrstuvwxyz0123456789+/') let resultPtr := add(result, add(32, bytesBefore)) for { let i := 0 } lt(i, len) {
result := mload(0x40) mstore(0x40, add(add(result, encodedLen), add(0x20, add(bytesBefore, bytesAfter)))) let tablePtr := mload(0x40) mstore(add(tablePtr, 0x1f), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef') mstore(add(tablePtr, 0x3f), 'ghijklmnopqrstuvwxyz0123456789+/') let resultPtr := add(result, add(32, bytesBefore)) for { let i := 0 } lt(i, len) {
80,898
47
// token comes from somewhere
emit Transfer(0, _target, _amount);
emit Transfer(0, _target, _amount);
43,123
96
// Don't store ad details on blockchain. Use events as storage as they are significantly cheaper. ads are stored in an array, the id of an ad is its index in this array.
Ad[] ads;
Ad[] ads;
26,413
3
// EVENTS
event PropertyListed(uint256 indexed id, address indexed owner, uint256 price); event PropertySold(uint256 indexed id , address indexed oldOwner, address indexed newOwner, uint256 price); event PropertyResold(uint256 indexed id, address indexed oldOwner, address indexed newOwner, uint256 price);
event PropertyListed(uint256 indexed id, address indexed owner, uint256 price); event PropertySold(uint256 indexed id , address indexed oldOwner, address indexed newOwner, uint256 price); event PropertyResold(uint256 indexed id, address indexed oldOwner, address indexed newOwner, uint256 price);
3,578
108
// Introspects whether an identifier represents an non-fungible token. id Identifier to query.return True if `id` represents an non-fungible token. /
function isNFT(uint256 id) public virtual pure returns (bool) { return (id & _NF_BIT) != 0 && (id & _NF_TOKEN_MASK != 0); }
function isNFT(uint256 id) public virtual pure returns (bool) { return (id & _NF_BIT) != 0 && (id & _NF_TOKEN_MASK != 0); }
42,105
21
// cal weight
uint256[] memory calWeight = new uint256[](_meta.length()+1); for(uint32 i = 0; i < _meta.length(); i++) { calWeight[i] = _weightSlice(_meta, _meta.length()-i); }
uint256[] memory calWeight = new uint256[](_meta.length()+1); for(uint32 i = 0; i < _meta.length(); i++) { calWeight[i] = _weightSlice(_meta, _meta.length()-i); }
6,505
118
// Mapping from Asset Types to count of that type in exsistance
mapping(uint32 => uint64) internal assetTypeTotalCount; mapping(uint32 => uint64) internal assetTypeBurnedCount;
mapping(uint32 => uint64) internal assetTypeTotalCount; mapping(uint32 => uint64) internal assetTypeBurnedCount;
50,862
101
// Emit an event with the results of this order.
emit OrderResult( hash, _order.outline.maker, _taker, settledParameters );
emit OrderResult( hash, _order.outline.maker, _taker, settledParameters );
21,134
90
// The ETH raised from the staking fees collected before boogiePoolActive == true is used to seed the ETH side of the BOOGIE-ETH Uniswap pool. Mint 500,000 new BOOGIE to seed the BOOGIE liquidity in the BOOGIE-ETH Uniswap pool + referral bonus
uint256 initialMintAmount = 500000 * 10**18; boogie.mint(address(this), initialMintAmount); uint256 initialBoogieLiquidity = initialMintAmount.div(2); //Allocate 250k tokens to seed the BOOGIE liquidity in the BOOGIE-ETH Uniswap pool uint256 referralBonusAmount = initialMintAmount.div(2); //Allocate 250k tokens for referral bonus
uint256 initialMintAmount = 500000 * 10**18; boogie.mint(address(this), initialMintAmount); uint256 initialBoogieLiquidity = initialMintAmount.div(2); //Allocate 250k tokens to seed the BOOGIE liquidity in the BOOGIE-ETH Uniswap pool uint256 referralBonusAmount = initialMintAmount.div(2); //Allocate 250k tokens for referral bonus
65,987
122
// Basic checks
require(buyStrikePrice < sellStrikePrice, "buyStrikePrice should be less than sellStrikePrice"); require(controller.isOperator(ownerAddress, address(this)), "You haven't added this contract as an operator");
require(buyStrikePrice < sellStrikePrice, "buyStrikePrice should be less than sellStrikePrice"); require(controller.isOperator(ownerAddress, address(this)), "You haven't added this contract as an operator");
3,955
47
// Called by the delegator on a delegate to forfeit its responsibility /
function _resignImplementation() public;
function _resignImplementation() public;
33,446
38
// Pay previous tokenOwner if owner is not contract
if (oldOwner != address(this)) { oldOwner.transfer(payment); //(1-0.2) }
if (oldOwner != address(this)) { oldOwner.transfer(payment); //(1-0.2) }
21,332
17
// Unilateral Functions / start exit with onchain state
function startExit( address user
function startExit( address user
5,636
39
// Gets owners/ return memory array of owners
function getOwners() public constant returns (address[]) { address[] memory result = new address[](m_numOwners); for (uint i = 0; i < m_numOwners; i++) result[i] = getOwner(i); return result; }
function getOwners() public constant returns (address[]) { address[] memory result = new address[](m_numOwners); for (uint i = 0; i < m_numOwners; i++) result[i] = getOwner(i); return result; }
56,636
3
// Beneficial address
address public beneficial;
address public beneficial;
81,285
24
// Helper function to make safe "blind" Uniswap Swaps by comparing value in vs value out of the swap. Only works for Uniswap V2 or V3 exchanges. assetIn the asset to make a swap with assetOut the asset to get out of the swap amountIn the amount of `assetIn` to swap with, can be type(uint256).max exchange enum value that determines what exchange to make the swap onsee SwapRouter.sol params swap params needed to perform the swap, dependent on which exchange is selectedsee SwapRouter.sol slippage number less than 1e18, defining the max swap slippagereturn amountOut the amount of `assetOut` received from the
function oracleSwap( ERC20 assetIn, ERC20 assetOut, uint256 amountIn, SwapRouter.Exchange exchange, bytes memory params,
function oracleSwap( ERC20 assetIn, ERC20 assetOut, uint256 amountIn, SwapRouter.Exchange exchange, bytes memory params,
3,751
71
// Update the global state due to more time cumulated and/or new BPT staking token amount New BPT staking deposited (can be 0) /
function _updateTotalStaking(uint256 amount) private { uint256 additionalAmountTime = totalStakingAmount.mul(now.sub(lastUpdatedTimestamp)); totalStakingAmount = totalStakingAmount.add(amount); totalStakingAmountTime = totalStakingAmountTime.add(additionalAmountTime); lastUpdatedTimestamp = now; }
function _updateTotalStaking(uint256 amount) private { uint256 additionalAmountTime = totalStakingAmount.mul(now.sub(lastUpdatedTimestamp)); totalStakingAmount = totalStakingAmount.add(amount); totalStakingAmountTime = totalStakingAmountTime.add(additionalAmountTime); lastUpdatedTimestamp = now; }
75,474
27
// The underlying queue data structure stores 2 elements per insertion, so to get the real queue length we need to divide by 2 and subtract 1.
uint256 queueIndex = queueRef.length() / 2 - 1; emit TransactionEnqueued( sender, _target, _gasLimit, _data, queueIndex, block.timestamp );
uint256 queueIndex = queueRef.length() / 2 - 1; emit TransactionEnqueued( sender, _target, _gasLimit, _data, queueIndex, block.timestamp );
27,760
313
// Emit an event to track whitelist activation status changes.
emit WhitelistActiveUpdate(whitelistId, isActive);
emit WhitelistActiveUpdate(whitelistId, isActive);
33,116
76
// Lock token Lockwhich is defined the lock logic /
contract Lock is PausableToken{ mapping(address => uint256) public teamLockTime; // Lock start time mapping(address => uint256) public fundLockTime; // Lock start time uint256 public issueDate =0 ;//issueDate mapping(address => uint256) public teamLocked;// Total Team lock mapping(address => uint256) public fundLocked;// Total fund lock mapping(address => uint256) public teamUsed; // Team Used mapping(address => uint256) public fundUsed; // Fund Used mapping(address => uint256) public teamReverse; // Team reserve mapping(address => uint256) public fundReverse; // Fund reserve /** * @dev Calculate the number of Tokens available for teamAccount * @param _to teamAccount's address */ function teamAvailable(address _to) internal view returns (uint256) { require(teamLockTime[_to]>0); uint256 now1 = block.timestamp; uint256 lockTime = teamLockTime[_to]; uint256 time = now1.sub(lockTime); //Unlocked 20% first uint256 percent = 20; // 20% per 180 days after issue if(time >= 180 days) { percent = (time.div(9 days)) .add(1); } percent = percent > 100 ? 100 : percent; uint256 avail = teamLocked[_to]; require(avail>0); avail = avail.mul(percent).div(100).sub(teamUsed[_to]); return avail ; } /** * @dev Get the number of Tokens available for the current private fund account * @param _to SLGCFundAccount's address **/ function fundAvailable(address _to) internal view returns (uint256) { require(fundLockTime[_to]>0); //The start time of the lock position uint256 lockTime = fundLockTime[_to]; //The interval between the current time and the start time of the lockout uint256 time = block.timestamp.sub(lockTime); //Unlocked 5% first uint256 percent = 5000; //unlocking 58/100000 per day if(time >= 1 days) { percent = percent.add( (((time.sub(1 days)).div (1 days)).add (1)).mul (58)); } percent = percent > 100000 ? 100000 : percent; uint256 avail = fundLocked[_to]; require(avail>0); avail = avail.mul(percent).div(100000).sub(fundUsed[_to]); return avail ; } /** * @dev Team lock * @param _to team lock account's address * @param _value the number of Token */ function teamLock(address _to,uint256 _value) internal { require(_value>0); teamLocked[_to] = teamLocked[_to].add(_value); teamReverse[_to] = teamReverse[_to].add(_value); teamLockTime[_to] = block.timestamp; // Lock start time } /** * @dev Privately offered fund lock * @param _to Privately offered fund account's address * @param _value the number of Token */ function fundLock(address _to,uint256 _value) internal { require(_value>0); fundLocked[_to] =fundLocked[_to].add(_value); fundReverse[_to] = fundReverse[_to].add(_value); if(fundLockTime[_to] == 0) fundLockTime[_to] = block.timestamp; // Lock start time } /** * @dev Team account transaction * @param _to The accept token address * @param _value Number of transactions */ function teamLockTransfer(address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[msg.sender].sub((teamLocked[msg.sender].sub(teamUsed[msg.sender]))+(fundLocked[msg.sender].sub(fundUsed[msg.sender]))); uint256 totalAvail=0; uint256 availTeam =0; if(issueDate==0) { totalAvail = availReverse; } else{ //the number of Tokens available for teamAccount'Locked part availTeam = teamAvailable(msg.sender); //the number of Tokens available for teamAccount totalAvail = availTeam.add(availReverse); } require(_value <= totalAvail); bool ret = super.transfer(_to,_value); if(ret == true && issueDate>0) { //If over the teamAccount's released part if(_value > availTeam){ teamUsed[msg.sender] = teamUsed[msg.sender].add(availTeam); teamReverse[msg.sender] = teamReverse[msg.sender].sub(availTeam); } //If in the teamAccount's released part else{ teamUsed[msg.sender] = teamUsed[msg.sender].add(_value); teamReverse[msg.sender] = teamReverse[msg.sender].sub(_value); } } if(teamUsed[msg.sender] >= teamLocked[msg.sender]){ delete teamLockTime[msg.sender]; delete teamReverse[msg.sender]; } return ret; } /** * @dev Team account authorization transaction * @param _from The give token address * @param _to The accept token address * @param _value Number of transactions */ function teamLockTransferFrom(address _from,address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[_from].sub((teamLocked[_from].sub(teamUsed[_from]))+(fundLocked[_from].sub(fundUsed[_from]))); uint256 totalAvail=0; uint256 availTeam =0; if(issueDate==0) { totalAvail = availReverse; } else{ //the number of Tokens available for teamAccount'Locked part availTeam = teamAvailable(_from); //the number of Tokens available for teamAccount totalAvail = availTeam.add(availReverse); } require(_value <= totalAvail); bool ret = super.transferFrom(_from,_to,_value); if(ret == true && issueDate>0) { //If over the teamAccount's released part if(_value > availTeam){ teamUsed[_from] = teamUsed[_from].add(availTeam); teamReverse[_from] = teamReverse[_from].sub(availTeam); } //If in the teamAccount's released part else{ teamUsed[_from] = teamUsed[_from].add(_value); teamReverse[_from] = teamReverse[_from].sub(_value); } } if(teamUsed[_from] >= teamLocked[_from]){ delete teamLockTime[_from]; delete teamReverse[_from]; } return ret; } /** * @dev Privately Offered Fund Transfer Token * @param _to The accept token address * @param _value Number of transactions */ function fundLockTransfer(address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[msg.sender].sub((teamLocked[msg.sender].sub(teamUsed[msg.sender]))+(fundLocked[msg.sender].sub(fundUsed[msg.sender]))); uint256 totalAvail=0; uint256 availFund = 0; if(issueDate==0) { totalAvail = availReverse; } else{ require(now>issueDate); //the number of Tokens available for SLGCFundAccount'Locked part availFund = fundAvailable(msg.sender); //the number of Tokens available for SLGCFundAccount totalAvail = availFund.add(availReverse); } require(_value <= totalAvail); bool ret = super.transfer(_to,_value); if(ret == true && issueDate>0) { //If over the SLGCFundAccount's released part if(_value > availFund){ fundUsed[msg.sender] = fundUsed[msg.sender].add(availFund); fundReverse[msg.sender] = fundReverse[msg.sender].sub(availFund); } //If in the SLGCFundAccount's released part else{ fundUsed[msg.sender] = fundUsed[msg.sender].add(_value); fundReverse[msg.sender] = fundReverse[msg.sender].sub(_value); } } if(fundUsed[msg.sender] >= fundLocked[msg.sender]){ delete fundLockTime[msg.sender]; delete fundReverse[msg.sender]; } return ret; } /** * @dev Privately Offered Fund Transfer Token * @param _from The give token address * @param _to The accept token address * @param _value Number of transactions */ function fundLockTransferFrom(address _from,address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[_from].sub((teamLocked[_from].sub(teamUsed[_from]))+(fundLocked[_from].sub(fundUsed[_from]))); uint256 totalAvail=0; uint256 availFund = 0; if(issueDate==0) { totalAvail = availReverse; } else{ require(now>issueDate); //the number of Tokens available for SLGCFundAccount'Locked part availFund = fundAvailable(_from); //the number of Tokens available for SLGCFundAccount totalAvail = availFund.add(availReverse); } require(_value <= totalAvail); bool ret = super.transferFrom(_from,_to,_value); if(ret == true && issueDate>0) { //If over the SLGCFundAccount's released part if(_value > availFund){ fundUsed[_from] = fundUsed[_from].add(availFund); fundReverse[_from] = fundReverse[_from].sub(availFund); } //If in the SLGCFundAccount's released part else{ fundUsed[_from] = fundUsed[_from].add(_value); fundReverse[_from] = fundReverse[_from].sub(_value); } } if(fundUsed[_from] >= fundLocked[_from]){ delete fundLockTime[_from]; } return ret; } }
contract Lock is PausableToken{ mapping(address => uint256) public teamLockTime; // Lock start time mapping(address => uint256) public fundLockTime; // Lock start time uint256 public issueDate =0 ;//issueDate mapping(address => uint256) public teamLocked;// Total Team lock mapping(address => uint256) public fundLocked;// Total fund lock mapping(address => uint256) public teamUsed; // Team Used mapping(address => uint256) public fundUsed; // Fund Used mapping(address => uint256) public teamReverse; // Team reserve mapping(address => uint256) public fundReverse; // Fund reserve /** * @dev Calculate the number of Tokens available for teamAccount * @param _to teamAccount's address */ function teamAvailable(address _to) internal view returns (uint256) { require(teamLockTime[_to]>0); uint256 now1 = block.timestamp; uint256 lockTime = teamLockTime[_to]; uint256 time = now1.sub(lockTime); //Unlocked 20% first uint256 percent = 20; // 20% per 180 days after issue if(time >= 180 days) { percent = (time.div(9 days)) .add(1); } percent = percent > 100 ? 100 : percent; uint256 avail = teamLocked[_to]; require(avail>0); avail = avail.mul(percent).div(100).sub(teamUsed[_to]); return avail ; } /** * @dev Get the number of Tokens available for the current private fund account * @param _to SLGCFundAccount's address **/ function fundAvailable(address _to) internal view returns (uint256) { require(fundLockTime[_to]>0); //The start time of the lock position uint256 lockTime = fundLockTime[_to]; //The interval between the current time and the start time of the lockout uint256 time = block.timestamp.sub(lockTime); //Unlocked 5% first uint256 percent = 5000; //unlocking 58/100000 per day if(time >= 1 days) { percent = percent.add( (((time.sub(1 days)).div (1 days)).add (1)).mul (58)); } percent = percent > 100000 ? 100000 : percent; uint256 avail = fundLocked[_to]; require(avail>0); avail = avail.mul(percent).div(100000).sub(fundUsed[_to]); return avail ; } /** * @dev Team lock * @param _to team lock account's address * @param _value the number of Token */ function teamLock(address _to,uint256 _value) internal { require(_value>0); teamLocked[_to] = teamLocked[_to].add(_value); teamReverse[_to] = teamReverse[_to].add(_value); teamLockTime[_to] = block.timestamp; // Lock start time } /** * @dev Privately offered fund lock * @param _to Privately offered fund account's address * @param _value the number of Token */ function fundLock(address _to,uint256 _value) internal { require(_value>0); fundLocked[_to] =fundLocked[_to].add(_value); fundReverse[_to] = fundReverse[_to].add(_value); if(fundLockTime[_to] == 0) fundLockTime[_to] = block.timestamp; // Lock start time } /** * @dev Team account transaction * @param _to The accept token address * @param _value Number of transactions */ function teamLockTransfer(address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[msg.sender].sub((teamLocked[msg.sender].sub(teamUsed[msg.sender]))+(fundLocked[msg.sender].sub(fundUsed[msg.sender]))); uint256 totalAvail=0; uint256 availTeam =0; if(issueDate==0) { totalAvail = availReverse; } else{ //the number of Tokens available for teamAccount'Locked part availTeam = teamAvailable(msg.sender); //the number of Tokens available for teamAccount totalAvail = availTeam.add(availReverse); } require(_value <= totalAvail); bool ret = super.transfer(_to,_value); if(ret == true && issueDate>0) { //If over the teamAccount's released part if(_value > availTeam){ teamUsed[msg.sender] = teamUsed[msg.sender].add(availTeam); teamReverse[msg.sender] = teamReverse[msg.sender].sub(availTeam); } //If in the teamAccount's released part else{ teamUsed[msg.sender] = teamUsed[msg.sender].add(_value); teamReverse[msg.sender] = teamReverse[msg.sender].sub(_value); } } if(teamUsed[msg.sender] >= teamLocked[msg.sender]){ delete teamLockTime[msg.sender]; delete teamReverse[msg.sender]; } return ret; } /** * @dev Team account authorization transaction * @param _from The give token address * @param _to The accept token address * @param _value Number of transactions */ function teamLockTransferFrom(address _from,address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[_from].sub((teamLocked[_from].sub(teamUsed[_from]))+(fundLocked[_from].sub(fundUsed[_from]))); uint256 totalAvail=0; uint256 availTeam =0; if(issueDate==0) { totalAvail = availReverse; } else{ //the number of Tokens available for teamAccount'Locked part availTeam = teamAvailable(_from); //the number of Tokens available for teamAccount totalAvail = availTeam.add(availReverse); } require(_value <= totalAvail); bool ret = super.transferFrom(_from,_to,_value); if(ret == true && issueDate>0) { //If over the teamAccount's released part if(_value > availTeam){ teamUsed[_from] = teamUsed[_from].add(availTeam); teamReverse[_from] = teamReverse[_from].sub(availTeam); } //If in the teamAccount's released part else{ teamUsed[_from] = teamUsed[_from].add(_value); teamReverse[_from] = teamReverse[_from].sub(_value); } } if(teamUsed[_from] >= teamLocked[_from]){ delete teamLockTime[_from]; delete teamReverse[_from]; } return ret; } /** * @dev Privately Offered Fund Transfer Token * @param _to The accept token address * @param _value Number of transactions */ function fundLockTransfer(address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[msg.sender].sub((teamLocked[msg.sender].sub(teamUsed[msg.sender]))+(fundLocked[msg.sender].sub(fundUsed[msg.sender]))); uint256 totalAvail=0; uint256 availFund = 0; if(issueDate==0) { totalAvail = availReverse; } else{ require(now>issueDate); //the number of Tokens available for SLGCFundAccount'Locked part availFund = fundAvailable(msg.sender); //the number of Tokens available for SLGCFundAccount totalAvail = availFund.add(availReverse); } require(_value <= totalAvail); bool ret = super.transfer(_to,_value); if(ret == true && issueDate>0) { //If over the SLGCFundAccount's released part if(_value > availFund){ fundUsed[msg.sender] = fundUsed[msg.sender].add(availFund); fundReverse[msg.sender] = fundReverse[msg.sender].sub(availFund); } //If in the SLGCFundAccount's released part else{ fundUsed[msg.sender] = fundUsed[msg.sender].add(_value); fundReverse[msg.sender] = fundReverse[msg.sender].sub(_value); } } if(fundUsed[msg.sender] >= fundLocked[msg.sender]){ delete fundLockTime[msg.sender]; delete fundReverse[msg.sender]; } return ret; } /** * @dev Privately Offered Fund Transfer Token * @param _from The give token address * @param _to The accept token address * @param _value Number of transactions */ function fundLockTransferFrom(address _from,address _to, uint256 _value) internal returns (bool) { //The remaining part uint256 availReverse = balances[_from].sub((teamLocked[_from].sub(teamUsed[_from]))+(fundLocked[_from].sub(fundUsed[_from]))); uint256 totalAvail=0; uint256 availFund = 0; if(issueDate==0) { totalAvail = availReverse; } else{ require(now>issueDate); //the number of Tokens available for SLGCFundAccount'Locked part availFund = fundAvailable(_from); //the number of Tokens available for SLGCFundAccount totalAvail = availFund.add(availReverse); } require(_value <= totalAvail); bool ret = super.transferFrom(_from,_to,_value); if(ret == true && issueDate>0) { //If over the SLGCFundAccount's released part if(_value > availFund){ fundUsed[_from] = fundUsed[_from].add(availFund); fundReverse[_from] = fundReverse[_from].sub(availFund); } //If in the SLGCFundAccount's released part else{ fundUsed[_from] = fundUsed[_from].add(_value); fundReverse[_from] = fundReverse[_from].sub(_value); } } if(fundUsed[_from] >= fundLocked[_from]){ delete fundLockTime[_from]; } return ret; } }
8,886
0
// this field can be negative
int funds_correction;
int funds_correction;
63,638
8
// return number of the stored document
return index;
return index;
46,920