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 |
|---|---|---|---|---|
5 | // Event to notify one of the characters' requirements to mint differ | event CharacterChange(
uint8 indexed characterId,
uint256 thresholdUser,
uint256 costRune,
bool isActive
);
| event CharacterChange(
uint8 indexed characterId,
uint256 thresholdUser,
uint256 costRune,
bool isActive
);
| 33,194 |
49 | // Allows to remove an owner from the Safe and update the threshold at the same time./This can only be done via a Safe transaction./Removes the owner `owner` from the Safe and updates the threshold to `_threshold`./prevOwner Owner that pointed to the owner to be removed in the linked list/owner Owner address to be removed./_threshold New threshold. | function removeOwner(
address prevOwner,
address owner,
uint256 _threshold
| function removeOwner(
address prevOwner,
address owner,
uint256 _threshold
| 36,598 |
304 | // See {IERC20Permit-DOMAIN_SEPARATOR}./ solhint-disable-next-line func-name-mixedcase | function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
| function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
| 26,870 |
197 | // Returns cluster token to the user. Releases DHV coverage./_pid Cluster pool id./_amount Cluster token amount./_asset Cluster token address./_user User address. | function afterWithdrawHook(
address _asset,
uint256 _amount,
uint256 _pid,
address _user
| function afterWithdrawHook(
address _asset,
uint256 _amount,
uint256 _pid,
address _user
| 34,587 |
20 | // update the swapDurations mapping | swapDurations[_duration] = _is_supported;
| swapDurations[_duration] = _is_supported;
| 75,629 |
43 | // now checking the periods check to see if the stake is locked | uint stakeAge = (block.timestamp - user_lock.since)/(3600*24); // number of days
uint period = user_lock.period * 30; // number of days for lock
require (stakeAge >= period, "You can't unlock now.");
balances[msg.sender].add(user_lock.amount);
userLocks[msg.sender].locks[index].amount = 0;
emit UnlokedSuccesfull(msg.sender, user_lock.amount, period);
| uint stakeAge = (block.timestamp - user_lock.since)/(3600*24); // number of days
uint period = user_lock.period * 30; // number of days for lock
require (stakeAge >= period, "You can't unlock now.");
balances[msg.sender].add(user_lock.amount);
userLocks[msg.sender].locks[index].amount = 0;
emit UnlokedSuccesfull(msg.sender, user_lock.amount, period);
| 41,723 |
34 | // You get icharacter skill leveltool usage rate of the rewardIndex'th reward TODO: This is always going to round down. We cannot have decimal rewards. | uint256 rewardAmountPerBlock = i * characterSkillLevel * toolPowerStats.usageRate;
Reward memory reward = Reward(
rewardsContracts[rewardIndex],
rewardAmountPerBlock * (block.timestamp - playerLastUpdate[_playerAddress])
);
rewards[rewardIndex] = reward;
rewardIndex++;
| uint256 rewardAmountPerBlock = i * characterSkillLevel * toolPowerStats.usageRate;
Reward memory reward = Reward(
rewardsContracts[rewardIndex],
rewardAmountPerBlock * (block.timestamp - playerLastUpdate[_playerAddress])
);
rewards[rewardIndex] = reward;
rewardIndex++;
| 29,316 |
44 | // optional booster module for calculating virtual balances on markets | IFlywheelBooster public immutable flywheelBooster;
| IFlywheelBooster public immutable flywheelBooster;
| 52,442 |
1,086 | // [WETH, BUSD, VAI] or [VAI, BUSD, WETH] | path = new address[](3);
path[0] = _from;
path[1] = intermediate;
path[2] = _to;
| path = new address[](3);
path[0] = _from;
path[1] = intermediate;
path[2] = _to;
| 49,001 |
4 | // Periods should always satisfy range [) | modifier onlyDuringValidPeriod(FN fn) {
checkValidPeriod(fn);
_;
}
| modifier onlyDuringValidPeriod(FN fn) {
checkValidPeriod(fn);
_;
}
| 44,716 |
7 | // Pool utilization that leads to provisional default (as 18-digit decimal) | uint256 public provisionalDefaultUtilization;
| uint256 public provisionalDefaultUtilization;
| 37,701 |
119 | // Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}. Tokens start existing when they are minted (`_mint`),and stop existing when they are burned (`_burn`). / | function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
| function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
| 225 |
19 | // _path = abi.encodePacked(remoteAddress, localAddress) this function set the trusted path for the cross-chain communication | function setTrustedRemote(uint16 _srcChainId, bytes calldata _path) external onlyOwner {
trustedRemoteLookup[_srcChainId] = _path;
emit SetTrustedRemote(_srcChainId, _path);
}
| function setTrustedRemote(uint16 _srcChainId, bytes calldata _path) external onlyOwner {
trustedRemoteLookup[_srcChainId] = _path;
emit SetTrustedRemote(_srcChainId, _path);
}
| 20,839 |
398 | // 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;
}
| 645 |
77 | // updated balances from sales | uint256 ammEndToken0; uint256 ammEndToken1;
(token0Out, token1Out, ammEndToken0, ammEndToken1) = ExecVirtualOrdersLib.computeVirtualBalances(
reserveResult.newReserve0,
reserveResult.newReserve1,
token0SellAmount,
token1SellAmount
);
| uint256 ammEndToken0; uint256 ammEndToken1;
(token0Out, token1Out, ammEndToken0, ammEndToken1) = ExecVirtualOrdersLib.computeVirtualBalances(
reserveResult.newReserve0,
reserveResult.newReserve1,
token0SellAmount,
token1SellAmount
);
| 60,368 |
141 | // emit proposal event | emit NewProposal(id, proposal.start, voteDuration, proposal.proposer, proposal.executor);
| emit NewProposal(id, proposal.start, voteDuration, proposal.proposer, proposal.executor);
| 30,469 |
107 | // This is an alternative to {approve} that can be used as a mitigation forproblems described in {ERC20-approve}. Emits an {Approval} event indicating the updated allowance. Requirements: - `spender` cannot be the zero address.- `spender` must have allowance for the caller of at least`subtractedValue`. / | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'ERC20: decreased allowance below zero'));
return true;
}
| function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'ERC20: decreased allowance below zero'));
return true;
}
| 14,774 |
192 | // Allows admin of the contract to transfer any tokens which are assigned to the contract This method is for safety if by any chance tokens or ETHs are assigned to the contract by mistaketoken Address of the token to be transferreddestination Recepient of the tokenamount Amount of tokens to be transferred/ | function transferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyAdmin
| function transferTokens(
address token,
address payable destination,
uint256 amount
)
external
onlyAdmin
| 2,545 |
191 | // Smart contract library of mathematical functions operating with signed64.64-bit fixed point numbers.Signed 64.64-bit fixed point number isbasically a simple fraction whose numerator is signed 128-bit integer anddenominator is 2^64.As long as denominator is always the same, there is noneed to store it, thus in Solidity signed 64.64-bit fixed point numbers arerepresented by int128 type holding only the numerator. / | library ABDKMath64x64 {
/*
* Minimum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MIN_64x64 = -0x80000000000000000000000000000000;
/*
* Maximum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Convert signed 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromInt (int256 x) internal pure returns (int128) {
unchecked {
require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF);
return int128 (x << 64);
}
}
/**
* Convert signed 64.64 fixed point number into signed 64-bit integer number
* rounding down.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64-bit integer number
*/
function toInt (int128 x) internal pure returns (int64) {
unchecked {
return int64 (x >> 64);
}
}
/**
* Convert unsigned 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromUInt (uint256 x) internal pure returns (int128) {
unchecked {
require (x <= 0x7FFFFFFFFFFFFFFF);
return int128 (int256 (x << 64));
}
}
/**
* Convert signed 64.64 fixed point number into unsigned 64-bit integer
* number rounding down. Revert on underflow.
*
* @param x signed 64.64-bit fixed point number
* @return unsigned 64-bit integer number
*/
function toUInt (int128 x) internal pure returns (uint64) {
unchecked {
require (x >= 0);
return uint64 (uint128 (x >> 64));
}
}
/**
* Convert signed 128.128 fixed point number into signed 64.64-bit fixed point
* number rounding down. Revert on overflow.
*
* @param x signed 128.128-bin fixed point number
* @return signed 64.64-bit fixed point number
*/
function from128x128 (int256 x) internal pure returns (int128) {
unchecked {
int256 result = x >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Convert signed 64.64 fixed point number into signed 128.128 fixed point
* number.
*
* @param x signed 64.64-bit fixed point number
* @return signed 128.128 fixed point number
*/
function to128x128 (int128 x) internal pure returns (int256) {
unchecked {
return int256 (x) << 64;
}
}
/**
* Calculate x + y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function add (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) + y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x - y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sub (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) - y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding down. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function mul (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) * y >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding towards zero, where x is signed 64.64 fixed point
* number and y is signed 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y signed 256-bit integer number
* @return signed 256-bit integer number
*/
function muli (int128 x, int256 y) internal pure returns (int256) {
unchecked {
if (x == MIN_64x64) {
require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF &&
y <= 0x1000000000000000000000000000000000000000000000000);
return -y << 63;
} else {
bool negativeResult = false;
if (x < 0) {
x = -x;
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint256 absoluteResult = mulu (x, uint256 (y));
if (negativeResult) {
require (absoluteResult <=
0x8000000000000000000000000000000000000000000000000000000000000000);
return -int256 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int256 (absoluteResult);
}
}
}
}
/**
* Calculate x * y rounding down, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y unsigned 256-bit integer number
* @return unsigned 256-bit integer number
*/
function mulu (int128 x, uint256 y) internal pure returns (uint256) {
unchecked {
if (y == 0) return 0;
require (x >= 0);
uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64;
uint256 hi = uint256 (int256 (x)) * (y >> 128);
require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
hi <<= 64;
require (hi <=
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo);
return hi + lo;
}
}
/**
* Calculate x / y rounding towards zero. Revert on overflow or when y is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function div (int128 x, int128 y) internal pure returns (int128) {
unchecked {
require (y != 0);
int256 result = (int256 (x) << 64) / y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x / y rounding towards zero, where x and y are signed 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x signed 256-bit integer number
* @param y signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divi (int256 x, int256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
bool negativeResult = false;
if (x < 0) {
x = -x; // We rely on overflow behavior here
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint128 absoluteResult = divuu (uint256 (x), uint256 (y));
if (negativeResult) {
require (absoluteResult <= 0x80000000000000000000000000000000);
return -int128 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int128 (absoluteResult); // We rely on overflow behavior here
}
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divu (uint256 x, uint256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
uint128 result = divuu (x, y);
require (result <= uint128 (MAX_64x64));
return int128 (result);
}
}
/**
* Calculate -x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function neg (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return -x;
}
}
/**
* Calculate |x|. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function abs (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return x < 0 ? -x : x;
}
}
/**
* Calculate 1 / x rounding towards zero. Revert on overflow or when x is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function inv (int128 x) internal pure returns (int128) {
unchecked {
require (x != 0);
int256 result = int256 (0x100000000000000000000000000000000) / x;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function avg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
return int128 ((int256 (x) + int256 (y)) >> 1);
}
}
/**
* Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down.
* Revert on overflow or in case x * y is negative.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function gavg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 m = int256 (x) * int256 (y);
require (m >= 0);
require (m <
0x4000000000000000000000000000000000000000000000000000000000000000);
return int128 (sqrtu (uint256 (m)));
}
}
/**
* Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y uint256 value
* @return signed 64.64-bit fixed point number
*/
function pow (int128 x, uint256 y) internal pure returns (int128) {
unchecked {
bool negative = x < 0 && y & 1 == 1;
uint256 absX = uint128 (x < 0 ? -x : x);
uint256 absResult;
absResult = 0x100000000000000000000000000000000;
if (absX <= 0x10000000000000000) {
absX <<= 63;
while (y != 0) {
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x2 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x4 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x8 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
y >>= 4;
}
absResult >>= 64;
} else {
uint256 absXShift = 63;
if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; }
if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; }
if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; }
if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; }
if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; }
if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; }
uint256 resultShift = 0;
while (y != 0) {
require (absXShift < 64);
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
resultShift += absXShift;
if (absResult > 0x100000000000000000000000000000000) {
absResult >>= 1;
resultShift += 1;
}
}
absX = absX * absX >> 127;
absXShift <<= 1;
if (absX >= 0x100000000000000000000000000000000) {
absX >>= 1;
absXShift += 1;
}
y >>= 1;
}
require (resultShift < 64);
absResult >>= 64 - resultShift;
}
int256 result = negative ? -int256 (absResult) : int256 (absResult);
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate sqrt (x) rounding down. Revert if x < 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sqrt (int128 x) internal pure returns (int128) {
unchecked {
require (x >= 0);
return int128 (sqrtu (uint256 (int256 (x)) << 64));
}
}
/**
* Calculate binary logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function log_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
int256 msb = 0;
int256 xc = x;
if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; }
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
int256 result = msb - 64 << 64;
uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb);
for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) {
ux *= ux;
uint256 b = ux >> 255;
ux >>= 127 + b;
result += bit * int256 (b);
}
return int128 (result);
}
}
/**
* Calculate natural logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function ln (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
return int128 (int256 (
uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128));
}
}
/**
* Calculate binary exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
uint256 result = 0x80000000000000000000000000000000;
if (x & 0x8000000000000000 > 0)
result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128;
if (x & 0x4000000000000000 > 0)
result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128;
if (x & 0x2000000000000000 > 0)
result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128;
if (x & 0x1000000000000000 > 0)
result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128;
if (x & 0x800000000000000 > 0)
result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128;
if (x & 0x400000000000000 > 0)
result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128;
if (x & 0x200000000000000 > 0)
result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128;
if (x & 0x100000000000000 > 0)
result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128;
if (x & 0x80000000000000 > 0)
result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128;
if (x & 0x40000000000000 > 0)
result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128;
if (x & 0x20000000000000 > 0)
result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128;
if (x & 0x10000000000000 > 0)
result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128;
if (x & 0x8000000000000 > 0)
result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128;
if (x & 0x4000000000000 > 0)
result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128;
if (x & 0x2000000000000 > 0)
result = result * 0x1000162E525EE054754457D5995292026 >> 128;
if (x & 0x1000000000000 > 0)
result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128;
if (x & 0x800000000000 > 0)
result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128;
if (x & 0x400000000000 > 0)
result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128;
if (x & 0x200000000000 > 0)
result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128;
if (x & 0x100000000000 > 0)
result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128;
if (x & 0x80000000000 > 0)
result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128;
if (x & 0x40000000000 > 0)
result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128;
if (x & 0x20000000000 > 0)
result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128;
if (x & 0x10000000000 > 0)
result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128;
if (x & 0x8000000000 > 0)
result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128;
if (x & 0x4000000000 > 0)
result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128;
if (x & 0x2000000000 > 0)
result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128;
if (x & 0x1000000000 > 0)
result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128;
if (x & 0x800000000 > 0)
result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128;
if (x & 0x400000000 > 0)
result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128;
if (x & 0x200000000 > 0)
result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128;
if (x & 0x100000000 > 0)
result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128;
if (x & 0x80000000 > 0)
result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128;
if (x & 0x40000000 > 0)
result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128;
if (x & 0x20000000 > 0)
result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128;
if (x & 0x10000000 > 0)
result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128;
if (x & 0x8000000 > 0)
result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128;
if (x & 0x4000000 > 0)
result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128;
if (x & 0x2000000 > 0)
result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128;
if (x & 0x1000000 > 0)
result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128;
if (x & 0x800000 > 0)
result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128;
if (x & 0x400000 > 0)
result = result * 0x100000000002C5C85FDF477B662B26945 >> 128;
if (x & 0x200000 > 0)
result = result * 0x10000000000162E42FEFA3AE53369388C >> 128;
if (x & 0x100000 > 0)
result = result * 0x100000000000B17217F7D1D351A389D40 >> 128;
if (x & 0x80000 > 0)
result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128;
if (x & 0x40000 > 0)
result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128;
if (x & 0x20000 > 0)
result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128;
if (x & 0x10000 > 0)
result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128;
if (x & 0x8000 > 0)
result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128;
if (x & 0x4000 > 0)
result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128;
if (x & 0x2000 > 0)
result = result * 0x1000000000000162E42FEFA39F02B772C >> 128;
if (x & 0x1000 > 0)
result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128;
if (x & 0x800 > 0)
result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128;
if (x & 0x400 > 0)
result = result * 0x100000000000002C5C85FDF473DEA871F >> 128;
if (x & 0x200 > 0)
result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128;
if (x & 0x100 > 0)
result = result * 0x100000000000000B17217F7D1CF79E949 >> 128;
if (x & 0x80 > 0)
result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128;
if (x & 0x40 > 0)
result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128;
if (x & 0x20 > 0)
result = result * 0x100000000000000162E42FEFA39EF366F >> 128;
if (x & 0x10 > 0)
result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128;
if (x & 0x8 > 0)
result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128;
if (x & 0x4 > 0)
result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128;
if (x & 0x2 > 0)
result = result * 0x1000000000000000162E42FEFA39EF358 >> 128;
if (x & 0x1 > 0)
result = result * 0x10000000000000000B17217F7D1CF79AB >> 128;
result >>= uint256 (int256 (63 - (x >> 64)));
require (result <= uint256 (int256 (MAX_64x64)));
return int128 (int256 (result));
}
}
/**
* Calculate natural exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
return exp_2 (
int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128));
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return unsigned 64.64-bit fixed point number
*/
function divuu (uint256 x, uint256 y) private pure returns (uint128) {
unchecked {
require (y != 0);
uint256 result;
if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
result = (x << 64) / y;
else {
uint256 msb = 192;
uint256 xc = x >> 192;
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1);
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 hi = result * (y >> 128);
uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 xh = x >> 192;
uint256 xl = x << 64;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
lo = hi << 128;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
assert (xh == hi >> 128);
result += xl / y;
}
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return uint128 (result);
}
}
/**
* Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer
* number.
*
* @param x unsigned 256-bit integer number
* @return unsigned 128-bit integer number
*/
function sqrtu (uint256 x) private pure returns (uint128) {
unchecked {
if (x == 0) return 0;
else {
uint256 xx = x;
uint256 r = 1;
if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; }
if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; }
if (xx >= 0x100000000) { xx >>= 32; r <<= 16; }
if (xx >= 0x10000) { xx >>= 16; r <<= 8; }
if (xx >= 0x100) { xx >>= 8; r <<= 4; }
if (xx >= 0x10) { xx >>= 4; r <<= 2; }
if (xx >= 0x8) { r <<= 1; }
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1; // Seven iterations should be enough
uint256 r1 = x / r;
return uint128 (r < r1 ? r : r1);
}
}
}
}
| library ABDKMath64x64 {
/*
* Minimum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MIN_64x64 = -0x80000000000000000000000000000000;
/*
* Maximum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Convert signed 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromInt (int256 x) internal pure returns (int128) {
unchecked {
require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF);
return int128 (x << 64);
}
}
/**
* Convert signed 64.64 fixed point number into signed 64-bit integer number
* rounding down.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64-bit integer number
*/
function toInt (int128 x) internal pure returns (int64) {
unchecked {
return int64 (x >> 64);
}
}
/**
* Convert unsigned 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromUInt (uint256 x) internal pure returns (int128) {
unchecked {
require (x <= 0x7FFFFFFFFFFFFFFF);
return int128 (int256 (x << 64));
}
}
/**
* Convert signed 64.64 fixed point number into unsigned 64-bit integer
* number rounding down. Revert on underflow.
*
* @param x signed 64.64-bit fixed point number
* @return unsigned 64-bit integer number
*/
function toUInt (int128 x) internal pure returns (uint64) {
unchecked {
require (x >= 0);
return uint64 (uint128 (x >> 64));
}
}
/**
* Convert signed 128.128 fixed point number into signed 64.64-bit fixed point
* number rounding down. Revert on overflow.
*
* @param x signed 128.128-bin fixed point number
* @return signed 64.64-bit fixed point number
*/
function from128x128 (int256 x) internal pure returns (int128) {
unchecked {
int256 result = x >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Convert signed 64.64 fixed point number into signed 128.128 fixed point
* number.
*
* @param x signed 64.64-bit fixed point number
* @return signed 128.128 fixed point number
*/
function to128x128 (int128 x) internal pure returns (int256) {
unchecked {
return int256 (x) << 64;
}
}
/**
* Calculate x + y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function add (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) + y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x - y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sub (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) - y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding down. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function mul (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) * y >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding towards zero, where x is signed 64.64 fixed point
* number and y is signed 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y signed 256-bit integer number
* @return signed 256-bit integer number
*/
function muli (int128 x, int256 y) internal pure returns (int256) {
unchecked {
if (x == MIN_64x64) {
require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF &&
y <= 0x1000000000000000000000000000000000000000000000000);
return -y << 63;
} else {
bool negativeResult = false;
if (x < 0) {
x = -x;
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint256 absoluteResult = mulu (x, uint256 (y));
if (negativeResult) {
require (absoluteResult <=
0x8000000000000000000000000000000000000000000000000000000000000000);
return -int256 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int256 (absoluteResult);
}
}
}
}
/**
* Calculate x * y rounding down, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y unsigned 256-bit integer number
* @return unsigned 256-bit integer number
*/
function mulu (int128 x, uint256 y) internal pure returns (uint256) {
unchecked {
if (y == 0) return 0;
require (x >= 0);
uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64;
uint256 hi = uint256 (int256 (x)) * (y >> 128);
require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
hi <<= 64;
require (hi <=
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo);
return hi + lo;
}
}
/**
* Calculate x / y rounding towards zero. Revert on overflow or when y is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function div (int128 x, int128 y) internal pure returns (int128) {
unchecked {
require (y != 0);
int256 result = (int256 (x) << 64) / y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x / y rounding towards zero, where x and y are signed 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x signed 256-bit integer number
* @param y signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divi (int256 x, int256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
bool negativeResult = false;
if (x < 0) {
x = -x; // We rely on overflow behavior here
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint128 absoluteResult = divuu (uint256 (x), uint256 (y));
if (negativeResult) {
require (absoluteResult <= 0x80000000000000000000000000000000);
return -int128 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int128 (absoluteResult); // We rely on overflow behavior here
}
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divu (uint256 x, uint256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
uint128 result = divuu (x, y);
require (result <= uint128 (MAX_64x64));
return int128 (result);
}
}
/**
* Calculate -x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function neg (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return -x;
}
}
/**
* Calculate |x|. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function abs (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return x < 0 ? -x : x;
}
}
/**
* Calculate 1 / x rounding towards zero. Revert on overflow or when x is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function inv (int128 x) internal pure returns (int128) {
unchecked {
require (x != 0);
int256 result = int256 (0x100000000000000000000000000000000) / x;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function avg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
return int128 ((int256 (x) + int256 (y)) >> 1);
}
}
/**
* Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down.
* Revert on overflow or in case x * y is negative.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function gavg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 m = int256 (x) * int256 (y);
require (m >= 0);
require (m <
0x4000000000000000000000000000000000000000000000000000000000000000);
return int128 (sqrtu (uint256 (m)));
}
}
/**
* Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y uint256 value
* @return signed 64.64-bit fixed point number
*/
function pow (int128 x, uint256 y) internal pure returns (int128) {
unchecked {
bool negative = x < 0 && y & 1 == 1;
uint256 absX = uint128 (x < 0 ? -x : x);
uint256 absResult;
absResult = 0x100000000000000000000000000000000;
if (absX <= 0x10000000000000000) {
absX <<= 63;
while (y != 0) {
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x2 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x4 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x8 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
y >>= 4;
}
absResult >>= 64;
} else {
uint256 absXShift = 63;
if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; }
if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; }
if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; }
if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; }
if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; }
if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; }
uint256 resultShift = 0;
while (y != 0) {
require (absXShift < 64);
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
resultShift += absXShift;
if (absResult > 0x100000000000000000000000000000000) {
absResult >>= 1;
resultShift += 1;
}
}
absX = absX * absX >> 127;
absXShift <<= 1;
if (absX >= 0x100000000000000000000000000000000) {
absX >>= 1;
absXShift += 1;
}
y >>= 1;
}
require (resultShift < 64);
absResult >>= 64 - resultShift;
}
int256 result = negative ? -int256 (absResult) : int256 (absResult);
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate sqrt (x) rounding down. Revert if x < 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sqrt (int128 x) internal pure returns (int128) {
unchecked {
require (x >= 0);
return int128 (sqrtu (uint256 (int256 (x)) << 64));
}
}
/**
* Calculate binary logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function log_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
int256 msb = 0;
int256 xc = x;
if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; }
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
int256 result = msb - 64 << 64;
uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb);
for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) {
ux *= ux;
uint256 b = ux >> 255;
ux >>= 127 + b;
result += bit * int256 (b);
}
return int128 (result);
}
}
/**
* Calculate natural logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function ln (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
return int128 (int256 (
uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128));
}
}
/**
* Calculate binary exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
uint256 result = 0x80000000000000000000000000000000;
if (x & 0x8000000000000000 > 0)
result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128;
if (x & 0x4000000000000000 > 0)
result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128;
if (x & 0x2000000000000000 > 0)
result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128;
if (x & 0x1000000000000000 > 0)
result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128;
if (x & 0x800000000000000 > 0)
result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128;
if (x & 0x400000000000000 > 0)
result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128;
if (x & 0x200000000000000 > 0)
result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128;
if (x & 0x100000000000000 > 0)
result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128;
if (x & 0x80000000000000 > 0)
result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128;
if (x & 0x40000000000000 > 0)
result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128;
if (x & 0x20000000000000 > 0)
result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128;
if (x & 0x10000000000000 > 0)
result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128;
if (x & 0x8000000000000 > 0)
result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128;
if (x & 0x4000000000000 > 0)
result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128;
if (x & 0x2000000000000 > 0)
result = result * 0x1000162E525EE054754457D5995292026 >> 128;
if (x & 0x1000000000000 > 0)
result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128;
if (x & 0x800000000000 > 0)
result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128;
if (x & 0x400000000000 > 0)
result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128;
if (x & 0x200000000000 > 0)
result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128;
if (x & 0x100000000000 > 0)
result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128;
if (x & 0x80000000000 > 0)
result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128;
if (x & 0x40000000000 > 0)
result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128;
if (x & 0x20000000000 > 0)
result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128;
if (x & 0x10000000000 > 0)
result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128;
if (x & 0x8000000000 > 0)
result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128;
if (x & 0x4000000000 > 0)
result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128;
if (x & 0x2000000000 > 0)
result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128;
if (x & 0x1000000000 > 0)
result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128;
if (x & 0x800000000 > 0)
result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128;
if (x & 0x400000000 > 0)
result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128;
if (x & 0x200000000 > 0)
result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128;
if (x & 0x100000000 > 0)
result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128;
if (x & 0x80000000 > 0)
result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128;
if (x & 0x40000000 > 0)
result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128;
if (x & 0x20000000 > 0)
result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128;
if (x & 0x10000000 > 0)
result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128;
if (x & 0x8000000 > 0)
result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128;
if (x & 0x4000000 > 0)
result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128;
if (x & 0x2000000 > 0)
result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128;
if (x & 0x1000000 > 0)
result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128;
if (x & 0x800000 > 0)
result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128;
if (x & 0x400000 > 0)
result = result * 0x100000000002C5C85FDF477B662B26945 >> 128;
if (x & 0x200000 > 0)
result = result * 0x10000000000162E42FEFA3AE53369388C >> 128;
if (x & 0x100000 > 0)
result = result * 0x100000000000B17217F7D1D351A389D40 >> 128;
if (x & 0x80000 > 0)
result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128;
if (x & 0x40000 > 0)
result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128;
if (x & 0x20000 > 0)
result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128;
if (x & 0x10000 > 0)
result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128;
if (x & 0x8000 > 0)
result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128;
if (x & 0x4000 > 0)
result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128;
if (x & 0x2000 > 0)
result = result * 0x1000000000000162E42FEFA39F02B772C >> 128;
if (x & 0x1000 > 0)
result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128;
if (x & 0x800 > 0)
result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128;
if (x & 0x400 > 0)
result = result * 0x100000000000002C5C85FDF473DEA871F >> 128;
if (x & 0x200 > 0)
result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128;
if (x & 0x100 > 0)
result = result * 0x100000000000000B17217F7D1CF79E949 >> 128;
if (x & 0x80 > 0)
result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128;
if (x & 0x40 > 0)
result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128;
if (x & 0x20 > 0)
result = result * 0x100000000000000162E42FEFA39EF366F >> 128;
if (x & 0x10 > 0)
result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128;
if (x & 0x8 > 0)
result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128;
if (x & 0x4 > 0)
result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128;
if (x & 0x2 > 0)
result = result * 0x1000000000000000162E42FEFA39EF358 >> 128;
if (x & 0x1 > 0)
result = result * 0x10000000000000000B17217F7D1CF79AB >> 128;
result >>= uint256 (int256 (63 - (x >> 64)));
require (result <= uint256 (int256 (MAX_64x64)));
return int128 (int256 (result));
}
}
/**
* Calculate natural exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
return exp_2 (
int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128));
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return unsigned 64.64-bit fixed point number
*/
function divuu (uint256 x, uint256 y) private pure returns (uint128) {
unchecked {
require (y != 0);
uint256 result;
if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
result = (x << 64) / y;
else {
uint256 msb = 192;
uint256 xc = x >> 192;
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1);
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 hi = result * (y >> 128);
uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 xh = x >> 192;
uint256 xl = x << 64;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
lo = hi << 128;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
assert (xh == hi >> 128);
result += xl / y;
}
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return uint128 (result);
}
}
/**
* Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer
* number.
*
* @param x unsigned 256-bit integer number
* @return unsigned 128-bit integer number
*/
function sqrtu (uint256 x) private pure returns (uint128) {
unchecked {
if (x == 0) return 0;
else {
uint256 xx = x;
uint256 r = 1;
if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; }
if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; }
if (xx >= 0x100000000) { xx >>= 32; r <<= 16; }
if (xx >= 0x10000) { xx >>= 16; r <<= 8; }
if (xx >= 0x100) { xx >>= 8; r <<= 4; }
if (xx >= 0x10) { xx >>= 4; r <<= 2; }
if (xx >= 0x8) { r <<= 1; }
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1; // Seven iterations should be enough
uint256 r1 = x / r;
return uint128 (r < r1 ? r : r1);
}
}
}
}
| 7,402 |
131 | // Sets the treasury mint percentage of rebase / | event NewRebaseMintPercent(uint256 oldRebaseMintPerc, uint256 newRebaseMintPerc);
| event NewRebaseMintPercent(uint256 oldRebaseMintPerc, uint256 newRebaseMintPerc);
| 19,020 |
1 | // @custom:security-contact cossacks@mail.io | contract Cossacks is ERC20, Ownable {
constructor() ERC20("Cossacks", "CSKS") {
_mint(msg.sender, 444444444444444 * 10 ** decimals());
}
}
| contract Cossacks is ERC20, Ownable {
constructor() ERC20("Cossacks", "CSKS") {
_mint(msg.sender, 444444444444444 * 10 ** decimals());
}
}
| 25,388 |
8 | // The Ownable constructor sets the original `owner` of the contract to the sender account./ | function Ownable() public {
owner = msg.sender;
}
| function Ownable() public {
owner = msg.sender;
}
| 25,793 |
356 | // _withUpdate :reserved / | function addPool(ERC20 _token, bool _withUpdate) public onlyGovernance {
require(tokenOfPid[address(_token)] == 0, "Token is exists.");
address _spToken = _createToken("Supply-Provider Token", tokenPrefix.concat(_token.symbol()), _token.decimals());
lendPoolInfo.push(
CompoundLendPool({
token: address(_token),
spToken: _spToken,
curSupply: 0,
curBorrow: 0,
totalRecvInterests: 0
})
);
tokenOfPid[address(_token)] = lendPoolInfo.length - 1;
spTokenOfPid[address(_spToken)] = tokenOfPid[address(_token)];
authSpTokenMap[_spToken] = true;
borrowCompound.addBorrowPool(address(_token),_spToken);
emit AddPoolEvent(msg.sender,address(_token),0,_withUpdate);
}
| function addPool(ERC20 _token, bool _withUpdate) public onlyGovernance {
require(tokenOfPid[address(_token)] == 0, "Token is exists.");
address _spToken = _createToken("Supply-Provider Token", tokenPrefix.concat(_token.symbol()), _token.decimals());
lendPoolInfo.push(
CompoundLendPool({
token: address(_token),
spToken: _spToken,
curSupply: 0,
curBorrow: 0,
totalRecvInterests: 0
})
);
tokenOfPid[address(_token)] = lendPoolInfo.length - 1;
spTokenOfPid[address(_spToken)] = tokenOfPid[address(_token)];
authSpTokenMap[_spToken] = true;
borrowCompound.addBorrowPool(address(_token),_spToken);
emit AddPoolEvent(msg.sender,address(_token),0,_withUpdate);
}
| 59,891 |
1 | // past requests Id. | uint256[] public requestIds;
uint256 public lastRequestId;
| uint256[] public requestIds;
uint256 public lastRequestId;
| 22,691 |
4 | // Withdraws all Cheemscoin to dev address Purpose is so exchange funds can be allocated elsewhere if needed | function withdraw() public {
require(msg.sender == dev, "Only dev can withdraw");
uint256 exchangeBalance = cheemscoin.balanceOf(address(this));
require(exchangeBalance > 0, "Exchange has no funds");
cheemscoin.transfer(dev, exchangeBalance);
}
| function withdraw() public {
require(msg.sender == dev, "Only dev can withdraw");
uint256 exchangeBalance = cheemscoin.balanceOf(address(this));
require(exchangeBalance > 0, "Exchange has no funds");
cheemscoin.transfer(dev, exchangeBalance);
}
| 23,709 |
4 | // Address of CouponTokenCampaign contract | address public couponTokenCampaignAddr;
| address public couponTokenCampaignAddr;
| 8,513 |
20 | // Only used when claiming more bonds than fits into a transaction Stored in a mapping indexed by question_id. | struct Claim {
address payee;
uint256 last_bond;
uint256 queued_funds;
}
| struct Claim {
address payee;
uint256 last_bond;
uint256 queued_funds;
}
| 34,207 |
51 | // Updates issuer ownership, only callable by Sygnum operator. issuer_ The new issuer. / | function updateIssuer(address issuer_) public onlyOperator {
_issuer = issuer_;
emit IssuerUpdated(msg.sender, _issuer, address(this));
}
| function updateIssuer(address issuer_) public onlyOperator {
_issuer = issuer_;
emit IssuerUpdated(msg.sender, _issuer, address(this));
}
| 11,090 |
10 | // Transfers ownership of the contract to a new account (`newOwner`).Can only be called by the current owner. / | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
| function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
| 13,449 |
5 | // function mint(address _to, uint _amount) external; |
function mint(address _account, uint256 _amount) external returns (bool);
|
function mint(address _account, uint256 _amount) external returns (bool);
| 687 |
302 | // remove sub tokenIds itself | _subTokens[tokenId].remove(_subTokenId);
| _subTokens[tokenId].remove(_subTokenId);
| 76,860 |
58 | // calculate the amounts needed to move the price to the next target if it is possible or as much as possible | (currentPrice, step.input, step.output, step.feeAmount) = PriceMovementMath.movePriceTowardsTarget(
zeroToOne,
currentPrice,
(zeroToOne == (step.nextTickPrice < limitSqrtPrice)) // move the price to the target or to the limit
? limitSqrtPrice
: step.nextTickPrice,
currentLiquidity,
amountRequired,
cache.fee
);
| (currentPrice, step.input, step.output, step.feeAmount) = PriceMovementMath.movePriceTowardsTarget(
zeroToOne,
currentPrice,
(zeroToOne == (step.nextTickPrice < limitSqrtPrice)) // move the price to the target or to the limit
? limitSqrtPrice
: step.nextTickPrice,
currentLiquidity,
amountRequired,
cache.fee
);
| 28,076 |
0 | // The interchain state root. | bytes32 public stateRoot;
| bytes32 public stateRoot;
| 48,828 |
336 | // Internal view function that, given an action type and arguments,will return the action ID or message hash that will need to be prefixed(according to EIP-191 0x45), hashed, and signed by the key designated bythe Dharma Key Registry in order to construct a valid signature for thecorresponding action. The current nonce will be supplied to this functionwhen reconstructing an action ID during protected function execution basedon the supplied parameters. action uint8 The type of action, designated by it's index. Validactions in V8 include Cancel (0), SetUserSigningKey (1), Generic (2),GenericAtomicBatch (3), DAIWithdrawal (10), USDCWithdrawal (5),ETHWithdrawal (6), SetEscapeHatch (7), RemoveEscapeHatch (8), andDisableEscapeHatch (9). | function _getActionID(
ActionType action,
bytes memory arguments,
uint256 nonce,
uint256 minimumActionGas,
address userSigningKey,
address dharmaSigningKey
| function _getActionID(
ActionType action,
bytes memory arguments,
uint256 nonce,
uint256 minimumActionGas,
address userSigningKey,
address dharmaSigningKey
| 9,889 |
8 | // Creates (or resets if previously existed) a new pool template associatedwith an arbitrary pool index. After calling, any pair's pool initializedat this index will be created using this template. Previously existing pools at this index will not be updated by this call, and must be individually reset. This is only a consideration if thetemplate is being reset, as a pool can't be created at an index beore atemplate exists.poolIdx The arbitrary index for which this template will be created. After calling, any user will be able to initialize a pool with thistemplate in any pair by using this pool index. | internal {
PoolSpecs.Pool storage templ = templates_[poolIdx];
templ.schema_ = PoolSpecs.BASE_SCHEMA;
templ.feeRate_ = feeRate;
templ.tickSize_ = tickSize;
templ.jitThresh_ = jitThresh;
templ.knockoutBits_ = knockout;
templ.oracleFlags_ = oracleFlags;
// If template is set to use a permissioned oracle, validate that the oracle address is a
// valid oracle contract
address oracle = PoolSpecs.oracleForPool(poolIdx, oracleFlags);
if (oracle != address(0)) {
require(oracle.code.length > 0 && ICrocPermitOracle(oracle).acceptsPermitOracle(),
"Oracle");
}
}
| internal {
PoolSpecs.Pool storage templ = templates_[poolIdx];
templ.schema_ = PoolSpecs.BASE_SCHEMA;
templ.feeRate_ = feeRate;
templ.tickSize_ = tickSize;
templ.jitThresh_ = jitThresh;
templ.knockoutBits_ = knockout;
templ.oracleFlags_ = oracleFlags;
// If template is set to use a permissioned oracle, validate that the oracle address is a
// valid oracle contract
address oracle = PoolSpecs.oracleForPool(poolIdx, oracleFlags);
if (oracle != address(0)) {
require(oracle.code.length > 0 && ICrocPermitOracle(oracle).acceptsPermitOracle(),
"Oracle");
}
}
| 9,188 |
104 | // Shortcut for the actual value | if (_block >= _checkpoints[_checkpoints.length-1].fromBlock)
return _checkpoints[_checkpoints.length-1].value;
if (_block < _checkpoints[0].fromBlock)
return 0;
| if (_block >= _checkpoints[_checkpoints.length-1].fromBlock)
return _checkpoints[_checkpoints.length-1].value;
if (_block < _checkpoints[0].fromBlock)
return 0;
| 78,691 |
13 | // amount {BU}/ return erc20s The addresses of the ERC20 tokens in the reference basket/ return quantities {qTok} The quantity of each ERC20 token to issue `amount` baskets | function quote(uint192 amount, RoundingMode rounding)
external
view
returns (address[] memory erc20s, uint256[] memory quantities);
| function quote(uint192 amount, RoundingMode rounding)
external
view
returns (address[] memory erc20s, uint256[] memory quantities);
| 20,851 |
22 | // Adds the minter role to provided address/Requires owner role to interact/_who is address to add role/ return A boolean that indicates if the operation was successful. | function addMinter(address _who) public onlyOwner returns (bool) {
_setMinter(_who, true);
}
| function addMinter(address _who) public onlyOwner returns (bool) {
_setMinter(_who, true);
}
| 32,301 |
5 | // Useful for when user wants to return tokens to get a refund,or when they want to transfer lots of tokens by paying gas fee only once. / | function transferFromBulk(
address from,
address to,
uint256[] memory tokenIds
| function transferFromBulk(
address from,
address to,
uint256[] memory tokenIds
| 13,251 |
37 | // Grant the items to the caller | balances[id][dst] = quantity.safeAdd(balances[id][dst]);
| balances[id][dst] = quantity.safeAdd(balances[id][dst]);
| 16,420 |
45 | // Increase the amount of tokens that an owner allowed to a spender. approve should be called when allowed[spender] == 0. To increment allowed value is better to use this function to avoid 2 calls (and wait until the first transaction is mined) | function increaseApproval(address spender, uint256 addedValue) public returns (bool) {
allowed[msg.sender][spender] = (allowed[msg.sender][spender].add(addedValue));
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
return true;
}
| function increaseApproval(address spender, uint256 addedValue) public returns (bool) {
allowed[msg.sender][spender] = (allowed[msg.sender][spender].add(addedValue));
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
return true;
}
| 7,390 |
43 | // solhint-disable-next-line avoid-low-level-calls | (bool success, bytes memory returndata) =
| (bool success, bytes memory returndata) =
| 636 |
43 | // to recieve ETH from uniswapV2Router when swaping | receive() external payable {}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
| receive() external payable {}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
| 845 |
79 | // Get the amount of name signal a curator has on a name pool. _graphAccount Subgraph owner _subgraphNumber Subgraph owners subgraph number which was curated on by nameCurators _curator Curator to look up to see n signal balancereturn Amount of name signal owned by a curator for the name pool / | function getCuratorNSignal(
address _graphAccount,
uint256 _subgraphNumber,
address _curator
| function getCuratorNSignal(
address _graphAccount,
uint256 _subgraphNumber,
address _curator
| 31,323 |
9 | // Check sender address and compare it to an owner. / | modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call this function.");
_;
}
| modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call this function.");
_;
}
| 34,316 |
203 | // decides if round end needs to be run & new round started.and if player unmasked earnings from previously played rounds need to be moved. | {
// if player has played a previous round, move their unmasked earnings
// from that round to gen vault.
if (plyr_[_pID].lrnd != 0)
updateGenVault(_pID, plyr_[_pID].lrnd);
// update player's last round played
plyr_[_pID].lrnd = rID_;
// set the joined round bool to true
_eventData_.compressedData = _eventData_.compressedData + 10;
return(_eventData_);
}
| {
// if player has played a previous round, move their unmasked earnings
// from that round to gen vault.
if (plyr_[_pID].lrnd != 0)
updateGenVault(_pID, plyr_[_pID].lrnd);
// update player's last round played
plyr_[_pID].lrnd = rID_;
// set the joined round bool to true
_eventData_.compressedData = _eventData_.compressedData + 10;
return(_eventData_);
}
| 73,449 |
13 | // makes the whitelist check unenforced / | function disableWhitelist()
external
onlyOwner()
| function disableWhitelist()
external
onlyOwner()
| 35,556 |
72 | // | begin(выкликать,Вин)
entry выкликать : ГЛАГОЛ
{
ВИД : СОВЕРШ
ПЕРЕХОДНОСТЬ:ПЕРЕХОДНЫЙ
НАКЛОНЕНИЕ:ИЗЪЯВ ВРЕМЯ:БУДУЩЕЕ ЛИЦО:1 ЧИСЛО:ЕД { [выкличу stress="в^ыкличу"] }
| begin(выкликать,Вин)
entry выкликать : ГЛАГОЛ
{
ВИД : СОВЕРШ
ПЕРЕХОДНОСТЬ:ПЕРЕХОДНЫЙ
НАКЛОНЕНИЕ:ИЗЪЯВ ВРЕМЯ:БУДУЩЕЕ ЛИЦО:1 ЧИСЛО:ЕД { [выкличу stress="в^ыкличу"] }
| 41,356 |
9 | // block progression if asset has defaulted, terminated or reached maturity | require(
contractPerformance == ContractPerformance.PF
|| contractPerformance == ContractPerformance.DL
|| contractPerformance == ContractPerformance.DQ,
"BaseActor.processEvent: ASSET_REACHED_FINAL_STATE"
);
(EventType eventType, uint256 scheduleTime) = decodeEvent(_event);
| require(
contractPerformance == ContractPerformance.PF
|| contractPerformance == ContractPerformance.DL
|| contractPerformance == ContractPerformance.DQ,
"BaseActor.processEvent: ASSET_REACHED_FINAL_STATE"
);
(EventType eventType, uint256 scheduleTime) = decodeEvent(_event);
| 37,435 |
80 | // ERC20 backward compatiability | if(!_to.call(bytes4(keccak256("tokenFallback(address,uint256)")), _from, _amount)) {
| if(!_to.call(bytes4(keccak256("tokenFallback(address,uint256)")), _from, _amount)) {
| 21,360 |
43 | // Check that the `_idPayment` has been added to the payments struct | if (_idPayment >= authorizedPayments.length) return;
Payment p = authorizedPayments[_idPayment];
| if (_idPayment >= authorizedPayments.length) return;
Payment p = authorizedPayments[_idPayment];
| 42,438 |
9 | // Emitted when `owner` enables `approved` to manage the `tokenId` token. / | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
| event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
| 363 |
13 | // Claim ONI to burn later.Callable only by owner admins. / | function claimFee(uint256 _amount) external;
| function claimFee(uint256 _amount) external;
| 15,782 |
76 | // Purpose: To withdraw tokens from the original address and transfer those tokens to the replacement address. Use in cases when e.g. investor loses access to his account. Conditions: Throw error if the `original` address supplied is not a shareholder. Throw error if the 'replacement' address already holds tokens. Original address MUST NOT be reused again. Only issuer can execute this function.original - original addressreplacement - replacement address/ | function reassign(
address original,
address replacement
)
external;
| function reassign(
address original,
address replacement
)
external;
| 18,539 |
9 | // NOTE: This could fail with out-of-gas if too many tokens are added. If this fails, the owner MUST update all pools manually Adding a new pool without updating other existing pools can cause a smaller WRN reward than it should be (both pending & claimable value) because `pendingWRN` value becomes smaller with a samller `accWRNPerShare` (= with a bigger `totalMultiplier`). We should save the old `accWRNPerShare` (calculated with the old, smaller `totalMultiplier`) for every pool to prevent this issue. | updateAllPools();
| updateAllPools();
| 20,410 |
14 | // Add another contract as blacklist agent. operator-only. | function addBlacklistAgent(address agent) external;
| function addBlacklistAgent(address agent) external;
| 20,321 |
12 | // Transfers tradeAmount from trader to this smart contract | IERC20(tokenUsedToPay).safeTransferFrom(trader, address(this), tradeAmountForLong);
| IERC20(tokenUsedToPay).safeTransferFrom(trader, address(this), tradeAmountForLong);
| 19,866 |
38 | // get price and updated time for a currency | function getPriceAndUpdatedTime(bytes32 currencyName) external view returns (uint price, uint time);
| function getPriceAndUpdatedTime(bytes32 currencyName) external view returns (uint price, uint time);
| 42,830 |
1 | // Possible to extend the same to a Vet address. | updates[tokenId] = string(abi.encodePacked(update, updates[tokenId]));
| updates[tokenId] = string(abi.encodePacked(update, updates[tokenId]));
| 35,837 |
121 | // Withdraws all assets, liquidates COMP, and invests again in the required ratio./ | function doHardWork() public restricted updateVirtualPrice {
if (claimAllowed) {
claim();
}
liquidateComp();
liquidateIdle();
// this updates the virtual price
investAllUnderlying();
// state of supply/loan will be updated by the modifier
}
| function doHardWork() public restricted updateVirtualPrice {
if (claimAllowed) {
claim();
}
liquidateComp();
liquidateIdle();
// this updates the virtual price
investAllUnderlying();
// state of supply/loan will be updated by the modifier
}
| 19,266 |
5 | // Require the sender to be the DAN contract address | require(msg.sender==dan, "NOT THE OWNER!");
| require(msg.sender==dan, "NOT THE OWNER!");
| 33,772 |
36 | // Function to change the duration / | function setDuration(uint256 newDuration) public {
require(
hasRole(DEFAULT_ADMIN_ROLE, msg.sender),
"TokenDistro::setDuration: ONLY_ADMIN_ROLE"
);
require(
startTime > getTimestamp(),
"TokenDistro::setDuration: IF_HAS_NOT_STARTED_YET"
);
duration = newDuration;
emit DurationChanged(newDuration);
}
| function setDuration(uint256 newDuration) public {
require(
hasRole(DEFAULT_ADMIN_ROLE, msg.sender),
"TokenDistro::setDuration: ONLY_ADMIN_ROLE"
);
require(
startTime > getTimestamp(),
"TokenDistro::setDuration: IF_HAS_NOT_STARTED_YET"
);
duration = newDuration;
emit DurationChanged(newDuration);
}
| 19,725 |
10 | // returns addresses of refferees _referrer- address of the referrerreturn address[] - returns the referee addresses / | function showReferrees(address _referrer)
| function showReferrees(address _referrer)
| 49,981 |
47 | // require(_to != 0x0);Prevent transfer to 0x0 address. Use burn() instead | require(balanceOf[_from] >= _value); // Check if the sender has enough
require(balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
emit Transfer(_from, _to, _value);
emit mylog(0);
| require(balanceOf[_from] >= _value); // Check if the sender has enough
require(balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
balanceOf[_from] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
emit Transfer(_from, _to, _value);
emit mylog(0);
| 39,393 |
147 | // Router, LP Pair Variables | IRouter02 public dexRouter;
address public pairAddr;
mapping (address => bool) dexRouters;
mapping (address => bool) lpPairs;
| IRouter02 public dexRouter;
address public pairAddr;
mapping (address => bool) dexRouters;
mapping (address => bool) lpPairs;
| 37,784 |
25 | // determine the last round ids for src and dest pairs when period ended or latest if not over | (uint srcRoundIdAtPeriodEnd, uint destRoundIdAtPeriodEnd) = getRoundIdsAtPeriodEnd(exchangeEntry);
| (uint srcRoundIdAtPeriodEnd, uint destRoundIdAtPeriodEnd) = getRoundIdsAtPeriodEnd(exchangeEntry);
| 23,405 |
27 | // ExchangeWrapper dYdX Contract interface that Exchange Wrapper smart contracts must implement in order to interfacewith other smart contracts through a common interface. / | interface ExchangeWrapper {
// ============ Public Functions ============
/**
* Exchange some amount of takerToken for makerToken.
*
* @param tradeOriginator Address of the initiator of the trade (however, this value
* cannot always be trusted as it is set at the discretion of the
* msg.sender)
* @param receiver Address to set allowance on once the trade has completed
* @param makerToken Address of makerToken, the token to receive
* @param takerToken Address of takerToken, the token to pay
* @param requestedFillAmount Amount of takerToken being paid
* @param orderData Arbitrary bytes data for any information to pass to the exchange
* @return The amount of makerToken received
*/
function exchange(
address tradeOriginator,
address receiver,
address makerToken,
address takerToken,
uint256 requestedFillAmount,
bytes calldata orderData
)
external
returns (uint256);
/**
* Get amount of takerToken required to buy a certain amount of makerToken for a given trade.
* Should match the takerToken amount used in exchangeForAmount. If the order cannot provide
* exactly desiredMakerToken, then it must return the price to buy the minimum amount greater
* than desiredMakerToken
*
* @param makerToken Address of makerToken, the token to receive
* @param takerToken Address of takerToken, the token to pay
* @param desiredMakerToken Amount of makerToken requested
* @param orderData Arbitrary bytes data for any information to pass to the exchange
* @return Amount of takerToken the needed to complete the transaction
*/
function getExchangeCost(
address makerToken,
address takerToken,
uint256 desiredMakerToken,
bytes calldata orderData
)
external
view
returns (uint256);
}
| interface ExchangeWrapper {
// ============ Public Functions ============
/**
* Exchange some amount of takerToken for makerToken.
*
* @param tradeOriginator Address of the initiator of the trade (however, this value
* cannot always be trusted as it is set at the discretion of the
* msg.sender)
* @param receiver Address to set allowance on once the trade has completed
* @param makerToken Address of makerToken, the token to receive
* @param takerToken Address of takerToken, the token to pay
* @param requestedFillAmount Amount of takerToken being paid
* @param orderData Arbitrary bytes data for any information to pass to the exchange
* @return The amount of makerToken received
*/
function exchange(
address tradeOriginator,
address receiver,
address makerToken,
address takerToken,
uint256 requestedFillAmount,
bytes calldata orderData
)
external
returns (uint256);
/**
* Get amount of takerToken required to buy a certain amount of makerToken for a given trade.
* Should match the takerToken amount used in exchangeForAmount. If the order cannot provide
* exactly desiredMakerToken, then it must return the price to buy the minimum amount greater
* than desiredMakerToken
*
* @param makerToken Address of makerToken, the token to receive
* @param takerToken Address of takerToken, the token to pay
* @param desiredMakerToken Amount of makerToken requested
* @param orderData Arbitrary bytes data for any information to pass to the exchange
* @return Amount of takerToken the needed to complete the transaction
*/
function getExchangeCost(
address makerToken,
address takerToken,
uint256 desiredMakerToken,
bytes calldata orderData
)
external
view
returns (uint256);
}
| 34,147 |
28 | // Convert all to real units | dy = ((dy - dyFee) * PRECISION) / RATES[j];
require(dy >= minDy, "Exchange resulted in fewer coins than expected");
uint256 dyAdminFee = (dyFee * adminFee) / FEE_DENOMINATOR;
dyAdminFee = (dyAdminFee * PRECISION) / RATES[j];
| dy = ((dy - dyFee) * PRECISION) / RATES[j];
require(dy >= minDy, "Exchange resulted in fewer coins than expected");
uint256 dyAdminFee = (dyFee * adminFee) / FEE_DENOMINATOR;
dyAdminFee = (dyAdminFee * PRECISION) / RATES[j];
| 20,246 |
11 | // Claim rewards for a given token and for another user/user User address to claim for/token Token address to claim | function claimFor(address user, address token) external {
_claim(user, token);
}
| function claimFor(address user, address token) external {
_claim(user, token);
}
| 24,780 |
12 | // verify lister is the owner of the asset | require(msg.sender==AinsophContract.ownerOf(asset), "Asset must be owned by user");
| require(msg.sender==AinsophContract.ownerOf(asset), "Asset must be owned by user");
| 33,026 |
1 | // Address of bonded updater | address public updater;
| address public updater;
| 25,421 |
22 | // pipper - shiller | ambassadors_[0x3595072a72390aa733f9389d61e384b89122fff6] = true;
| ambassadors_[0x3595072a72390aa733f9389d61e384b89122fff6] = true;
| 53,018 |
106 | // Update the recipient's account, decrease the debt of the recipient by the number of tokens burned. | _poke(recipient);
| _poke(recipient);
| 44,140 |
119 | // finalize the upgrade/Required state: Success | function finalizeUpgrade() external {
if (getState() != State.Success) throw;
// Abort if not in Success state.
if (upgradeAgent.owner() == 0x0) throw;
// we need a valid upgrade agent
if (msg.sender != upgradeMaster) throw;
// only upgradeMaster can finalize
if (finalizedUpgrade) throw;
// can't finalize twice
finalizedUpgrade = true;
// prevent future upgrades
upgradeAgent.finalizeUpgrade();
// call finalize upgrade on new contract
UpgradeFinalized(msg.sender, upgradeAgent);
}
| function finalizeUpgrade() external {
if (getState() != State.Success) throw;
// Abort if not in Success state.
if (upgradeAgent.owner() == 0x0) throw;
// we need a valid upgrade agent
if (msg.sender != upgradeMaster) throw;
// only upgradeMaster can finalize
if (finalizedUpgrade) throw;
// can't finalize twice
finalizedUpgrade = true;
// prevent future upgrades
upgradeAgent.finalizeUpgrade();
// call finalize upgrade on new contract
UpgradeFinalized(msg.sender, upgradeAgent);
}
| 38,683 |
12 | // ------------------------------------------------------------------------/ Admin function to withdraw ETH from this contract Withdraws to the `owner` address to The address to withdraw ETH to / | function withdrawETH(address to) public onlyOwnerOrAdmin {
_withdrawETH(to);
}
| function withdrawETH(address to) public onlyOwnerOrAdmin {
_withdrawETH(to);
}
| 15,604 |
31 | // The COMP borrow index for each market for each supplier as of the last time they accrued COMP | mapping(address => mapping(address => uint)) public compSupplierIndex;
| mapping(address => mapping(address => uint)) public compSupplierIndex;
| 45,953 |
312 | // allows democ admins to store arbitrary data this lets us (for example) set particular keys to signal cerain things to client apps s.t. the admin can turn them on and off. arbitraryData[democHash][key] | mapping (bytes32 => mapping (bytes32 => bytes)) arbitraryData;
| mapping (bytes32 => mapping (bytes32 => bytes)) arbitraryData;
| 22,441 |
11 | // SRC20Roles contract Roles wrapper contract around all roles needed for SRC20 contract. / | contract SRC20Roles is ISRC20Roles, DelegateRole, AuthorityRole, Managed, Ownable {
constructor(address owner, address manager, address rules) public
Managed(manager)
{
_transferOwnership(owner);
if (rules != address(0)) {
_addAuthority(rules);
}
}
function addAuthority(address account) external onlyOwner returns (bool) {
_addAuthority(account);
return true;
}
function removeAuthority(address account) external onlyOwner returns (bool) {
_removeAuthority(account);
return true;
}
function isAuthority(address account) external view returns (bool) {
return _hasAuthority(account);
}
function addDelegate(address account) external onlyOwner returns (bool) {
_addDelegate(account);
return true;
}
function removeDelegate(address account) external onlyOwner returns (bool) {
_removeDelegate(account);
return true;
}
function isDelegate(address account) external view returns (bool) {
return _hasDelegate(account);
}
/**
* @return the address of the manager.
*/
function manager() external view returns (address) {
return _manager;
}
function isManager(address account) external view returns (bool) {
return _isManager(account);
}
function renounceManagement() external onlyManager returns (bool) {
_renounceManagement();
return true;
}
function transferManagement(address newManager) external onlyManager returns (bool) {
_transferManagement(newManager);
return true;
}
} | contract SRC20Roles is ISRC20Roles, DelegateRole, AuthorityRole, Managed, Ownable {
constructor(address owner, address manager, address rules) public
Managed(manager)
{
_transferOwnership(owner);
if (rules != address(0)) {
_addAuthority(rules);
}
}
function addAuthority(address account) external onlyOwner returns (bool) {
_addAuthority(account);
return true;
}
function removeAuthority(address account) external onlyOwner returns (bool) {
_removeAuthority(account);
return true;
}
function isAuthority(address account) external view returns (bool) {
return _hasAuthority(account);
}
function addDelegate(address account) external onlyOwner returns (bool) {
_addDelegate(account);
return true;
}
function removeDelegate(address account) external onlyOwner returns (bool) {
_removeDelegate(account);
return true;
}
function isDelegate(address account) external view returns (bool) {
return _hasDelegate(account);
}
/**
* @return the address of the manager.
*/
function manager() external view returns (address) {
return _manager;
}
function isManager(address account) external view returns (bool) {
return _isManager(account);
}
function renounceManagement() external onlyManager returns (bool) {
_renounceManagement();
return true;
}
function transferManagement(address newManager) external onlyManager returns (bool) {
_transferManagement(newManager);
return true;
}
} | 41,692 |
54 | // No need to remove pairs | function addPairToTrack(address pair) onlyOwner public {
_addPairToTrack(pair);
}
| function addPairToTrack(address pair) onlyOwner public {
_addPairToTrack(pair);
}
| 40,330 |
5 | // Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay. | function delayedProtocolParams() external view returns (DelayedProtocolParams memory);
| function delayedProtocolParams() external view returns (DelayedProtocolParams memory);
| 31,621 |
185 | // this function can be called only from the extending contract | function mintExternal(address _address, uint256 _mintAmount) external {
require(
msg.sender == breedingContract,
"Sorry you dont have permission to mint"
);
_safeMint(_address, _mintAmount);
}
| function mintExternal(address _address, uint256 _mintAmount) external {
require(
msg.sender == breedingContract,
"Sorry you dont have permission to mint"
);
_safeMint(_address, _mintAmount);
}
| 16,154 |
78 | // zero out the 32 bytes slice we are about to returnwe need to do it because Solidity does not garbage collect | mstore(tempBytes, 0)
mstore(0x40, add(tempBytes, 0x20))
| mstore(tempBytes, 0)
mstore(0x40, add(tempBytes, 0x20))
| 9,198 |
190 | // Load free memory pointer. We're not going to use it - we're going to overwrite it! We need 0x60 bytes of memory for this hash, cheaper to overwrite the free memory pointer at 0x40, and then replace it, than allocating free memory | let memPtr := mload(0x40)
mstore(0x00, 0x1901) // EIP191 header
mstore(0x20, eip712DomainHash) // EIP712 domain hash
mstore(0x40, _hashStruct) // Hash of struct
_result := keccak256(0x1e, 0x42) // compute hash
| let memPtr := mload(0x40)
mstore(0x00, 0x1901) // EIP191 header
mstore(0x20, eip712DomainHash) // EIP712 domain hash
mstore(0x40, _hashStruct) // Hash of struct
_result := keccak256(0x1e, 0x42) // compute hash
| 49,658 |
31 | // 每轮项目方提取百分点 | uint32 projectPercent;
| uint32 projectPercent;
| 8,233 |
149 | // Sets the `auctionDelay` parameter on Aer/Can only be called by the guardian. Checks if the value is in the allowed range./auctionDelay See. Aer | function setAuctionDelay(uint256 auctionDelay) external isGuardian {
_inRange(auctionDelay, 0, 7 days);
aer.setParam("auctionDelay", auctionDelay);
}
| function setAuctionDelay(uint256 auctionDelay) external isGuardian {
_inRange(auctionDelay, 0, 7 days);
aer.setParam("auctionDelay", auctionDelay);
}
| 13,820 |
192 | // Standard math utilities missing in the Solidity language. | library Math {
/// @dev Returns the largest of two numbers.
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return (a >= b) ? a : b;
}
/// @dev Returns the smallest of two numbers.
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return (a < b) ? a : b;
}
/// @dev Returns the average of two numbers. The result is rounded towards
/// zero.
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return ((a / 2) + (b / 2)) + (((a % 2) + (b % 2)) / 2);
}
}
| library Math {
/// @dev Returns the largest of two numbers.
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return (a >= b) ? a : b;
}
/// @dev Returns the smallest of two numbers.
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return (a < b) ? a : b;
}
/// @dev Returns the average of two numbers. The result is rounded towards
/// zero.
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return ((a / 2) + (b / 2)) + (((a % 2) + (b % 2)) / 2);
}
}
| 29,680 |
239 | // The liquidator liquidates the borrowers collateral. The collateral seized is transferred to the liquidator. borrower The borrower of this sToken to be liquidated liquidator The address repaying the borrow and seizing collateral sTokenCollateral The market in which to seize collateral from the borrower repayAmount The amount of the underlying borrowed asset to repayreturn (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. / | function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, STokenInterface sTokenCollateral) internal returns (uint, uint) {
/* Fail if liquidate not allowed */
uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(sTokenCollateral), liquidator, borrower, repayAmount);
if (allowed != 0) {
return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_REJECTION, allowed), 0);
}
/* Verify market's block number equals current block number */
if (accrualBlockNumber != getBlockNumber()) {
return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0);
}
/* Verify sTokenCollateral market's block number equals current block number */
if (sTokenCollateral.accrualBlockNumber() != getBlockNumber()) {
return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0);
}
/* Fail if borrower = liquidator */
if (borrower == liquidator) {
return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0);
}
/* Fail if repayAmount = 0 */
if (repayAmount == 0) {
return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0);
}
/* Fail if repayAmount = -1 */
if (repayAmount == uint(-1)) {
return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0);
}
/* Fail if repayBorrow fails */
(uint repayBorrowError, uint actualRepayAmount) = repayBorrowFresh(liquidator, borrower, repayAmount);
if (repayBorrowError != uint(Error.NO_ERROR)) {
return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0);
}
/////////////////////////
// EFFECTS & INTERACTIONS
// (No safe failures beyond this point)
/* We calculate the number of collateral tokens that will be seized */
(uint amountSeizeError, uint seizeTokens) = comptroller.liquidateCalculateSeizeTokens(address(this), address(sTokenCollateral), actualRepayAmount);
require(amountSeizeError == uint(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED");
/* Revert if borrower collateral token balance < seizeTokens */
require(sTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH");
// If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call
uint seizeError;
if (address(sTokenCollateral) == address(this)) {
seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens);
} else {
seizeError = sTokenCollateral.seize(liquidator, borrower, seizeTokens);
}
/* Revert if seize tokens fails (since we cannot be sure of side effects) */
require(seizeError == uint(Error.NO_ERROR), "token seizure failed");
/* We emit a LiquidateBorrow event */
emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(sTokenCollateral), seizeTokens);
/* We call the defense hook */
comptroller.liquidateBorrowVerify(address(this), address(sTokenCollateral), liquidator, borrower, actualRepayAmount, seizeTokens);
return (uint(Error.NO_ERROR), actualRepayAmount);
}
| function liquidateBorrowFresh(address liquidator, address borrower, uint repayAmount, STokenInterface sTokenCollateral) internal returns (uint, uint) {
/* Fail if liquidate not allowed */
uint allowed = comptroller.liquidateBorrowAllowed(address(this), address(sTokenCollateral), liquidator, borrower, repayAmount);
if (allowed != 0) {
return (failOpaque(Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_REJECTION, allowed), 0);
}
/* Verify market's block number equals current block number */
if (accrualBlockNumber != getBlockNumber()) {
return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0);
}
/* Verify sTokenCollateral market's block number equals current block number */
if (sTokenCollateral.accrualBlockNumber() != getBlockNumber()) {
return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0);
}
/* Fail if borrower = liquidator */
if (borrower == liquidator) {
return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0);
}
/* Fail if repayAmount = 0 */
if (repayAmount == 0) {
return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0);
}
/* Fail if repayAmount = -1 */
if (repayAmount == uint(-1)) {
return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0);
}
/* Fail if repayBorrow fails */
(uint repayBorrowError, uint actualRepayAmount) = repayBorrowFresh(liquidator, borrower, repayAmount);
if (repayBorrowError != uint(Error.NO_ERROR)) {
return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0);
}
/////////////////////////
// EFFECTS & INTERACTIONS
// (No safe failures beyond this point)
/* We calculate the number of collateral tokens that will be seized */
(uint amountSeizeError, uint seizeTokens) = comptroller.liquidateCalculateSeizeTokens(address(this), address(sTokenCollateral), actualRepayAmount);
require(amountSeizeError == uint(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED");
/* Revert if borrower collateral token balance < seizeTokens */
require(sTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH");
// If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call
uint seizeError;
if (address(sTokenCollateral) == address(this)) {
seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens);
} else {
seizeError = sTokenCollateral.seize(liquidator, borrower, seizeTokens);
}
/* Revert if seize tokens fails (since we cannot be sure of side effects) */
require(seizeError == uint(Error.NO_ERROR), "token seizure failed");
/* We emit a LiquidateBorrow event */
emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(sTokenCollateral), seizeTokens);
/* We call the defense hook */
comptroller.liquidateBorrowVerify(address(this), address(sTokenCollateral), liquidator, borrower, actualRepayAmount, seizeTokens);
return (uint(Error.NO_ERROR), actualRepayAmount);
}
| 6,378 |
136 | // update randIndex | bytes32 randseed = sha256(hash, block.number);
randIndex[0] = uint8(randseed[0]) / 8;
randIndex[1] = uint8(randseed[1]) / 8;
| bytes32 randseed = sha256(hash, block.number);
randIndex[0] = uint8(randseed[0]) / 8;
randIndex[1] = uint8(randseed[1]) / 8;
| 1,607 |
150 | // Leaves the contract without admin. It will not be possible to call`onlyAdmin` functions anymore. Can only be called by the current admin. NOTE: Renouncing admin will leave the contract without an admin,thereby removing any functionality that is only available to the admin. / | function renounceAdmin() public virtual onlyAdmin {
emit AdminTransferred(_admin, address(0));
_admin = address(0);
}
| function renounceAdmin() public virtual onlyAdmin {
emit AdminTransferred(_admin, address(0));
_admin = address(0);
}
| 36,907 |
0 | // appId is ipfs hash for unique metadata name, tagline, description, icon/ | struct App {
bytes32 appId;
string name;
string tagLine;
string description;
string icon;
string apkFile;
string iosFile;
string[] images;
}
| struct App {
bytes32 appId;
string name;
string tagLine;
string description;
string icon;
string apkFile;
string iosFile;
string[] images;
}
| 30,861 |
2 | // If a user has upgraded to the next version, transfers to this address are blocked | mapping (address => bool) isLocked;
| mapping (address => bool) isLocked;
| 41,656 |
223 | // For a direct burn, we start off with the full amounts, since we don't know the exact amounts initially. |
lockedPrpsToBurn = transferAmount;
burnableUnlockedPrps = unpacked.balance;
|
lockedPrpsToBurn = transferAmount;
burnableUnlockedPrps = unpacked.balance;
| 36,118 |
8 | // external functions |
function delegateSnapshotVotePower(
uint256 _index,
bytes32 _id,
address _delegatee
|
function delegateSnapshotVotePower(
uint256 _index,
bytes32 _id,
address _delegatee
| 6,378 |
690 | // We can unsafely cast to int256 because balances are actually stored as uint112 | _unsafeCastToInt256(amountsInOrOut, positive),
paidProtocolSwapFeeAmounts
);
| _unsafeCastToInt256(amountsInOrOut, positive),
paidProtocolSwapFeeAmounts
);
| 32,445 |
219 | // Transfer the reward to the challenger | require(token.transfer(challenges[challengeID].challenger, reward));
emit _ChallengeSucceeded(_listingHash, challengeID, challenges[challengeID].rewardPool, challenges[challengeID].totalTokens);
| require(token.transfer(challenges[challengeID].challenger, reward));
emit _ChallengeSucceeded(_listingHash, challengeID, challenges[challengeID].rewardPool, challenges[challengeID].totalTokens);
| 11,857 |
145 | // Calculates amount of account's tokens to be claimed from distributions / | function calculateClaimAmount(address account) internal view returns(uint256) {
if (nextDistributions[account] >= distributions.length) return 0;
return calculateClaimAmount(account, distributions.length);
}
| function calculateClaimAmount(address account) internal view returns(uint256) {
if (nextDistributions[account] >= distributions.length) return 0;
return calculateClaimAmount(account, distributions.length);
}
| 22,313 |
81 | // Dont have a fee when tropvault is sending, or infinite loop | transferToFeeDistributorAmount = 0;
transferToAmount = amount;
| transferToFeeDistributorAmount = 0;
transferToAmount = amount;
| 4,540 |
17 | // Assign Graph Tokens collected as curation fees to the curation pool reserve. This function can only be called by the Staking contract and will do the bookkeeping oftransferred tokens into this contract. _subgraphDeploymentID SubgraphDeployment where funds should be allocated as reserves _tokens Amount of Graph Tokens to add to reserves / | function collect(bytes32 _subgraphDeploymentID, uint256 _tokens) external override {
// Only Staking contract is authorized as caller
require(msg.sender == address(staking()), "Caller must be the staking contract");
// Must be curated to accept tokens
require(
isCurated(_subgraphDeploymentID),
"Subgraph deployment must be curated to collect fees"
);
// Collect new funds into reserve
CurationPool storage curationPool = pools[_subgraphDeploymentID];
curationPool.tokens = curationPool.tokens.add(_tokens);
emit Collected(_subgraphDeploymentID, _tokens);
}
| function collect(bytes32 _subgraphDeploymentID, uint256 _tokens) external override {
// Only Staking contract is authorized as caller
require(msg.sender == address(staking()), "Caller must be the staking contract");
// Must be curated to accept tokens
require(
isCurated(_subgraphDeploymentID),
"Subgraph deployment must be curated to collect fees"
);
// Collect new funds into reserve
CurationPool storage curationPool = pools[_subgraphDeploymentID];
curationPool.tokens = curationPool.tokens.add(_tokens);
emit Collected(_subgraphDeploymentID, _tokens);
}
| 17,074 |
56 | // from StorJ -- https:github.com/nginnever/storj-audit-verifier/blob/master/contracts/MerkleVerifyv3.sol/ non sorted merkle tree proof check / | function checkProofOrdered(
bytes32[] memory _proof,
bytes32 _root,
bytes32 _hash,
uint256 _index
| function checkProofOrdered(
bytes32[] memory _proof,
bytes32 _root,
bytes32 _hash,
uint256 _index
| 45,176 |
24 | // Override this if we prefer not to revert the entire transaction in out wallet contract implementation. | function _preExecCheck(
TransactionData memory transaction
| function _preExecCheck(
TransactionData memory transaction
| 22,366 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.