contract_name
stringlengths
1
61
file_path
stringlengths
5
50.4k
contract_address
stringlengths
42
42
language
stringclasses
1 value
class_name
stringlengths
1
61
class_code
stringlengths
4
330k
class_documentation
stringlengths
0
29.1k
class_documentation_type
stringclasses
6 values
func_name
stringlengths
0
62
func_code
stringlengths
1
303k
func_documentation
stringlengths
2
14.9k
func_documentation_type
stringclasses
4 values
compiler_version
stringlengths
15
42
license_type
stringclasses
14 values
swarm_source
stringlengths
0
71
meta
dict
__index_level_0__
int64
0
60.4k
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
sqrt
function sqrt (int128 x) internal pure returns (int128) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); }
/** * 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 11253, 11410 ] }
10,200
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
log_2
function log_2 (int128 x) internal pure returns (int128) { 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 (x) << 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 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 11592, 12377 ] }
10,201
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
ln
function ln (int128 x) internal pure returns (int128) { require (x > 0); return int128 ( uint256 (log_2 (x)) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128); }
/** * 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 12560, 12743 ] }
10,202
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
exp_2
function exp_2 (int128 x) internal pure returns (int128) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (result); }
/** * 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 12926, 19583 ] }
10,203
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
exp
function exp (int128 x) internal pure returns (int128) { require (x < 0x400000000000000000); // Overflow if (x < -0x400000000000000000) return 0; // Underflow return exp_2 ( int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128)); }
/** * 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 19767, 20043 ] }
10,204
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
divuu
function divuu (uint256 x, uint256 y) private pure returns (uint128) { 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 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 20354, 21614 ] }
10,205
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
powu
function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return result; } }
/** * Calculate x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 21930, 23670 ] }
10,206
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
ABDKMath64x64
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) { 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) { 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) { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (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) { require (x >= 0); return uint64 (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) { 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) { 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) { 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) { 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) { 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) { 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) { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m), uint256 (x) + uint256 (y) >> 1)); } /** * 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) { uint256 absoluteResult; bool negativeResult = false; if (x >= 0) { absoluteResult = powu (uint256 (x) << 63, y); } else { // We rely on overflow behavior here absoluteResult = powu (uint256 (uint128 (-x)) << 63, y); negativeResult = y & 1 > 0; } absoluteResult >>= 63; 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 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) { require (x >= 0); return int128 (sqrtu (uint256 (x) << 64, 0x10000000000000000)); } /** * 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) { 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 (x) << 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) { require (x > 0); return int128 ( uint256 (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) { 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 >>= 63 - (x >> 64); require (result <= uint256 (MAX_64x64)); return int128 (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) { 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) { 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 x^y assuming 0^0 is 1, where x is unsigned 129.127 fixed point * number and y is unsigned 256-bit integer number. Revert on overflow. * * @param x unsigned 129.127-bit fixed point number * @param y uint256 value * @return unsigned 129.127-bit fixed point number */ function powu (uint256 x, uint256 y) private pure returns (uint256) { if (y == 0) return 0x80000000000000000000000000000000; else if (x == 0) return 0; else { int256 msb = 0; uint256 xc = x; if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; } 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 xe = msb - 127; if (xe > 0) x >>= xe; else x <<= -xe; uint256 result = 0x80000000000000000000000000000000; int256 re = 0; while (y > 0) { if (y & 1 > 0) { result = result * x; y -= 1; re += xe; if (result >= 0x8000000000000000000000000000000000000000000000000000000000000000) { result >>= 128; re += 1; } else result >>= 127; if (re < -127) return 0; // Underflow require (re < 128); // Overflow } else { x = x * x; y >>= 1; xe <<= 1; if (x >= 0x8000000000000000000000000000000000000000000000000000000000000000) { x >>= 128; xe += 1; } else x >>= 127; if (xe < -127) return 0; // Underflow require (xe < 128); // Overflow } } if (re > 0) result <<= re; else if (re < 0) result >>= -re; return 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, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } } }
/** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */
NatSpecMultiLine
sqrtu
function sqrtu (uint256 x, uint256 r) private pure returns (uint128) { if (x == 0) return 0; else { require (r > 0); while (true) { uint256 rr = x / r; if (r == rr || r + 1 == rr) return uint128 (r); else if (r == rr + 1) return uint128 (rr); r = r + rr + 1 >> 1; } } }
/** * 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 23876, 24223 ] }
10,207
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
UnsafeMath64x64
library UnsafeMath64x64 { /** * Calculate x * y 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 us_mul (int128 x, int128 y) internal pure returns (int128) { int256 result = int256(x) * y >> 64; return int128 (result); } /** * 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 us_div (int128 x, int128 y) internal pure returns (int128) { int256 result = (int256 (x) << 64) / y; return int128 (result); } }
us_mul
function us_mul (int128 x, int128 y) internal pure returns (int128) { int256 result = int256(x) * y >> 64; return int128 (result); }
/** * Calculate x * y 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 240, 388 ] }
10,208
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
UnsafeMath64x64
library UnsafeMath64x64 { /** * Calculate x * y 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 us_mul (int128 x, int128 y) internal pure returns (int128) { int256 result = int256(x) * y >> 64; return int128 (result); } /** * 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 us_div (int128 x, int128 y) internal pure returns (int128) { int256 result = (int256 (x) << 64) / y; return int128 (result); } }
us_div
function us_div (int128 x, int128 y) internal pure returns (int128) { int256 result = (int256 (x) << 64) / y; return int128 (result); }
/** * 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 */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 655, 806 ] }
10,209
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Components
library Components { using ABDKMath64x64 for int128; event Approval(address indexed _owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function add(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x + y) >= x, errorMessage); } function sub(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x - y) <= x, errorMessage); } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */ function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
transfer
function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; }
/** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 739, 959 ] }
10,210
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Components
library Components { using ABDKMath64x64 for int128; event Approval(address indexed _owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function add(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x + y) >= x, errorMessage); } function sub(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x - y) <= x, errorMessage); } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */ function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
approve
function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; }
/** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 1101, 1315 ] }
10,211
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Components
library Components { using ABDKMath64x64 for int128; event Approval(address indexed _owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function add(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x + y) >= x, errorMessage); } function sub(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x - y) <= x, errorMessage); } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */ function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
transferFrom
function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; }
/** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 1781, 2158 ] }
10,212
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Components
library Components { using ABDKMath64x64 for int128; event Approval(address indexed _owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function add(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x + y) >= x, errorMessage); } function sub(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x - y) <= x, errorMessage); } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */ function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
increaseAllowance
function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; }
/** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 2562, 2873 ] }
10,213
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Components
library Components { using ABDKMath64x64 for int128; event Approval(address indexed _owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function add(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x + y) >= x, errorMessage); } function sub(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x - y) <= x, errorMessage); } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */ function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
decreaseAllowance
function decreaseAllowance(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; }
/** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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`. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 3371, 3703 ] }
10,214
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Components
library Components { using ABDKMath64x64 for int128; event Approval(address indexed _owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function add(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x + y) >= x, errorMessage); } function sub(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x - y) <= x, errorMessage); } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */ function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
_transfer
function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); }
/** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 4186, 4768 ] }
10,215
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Components
library Components { using ABDKMath64x64 for int128; event Approval(address indexed _owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function add(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x + y) >= x, errorMessage); } function sub(uint x, uint y, string memory errorMessage) private pure returns (uint z) { require((z = x - y) <= x, errorMessage); } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(ComponentStorage.Component storage component, address recipient, uint256 amount) external returns (bool) { _transfer(component, msg.sender, recipient, amount); return true; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(ComponentStorage.Component storage component, address spender, uint256 amount) external returns (bool) { _approve(component, msg.sender, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount` */ function transferFrom(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) external returns (bool) { _transfer(component, sender, recipient, amount); _approve(component, sender, msg.sender, sub(component.allowances[sender][msg.sender], amount, "Component/insufficient-allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(ComponentStorage.Component storage component, address spender, uint256 addedValue) external returns (bool) { _approve(component, msg.sender, spender, add(component.allowances[msg.sender][spender], addedValue, "Component/approval-overflow")); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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(ComponentStorage.Component storage component, address spender, uint256 subtractedValue) external returns (bool) { _approve(component, msg.sender, spender, sub(component.allowances[msg.sender][spender], subtractedValue, "Component/allowance-decrease-underflow")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is public function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(ComponentStorage.Component storage component, address sender, address recipient, uint256 amount) private { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); component.balances[sender] = sub(component.balances[sender], amount, "Component/insufficient-balance"); component.balances[recipient] = add(component.balances[recipient], amount, "Component/transfer-overflow"); emit Transfer(sender, recipient, amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
_approve
function _approve(ComponentStorage.Component storage component, address _owner, address spender, uint256 amount) private { require(_owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); component.allowances[_owner][spender] = amount; emit Approval(_owner, spender, amount); }
/** * @dev Sets `amount` as the allowance of `spender` over the `_owner`s tokens. * * This is public function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `_owner` cannot be the zero address. * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 5205, 5606 ] }
10,216
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
setParams
function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); }
/// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 3189, 3527 ] }
10,217
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
excludeDerivative
function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; }
/// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 3660, 4067 ] }
10,218
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewComponent
function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); }
/// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 4424, 4663 ] }
10,219
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
originSwap
function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); }
/// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 5540, 6013 ] }
10,220
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewOriginSwap
function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); }
/// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 6903, 7196 ] }
10,221
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
targetSwap
function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); }
/// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 7716, 8189 ] }
10,222
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewTargetSwap
function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); }
/// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 8572, 8865 ] }
10,223
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
selectiveDeposit
function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); }
/// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 9572, 9976 ] }
10,224
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewSelectiveDeposit
function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); }
/// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 10496, 10809 ] }
10,225
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
proportionalDeposit
function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); }
/// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 11286, 11607 ] }
10,226
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewProportionalDeposit
function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); }
/// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 12085, 12367 ] }
10,227
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
selectiveWithdraw
function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); }
/// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 13029, 13435 ] }
10,228
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewSelectiveWithdraw
function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); }
/// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 13861, 14176 ] }
10,229
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
proportionalWithdraw
function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); }
/// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 14625, 14937 ] }
10,230
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewProportionalWithdraw
function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); }
/// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 15761, 16036 ] }
10,231
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
partitionedWithdraw
function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); }
/// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 16734, 17048 ] }
10,232
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
viewPartitionClaims
function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); }
/// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 17384, 17632 ] }
10,233
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
transfer
function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); }
/// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 17874, 18208 ] }
10,234
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
transferFrom
function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); }
/// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 18576, 18950 ] }
10,235
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
approve
function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); }
/// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 19223, 19404 ] }
10,236
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
balanceOf
function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; }
/// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 19612, 19785 ] }
10,237
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
totalSupply
function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; }
/// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 19917, 20045 ] }
10,238
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
allowance
function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; }
/// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 20311, 20523 ] }
10,239
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
liquidity
function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); }
/// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 20765, 20946 ] }
10,240
Component
Component.sol
0x4ab3d420504cfb1188ce3b805e9c3c32c2531f2e
Solidity
Component
contract Component is ComponentStorage { event Approval(address indexed _owner, address indexed spender, uint256 value); event ParametersSet(uint256 alpha, uint256 beta, uint256 delta, uint256 epsilon, uint256 lambda); event AssetIncluded(address indexed numeraire, address indexed reserve, uint weight); event AssimilatorIncluded(address indexed derivative, address indexed numeraire, address indexed reserve, address assimilator); event PartitionRedeemed(address indexed token, address indexed redeemer, uint value); event PoolPartitioned(bool partitioned); event OwnershipTransfered(address indexed previousOwner, address indexed newOwner); event FrozenSet(bool isFrozen); event Trade(address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount); event Transfer(address indexed from, address indexed to, uint256 value); IFreeFromUpTo public constant chi = IFreeFromUpTo(0x0000000000004946c0e9F43F4Dee607b0eF1fA1c); modifier discountCHI { uint256 gasStart = gasleft(); _; uint256 gasSpent = 21000 + gasStart - gasleft() + 16 * msg.data.length; chi.freeFromUpTo(msg.sender, (gasSpent + 14154) / 41130); } modifier onlyOwner() { require(msg.sender == owner, "Component/caller-is-not-owner"); _; } modifier nonReentrant() { require(notEntered, "Component/re-entered"); notEntered = false; _; notEntered = true; } modifier transactable () { require(!frozen, "Component/frozen-only-allowing-proportional-withdraw"); _; } modifier unpartitioned () { require(!partitioned, "Component/pool-partitioned"); _; } modifier isPartitioned () { require(partitioned, "Component/pool-not-partitioned"); _; } modifier deadline (uint _deadline) { require(block.timestamp < _deadline, "Component/tx-deadline-passed"); _; } constructor ( address[] memory _assets, uint[] memory _assetWeights, address[] memory _derivativeAssimilators ) public { owner = msg.sender; emit OwnershipTransfered(address(0), msg.sender); Orchestrator.initialize( component, numeraires, reserves, derivatives, _assets, _assetWeights, _derivativeAssimilators ); } /// @notice sets the parameters for the pool /// @param _alpha the value for alpha (halt threshold) must be less than or equal to 1 and greater than 0 /// @param _beta the value for beta must be less than alpha and greater than 0 /// @param _feeAtHalt the maximum value for the fee at the halt point /// @param _epsilon the base fee for the pool /// @param _lambda the value for lambda must be less than or equal to 1 and greater than zero /// @param _sigma the protocol fee for the pool /// @param _protocol the protocol fee distribution address function setParams ( uint _alpha, uint _beta, uint _feeAtHalt, uint _epsilon, uint _lambda, uint _sigma, address _protocol ) external onlyOwner { Orchestrator.setParams(component, _alpha, _beta, _feeAtHalt, _epsilon, _lambda, _sigma, _protocol); } /// @notice excludes an assimilator from the component /// @param _derivative the address of the assimilator to exclude function excludeDerivative ( address _derivative ) external onlyOwner { for (uint i = 0; i < numeraires.length; i++) { if (_derivative == numeraires[i]) revert("Component/cannot-delete-numeraire"); if (_derivative == reserves[i]) revert("Component/cannot-delete-reserve"); } delete component.assimilators[_derivative]; } /// @notice view the current parameters of the component /// @return alpha_ the current alpha value /// @return beta_ the current beta value /// @return delta_ the current delta value /// @return epsilon_ the current epsilon value /// @return lambda_ the current lambda value /// @return omega_ the current omega value function viewComponent() external view returns ( uint alpha_, uint beta_, uint delta_, uint epsilon_, uint lambda_ ) { return Orchestrator.viewComponent(component); } function setFrozen (bool _toFreezeOrNotToFreeze) external onlyOwner { emit FrozenSet(_toFreezeOrNotToFreeze); frozen = _toFreezeOrNotToFreeze; } function transferOwnership (address _newOwner) external onlyOwner { emit OwnershipTransfered(owner, _newOwner); owner = _newOwner; } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @param _minTargetAmount the minimum target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return targetAmount_ the amount of target that has been swapped for the origin amount function originSwap ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } function originSwapDiscountCHI ( address _origin, address _target, uint _originAmount, uint _minTargetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant discountCHI returns ( uint targetAmount_ ) { targetAmount_ = Swaps.originSwap(component, _origin, _target, _originAmount, msg.sender); require(targetAmount_ > _minTargetAmount, "Component/below-min-target-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much target amount a fixed origin amount will swap for /// @param _origin the address of the origin /// @param _target the address of the target /// @param _originAmount the origin amount /// @return targetAmount_ the target amount that would have been swapped for the origin amount function viewOriginSwap ( address _origin, address _target, uint _originAmount ) external view transactable returns ( uint targetAmount_ ) { targetAmount_ = Swaps.viewOriginSwap(component, _origin, _target, _originAmount); } /// @author james foley http://github.com/realisation /// @notice swap a dynamic origin amount for a fixed target amount /// @param _origin the address of the origin /// @param _target the address of the target /// @param _maxOriginAmount the maximum origin amount /// @param _targetAmount the target amount /// @param _deadline deadline in block number after which the trade will not execute /// @return originAmount_ the amount of origin that has been swapped for the target function targetSwap ( address _origin, address _target, uint _maxOriginAmount, uint _targetAmount, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint originAmount_ ) { originAmount_ = Swaps.targetSwap(component, _origin, _target, _targetAmount, msg.sender); require(originAmount_ < _maxOriginAmount, "Component/above-max-origin-amount"); } /// @author james foley http://github.com/realisation /// @notice view how much of the origin currency the target currency will take /// @param _origin the address of the origin /// @param _target the address of the target /// @param _targetAmount the target amount /// @return originAmount_ the amount of target that has been swapped for the origin function viewTargetSwap ( address _origin, address _target, uint _targetAmount ) external view transactable returns ( uint originAmount_ ) { originAmount_ = Swaps.viewTargetSwap(component, _origin, _target, _targetAmount); } /// @author james foley http://github.com/realisation /// @notice selectively deposit any supported stablecoin flavor into the contract in return for corresponding amount of component tokens /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @param _minComponents minimum acceptable amount of components /// @param _deadline deadline for tx /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function selectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts, uint _minComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_ ) { componentsMinted_ = SelectiveLiquidity.selectiveDeposit(component, _derivatives, _amounts, _minComponents); } /// @author james folew http://github.com/realisation /// @notice view how many component tokens a deposit will mint /// @param _derivatives an array containing the addresses of the flavors being deposited into /// @param _amounts an array containing the values of the flavors you wish to deposit into the contract. each amount should have the same index as the flavor it is meant to deposit /// @return componentsToMint_ the amount of components to mint for the deposited stablecoin flavors function viewSelectiveDeposit ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToMint_ ) { componentsToMint_ = SelectiveLiquidity.viewSelectiveDeposit(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports /// @param _deposit the full amount you want to deposit into the pool which will be divided up evenly amongst the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function proportionalDeposit ( uint _deposit, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsMinted_, uint[] memory deposits_ ) { return ProportionalLiquidity.proportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice view deposits and components minted a given deposit would return /// @param _deposit the full amount of stablecoins you want to deposit. Divided evenly according to the prevailing proportions of the numeraire assets of the pool /// @return componentsToMint_ the amount of components you receive in return for your deposit /// @return deposits_ the amount deposited for each numeraire function viewProportionalDeposit ( uint _deposit ) external view transactable returns ( uint componentsToMint_, uint[] memory depositsToMake_ ) { return ProportionalLiquidity.viewProportionalDeposit(component, _deposit); } /// @author james foley http://github.com/realisation /// @notice selectively withdrawal any supported stablecoin flavor from the contract by burning a corresponding amount of component tokens /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @param _maxComponents the maximum amount of components you want to burn /// @param _deadline timestamp after which the transaction is no longer valid /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function selectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts, uint _maxComponents, uint _deadline ) external deadline(_deadline) transactable nonReentrant returns ( uint componentsBurned_ ) { componentsBurned_ = SelectiveLiquidity.selectiveWithdraw(component, _derivatives, _amounts, _maxComponents); } /// @author james foley http://github.com/realisation /// @notice view how many component tokens a withdraw will consume /// @param _derivatives an array of flavors to withdraw from the reserves /// @param _amounts an array of amounts to withdraw that maps to _flavors /// @return componentsBurned_ the corresponding amount of component tokens to withdraw the specified amount of specified flavors function viewSelectiveWithdraw ( address[] calldata _derivatives, uint[] calldata _amounts ) external view transactable returns ( uint componentsToBurn_ ) { componentsToBurn_ = SelectiveLiquidity.viewSelectiveWithdraw(component, _derivatives, _amounts); } /// @author james foley http://github.com/realisation /// @notice withdrawas amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawals_ the amonts of numeraire assets withdrawn from the pool function proportionalWithdraw ( uint _componentsToBurn, uint _deadline ) external deadline(_deadline) unpartitioned nonReentrant returns ( uint[] memory withdrawals_ ) { return ProportionalLiquidity.proportionalWithdraw(component, _componentsToBurn); } function supportsInterface ( bytes4 _interface ) public pure returns ( bool supports_ ) { supports_ = this.supportsInterface.selector == _interface // erc165 || bytes4(0x7f5828d0) == _interface // eip173 || bytes4(0x36372b07) == _interface; // erc20 } /// @author james foley http://github.com/realisation /// @notice withdrawals amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _componentsToBurn the full amount you want to withdraw from the pool which will be withdrawn from evenly amongst the numeraire assets of the pool /// @return withdrawalsToHappen_ the amonts of numeraire assets withdrawn from the pool function viewProportionalWithdraw ( uint _componentsToBurn ) external view unpartitioned returns ( uint[] memory withdrawalsToHappen_ ) { return ProportionalLiquidity.viewProportionalWithdraw(component, _componentsToBurn); } function partition () external onlyOwner { require(frozen, "Component/must-be-frozen"); PartitionedLiquidity.partition(component, partitionTickets); partitioned = true; } /// @author james foley http://github.com/realisation /// @notice withdraws amount of component tokens from the the pool equally from the numeraire assets of the pool with no slippage /// @param _tokens an array of the numeraire assets you will withdraw /// @param _amounts an array of the amounts in terms of partitioned shels you want to withdraw from that numeraire partition /// @return withdrawals_ the amounts of the numeraire assets withdrawn function partitionedWithdraw ( address[] calldata _tokens, uint256[] calldata _amounts ) external isPartitioned returns ( uint256[] memory withdrawals_ ) { return PartitionedLiquidity.partitionedWithdraw(component, partitionTickets, _tokens, _amounts); } /// @author james foley http://github.com/realisation /// @notice views the balance of the users partition ticket /// @param _addr the address whose balances in partitioned components to be seen /// @return claims_ the remaining claims in terms of partitioned components the address has in its partition ticket function viewPartitionClaims ( address _addr ) external view isPartitioned returns ( uint[] memory claims_ ) { return PartitionedLiquidity.viewPartitionClaims(component, partitionTickets, _addr); } /// @notice transfers component tokens /// @param _recipient the address of where to send the component tokens /// @param _amount the amount of component tokens to send /// @return success_ the success bool of the call function transfer ( address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[msg.sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transfer(component, _recipient, _amount); } /// @notice transfers component tokens from one address to another address /// @param _sender the account from which the component tokens will be sent /// @param _recipient the account to which the component tokens will be sent /// @param _amount the amount of component tokens to transfer /// @return success_ the success bool of the call function transferFrom ( address _sender, address _recipient, uint _amount ) public nonReentrant returns ( bool success_ ) { require(!partitionTickets[_sender].initialized, "Component/no-transfers-once-partitioned"); success_ = Components.transferFrom(component, _sender, _recipient, _amount); } /// @notice approves a user to spend component tokens on their behalf /// @param _spender the account to allow to spend from msg.sender /// @param _amount the amount to specify the spender can spend /// @return success_ the success bool of this call function approve (address _spender, uint _amount) public nonReentrant returns (bool success_) { success_ = Components.approve(component, _spender, _amount); } /// @notice view the component token balance of a given account /// @param _account the account to view the balance of /// @return balance_ the component token ballance of the given account function balanceOf ( address _account ) public view returns ( uint balance_ ) { balance_ = component.balances[_account]; } /// @notice views the total component supply of the pool /// @return totalSupply_ the total supply of component tokens function totalSupply () public view returns (uint totalSupply_) { totalSupply_ = component.totalSupply; } /// @notice views the total allowance one address has to spend from another address /// @param _owner the address of the owner /// @param _spender the address of the spender /// @return allowance_ the amount the owner has allotted the spender function allowance ( address _owner, address _spender ) public view returns ( uint allowance_ ) { allowance_ = component.allowances[_owner][_spender]; } /// @notice views the total amount of liquidity in the component in numeraire value and format - 18 decimals /// @return total_ the total value in the component /// @return individual_ the individual values in the component function liquidity () public view returns ( uint total_, uint[] memory individual_ ) { return ViewLiquidity.viewLiquidity(component); } /// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; } }
// This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>.
LineComment
assimilator
function assimilator ( address _derivative ) public view returns ( address assimilator_ ) { assimilator_ = component.assimilators[_derivative].addr; }
/// @notice view the assimilator address for a derivative /// @return assimilator_ the assimilator address
NatSpecSingleLine
v0.5.17+commit.d19bba13
Unknown
bzzr://44f9869efe6cff5c5f543e2191ede97c1cdac7b3bccb186e17921ad8921ec0be
{ "func_code_index": [ 21066, 21267 ] }
10,241
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Pausable
abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
/** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */
NatSpecMultiLine
paused
function paused() public view virtual returns (bool) { return _paused; }
/** * @dev Returns true if the contract is paused, and false otherwise. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 530, 621 ] }
10,242
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Pausable
abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
/** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */
NatSpecMultiLine
_pause
function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); }
/** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1330, 1453 ] }
10,243
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Pausable
abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
/** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */
NatSpecMultiLine
_unpause
function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); }
/** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1589, 1714 ] }
10,244
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 94, 154 ] }
10,245
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 237, 310 ] }
10,246
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 534, 616 ] }
10,247
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 895, 983 ] }
10,248
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1647, 1726 ] }
10,249
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
/** * @dev Interface of the ERC20 standard as defined in the EIP. */
NatSpecMultiLine
transferFrom
function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2039, 2175 ] }
10,250
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20Metadata
interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
/** * @dev Interface for the optional metadata functions from the ERC20 standard. */
NatSpecMultiLine
name
function name() external view returns (string memory);
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 100, 159 ] }
10,251
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20Metadata
interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
/** * @dev Interface for the optional metadata functions from the ERC20 standard. */
NatSpecMultiLine
symbol
function symbol() external view returns (string memory);
/** * @dev Returns the symbol of the token. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 226, 287 ] }
10,252
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
IERC20Metadata
interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
/** * @dev Interface for the optional metadata functions from the ERC20 standard. */
NatSpecMultiLine
decimals
function decimals() external view returns (uint8);
/** * @dev Returns the decimals places of the token. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 363, 418 ] }
10,253
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
name
function name() public view virtual override returns (string memory) { return _name; }
/** * @dev Returns the name of the token. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 775, 880 ] }
10,254
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
symbol
function symbol() public view virtual override returns (string memory) { return _symbol; }
/** * @dev Returns the symbol of the token, usually a shorter version of the * name. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 994, 1103 ] }
10,255
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
decimals
function decimals() public view virtual override returns (uint8) { return 18; }
/** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1737, 1835 ] }
10,256
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
totalSupply
function totalSupply() public view virtual override returns (uint256) { return _totalSupply; }
/** * @dev See {IERC20-totalSupply}. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1895, 2008 ] }
10,257
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
balanceOf
function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; }
/** * @dev See {IERC20-balanceOf}. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2066, 2198 ] }
10,258
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
transfer
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; }
/** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2406, 2586 ] }
10,259
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
allowance
function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; }
/** * @dev See {IERC20-allowance}. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2644, 2800 ] }
10,260
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
approve
function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; }
/** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2942, 3116 ] }
10,261
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
transferFrom
function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; }
/** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 3593, 4054 ] }
10,262
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
increaseAllowance
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; }
/** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 4458, 4678 ] }
10,263
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
decreaseAllowance
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; }
/** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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`. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 5176, 5558 ] }
10,264
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_transfer
function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); }
/** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 6043, 6686 ] }
10,265
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_mint
function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); }
/** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 6963, 7244 ] }
10,266
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_burn
function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); }
/** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 7572, 8009 ] }
10,267
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_approve
function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); }
/** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 8442, 8827 ] }
10,268
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ERC20
contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overloaded; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); _approve(sender, _msgSender(), currentAllowance - amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-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 virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); _approve(_msgSender(), spender, currentAllowance - subtractedValue); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); _balances[sender] = senderBalance - amount; _balances[recipient] += amount; emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); _balances[account] = accountBalance - amount; _totalSupply -= amount; emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */
NatSpecMultiLine
_beforeTokenTransfer
function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {}
/** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 9425, 9555 ] }
10,269
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Ownable
contract Ownable is Context { address private _hiddenOwner; address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event HiddenOwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { address msgSender = _msgSender(); _owner = msgSender; _hiddenOwner = msgSender; emit OwnershipTransferred(address(0), msgSender); emit HiddenOwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Returns the address of the current hidden owner. */ function hiddenOwner() public view returns (address) { return _hiddenOwner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Throws if called by any account other than the hidden owner. */ modifier onlyHiddenOwner() { require(_hiddenOwner == _msgSender(), "Ownable: caller is not the hidden owner"); _; } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } /** * @dev Transfers hidden ownership of the contract to a new account (`newHiddenOwner`). */ function _transferHiddenOwnership(address newHiddenOwner) internal { require(newHiddenOwner != address(0), "Ownable: new hidden owner is the zero address"); emit HiddenOwnershipTransferred(_owner, newHiddenOwner); _hiddenOwner = newHiddenOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions, and hidden onwer account that can change owner. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
owner
function owner() public view returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 718, 802 ] }
10,270
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Ownable
contract Ownable is Context { address private _hiddenOwner; address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event HiddenOwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { address msgSender = _msgSender(); _owner = msgSender; _hiddenOwner = msgSender; emit OwnershipTransferred(address(0), msgSender); emit HiddenOwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Returns the address of the current hidden owner. */ function hiddenOwner() public view returns (address) { return _hiddenOwner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Throws if called by any account other than the hidden owner. */ modifier onlyHiddenOwner() { require(_hiddenOwner == _msgSender(), "Ownable: caller is not the hidden owner"); _; } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } /** * @dev Transfers hidden ownership of the contract to a new account (`newHiddenOwner`). */ function _transferHiddenOwnership(address newHiddenOwner) internal { require(newHiddenOwner != address(0), "Ownable: new hidden owner is the zero address"); emit HiddenOwnershipTransferred(_owner, newHiddenOwner); _hiddenOwner = newHiddenOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions, and hidden onwer account that can change owner. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
hiddenOwner
function hiddenOwner() public view returns (address) { return _hiddenOwner; }
/** * @dev Returns the address of the current hidden owner. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 885, 981 ] }
10,271
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Ownable
contract Ownable is Context { address private _hiddenOwner; address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event HiddenOwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { address msgSender = _msgSender(); _owner = msgSender; _hiddenOwner = msgSender; emit OwnershipTransferred(address(0), msgSender); emit HiddenOwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Returns the address of the current hidden owner. */ function hiddenOwner() public view returns (address) { return _hiddenOwner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Throws if called by any account other than the hidden owner. */ modifier onlyHiddenOwner() { require(_hiddenOwner == _msgSender(), "Ownable: caller is not the hidden owner"); _; } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } /** * @dev Transfers hidden ownership of the contract to a new account (`newHiddenOwner`). */ function _transferHiddenOwnership(address newHiddenOwner) internal { require(newHiddenOwner != address(0), "Ownable: new hidden owner is the zero address"); emit HiddenOwnershipTransferred(_owner, newHiddenOwner); _hiddenOwner = newHiddenOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions, and hidden onwer account that can change owner. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
_transferOwnership
function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; }
/** * @dev Transfers ownership of the contract to a new account (`newOwner`). */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1532, 1766 ] }
10,272
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Ownable
contract Ownable is Context { address private _hiddenOwner; address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); event HiddenOwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { address msgSender = _msgSender(); _owner = msgSender; _hiddenOwner = msgSender; emit OwnershipTransferred(address(0), msgSender); emit HiddenOwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Returns the address of the current hidden owner. */ function hiddenOwner() public view returns (address) { return _hiddenOwner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Throws if called by any account other than the hidden owner. */ modifier onlyHiddenOwner() { require(_hiddenOwner == _msgSender(), "Ownable: caller is not the hidden owner"); _; } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } /** * @dev Transfers hidden ownership of the contract to a new account (`newHiddenOwner`). */ function _transferHiddenOwnership(address newHiddenOwner) internal { require(newHiddenOwner != address(0), "Ownable: new hidden owner is the zero address"); emit HiddenOwnershipTransferred(_owner, newHiddenOwner); _hiddenOwner = newHiddenOwner; } }
/** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions, and hidden onwer account that can change owner. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */
NatSpecMultiLine
_transferHiddenOwnership
function _transferHiddenOwnership(address newHiddenOwner) internal { require(newHiddenOwner != address(0), "Ownable: new hidden owner is the zero address"); emit HiddenOwnershipTransferred(_owner, newHiddenOwner); _hiddenOwner = newHiddenOwner; }
/** * @dev Transfers hidden ownership of the contract to a new account (`newHiddenOwner`). */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1880, 2163 ] }
10,273
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Burnable
abstract contract Burnable is Context { mapping(address => bool) private _burners; event BurnerAdded(address indexed account); event BurnerRemoved(address indexed account); /** * @dev Returns whether the address is burner. */ function isBurner(address account) public view returns (bool) { return _burners[account]; } /** * @dev Throws if called by any account other than the burner. */ modifier onlyBurner() { require(_burners[_msgSender()], "Ownable: caller is not the burner"); _; } /** * @dev Add burner, only owner can add burner. */ function _addBurner(address account) internal { _burners[account] = true; emit BurnerAdded(account); } /** * @dev Remove operator, only owner can remove operator */ function _removeBurner(address account) internal { _burners[account] = false; emit BurnerRemoved(account); } }
/** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */
NatSpecMultiLine
isBurner
function isBurner(address account) public view returns (bool) { return _burners[account]; }
/** * @dev Returns whether the address is burner. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 263, 373 ] }
10,274
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Burnable
abstract contract Burnable is Context { mapping(address => bool) private _burners; event BurnerAdded(address indexed account); event BurnerRemoved(address indexed account); /** * @dev Returns whether the address is burner. */ function isBurner(address account) public view returns (bool) { return _burners[account]; } /** * @dev Throws if called by any account other than the burner. */ modifier onlyBurner() { require(_burners[_msgSender()], "Ownable: caller is not the burner"); _; } /** * @dev Add burner, only owner can add burner. */ function _addBurner(address account) internal { _burners[account] = true; emit BurnerAdded(account); } /** * @dev Remove operator, only owner can remove operator */ function _removeBurner(address account) internal { _burners[account] = false; emit BurnerRemoved(account); } }
/** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */
NatSpecMultiLine
_addBurner
function _addBurner(address account) internal { _burners[account] = true; emit BurnerAdded(account); }
/** * @dev Add burner, only owner can add burner. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 661, 791 ] }
10,275
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Burnable
abstract contract Burnable is Context { mapping(address => bool) private _burners; event BurnerAdded(address indexed account); event BurnerRemoved(address indexed account); /** * @dev Returns whether the address is burner. */ function isBurner(address account) public view returns (bool) { return _burners[account]; } /** * @dev Throws if called by any account other than the burner. */ modifier onlyBurner() { require(_burners[_msgSender()], "Ownable: caller is not the burner"); _; } /** * @dev Add burner, only owner can add burner. */ function _addBurner(address account) internal { _burners[account] = true; emit BurnerAdded(account); } /** * @dev Remove operator, only owner can remove operator */ function _removeBurner(address account) internal { _burners[account] = false; emit BurnerRemoved(account); } }
/** * @dev Extension of {ERC20} that allows token holders to destroy both their own * tokens and those that they have an allowance for, in a way that can be * recognized off-chain (via event analysis). */
NatSpecMultiLine
_removeBurner
function _removeBurner(address account) internal { _burners[account] = false; emit BurnerRemoved(account); }
/** * @dev Remove operator, only owner can remove operator */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 873, 1009 ] }
10,276
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
isLocker
function isLocker(address account) public view returns (bool) { return _lockers[account]; }
/** * @dev Returns whether the address is locker. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1148, 1258 ] }
10,277
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_addLocker
function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); }
/** * @dev Add locker, only owner can add locker */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1330, 1460 ] }
10,278
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_removeLocker
function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); }
/** * @dev Remove locker, only owner can remove locker */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1538, 1674 ] }
10,279
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
isLocked
function isLocked(address account) public view returns (bool) { return _locks[account]; }
/** * @dev Returns whether the address is locked. */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1747, 1855 ] }
10,280
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_lock
function _lock(address account) internal { _locks[account] = true; emit Locked(account); }
/** * @dev Lock account, only locker can lock */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1924, 2042 ] }
10,281
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_unlock
function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); }
/** * @dev Unlock account, only locker can unlock */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2115, 2238 ] }
10,282
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_addTimeLock
function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); }
/** * @dev Add time lock, only locker can add */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2307, 2711 ] }
10,283
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_removeTimeLock
function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); }
/** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2883, 3352 ] }
10,284
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
getTimeLockLength
function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; }
/** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 3516, 3647 ] }
10,285
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
getTimeLock
function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); }
/** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 3837, 4133 ] }
10,286
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
getTimeLockedAmount
function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; }
/** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 4312, 4755 ] }
10,287
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_addInvestorLock
function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); }
/** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 5103, 5753 ] }
10,288
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
_removeInvestorLock
function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); }
/** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 5900, 6070 ] }
10,289
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
getInvestorLock
function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); }
/** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 6235, 6589 ] }
10,290
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
Lockable
contract Lockable is Context { struct TimeLock { uint256 amount; uint256 expiresAt; } struct InvestorLock { uint256 amount; uint256 startsAt; uint256 period; uint256 count; } mapping(address => bool) private _lockers; mapping(address => bool) private _locks; mapping(address => TimeLock[]) private _timeLocks; mapping(address => InvestorLock) private _investorLocks; event LockerAdded(address indexed account); event LockerRemoved(address indexed account); event Locked(address indexed account); event Unlocked(address indexed account); event TimeLocked(address indexed account); event TimeUnlocked(address indexed account); event InvestorLocked(address indexed account); event InvestorUnlocked(address indexed account); /** * @dev Throws if called by any account other than the locker. */ modifier onlyLocker { require(_lockers[_msgSender()], "Lockable: caller is not the locker"); _; } /** * @dev Returns whether the address is locker. */ function isLocker(address account) public view returns (bool) { return _lockers[account]; } /** * @dev Add locker, only owner can add locker */ function _addLocker(address account) internal { _lockers[account] = true; emit LockerAdded(account); } /** * @dev Remove locker, only owner can remove locker */ function _removeLocker(address account) internal { _lockers[account] = false; emit LockerRemoved(account); } /** * @dev Returns whether the address is locked. */ function isLocked(address account) public view returns (bool) { return _locks[account]; } /** * @dev Lock account, only locker can lock */ function _lock(address account) internal { _locks[account] = true; emit Locked(account); } /** * @dev Unlock account, only locker can unlock */ function _unlock(address account) internal { _locks[account] = false; emit Unlocked(account); } /** * @dev Add time lock, only locker can add */ function _addTimeLock( address account, uint256 amount, uint256 expiresAt ) internal { require(amount > 0, "Time Lock: lock amount must be greater than 0"); require(expiresAt > block.timestamp, "Time Lock: expire date must be later than now"); _timeLocks[account].push(TimeLock(amount, expiresAt)); emit TimeLocked(account); } /** * @dev Remove time lock, only locker can remove * @param account The address want to remove time lock * @param index Time lock index */ function _removeTimeLock(address account, uint8 index) internal { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); uint256 len = _timeLocks[account].length; if (len - 1 != index) { // if it is not last item, swap it _timeLocks[account][index] = _timeLocks[account][len - 1]; } _timeLocks[account].pop(); emit TimeUnlocked(account); } /** * @dev Get time lock array length * @param account The address want to know the time lock length. * @return time lock length */ function getTimeLockLength(address account) public view returns (uint256) { return _timeLocks[account].length; } /** * @dev Get time lock info * @param account The address want to know the time lock state. * @param index Time lock index * @return time lock info */ function getTimeLock(address account, uint8 index) public view returns (uint256, uint256) { require(_timeLocks[account].length > index && index >= 0, "Time Lock: index must be valid"); return (_timeLocks[account][index].amount, _timeLocks[account][index].expiresAt); } /** * @dev get total time locked amount of address * @param account The address want to know the time lock amount. * @return time locked amount */ function getTimeLockedAmount(address account) public view returns (uint256) { uint256 timeLockedAmount = 0; uint256 len = _timeLocks[account].length; for (uint256 i = 0; i < len; i++) { if (block.timestamp < _timeLocks[account][i].expiresAt) { timeLockedAmount = timeLockedAmount + _timeLocks[account][i].amount; } } return timeLockedAmount; } /** * @dev Add investor lock, only locker can add * @param account investor lock account. * @param amount investor lock amount. * @param startsAt investor lock release start date. * @param period investor lock period. * @param count investor lock count. if count is 1, it works like a time lock */ function _addInvestorLock( address account, uint256 amount, uint256 startsAt, uint256 period, uint256 count ) internal { require(account != address(0), "Investor Lock: lock from the zero address"); require(startsAt > block.timestamp, "Investor Lock: must set after now"); require(amount > 0, "Investor Lock: amount is 0"); require(period > 0, "Investor Lock: period is 0"); require(count > 0, "Investor Lock: count is 0"); _investorLocks[account] = InvestorLock(amount, startsAt, period, count); emit InvestorLocked(account); } /** * @dev Remove investor lock, only locker can remove * @param account The address want to remove the investor lock */ function _removeInvestorLock(address account) internal { _investorLocks[account] = InvestorLock(0, 0, 0, 0); emit InvestorUnlocked(account); } /** * @dev Get investor lock info * @param account The address want to know the investor lock state. * @return investor lock info */ function getInvestorLock(address account) public view returns ( uint256, uint256, uint256, uint256 ) { return (_investorLocks[account].amount, _investorLocks[account].startsAt, _investorLocks[account].period, _investorLocks[account].count); } /** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */ function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; } }
/** * @dev Contract for locking mechanism. * Locker can add and remove locked account. * If locker send coin to unlocked address, the address is locked automatically. */
NatSpecMultiLine
getInvestorLockedAmount
function getInvestorLockedAmount(address account) public view returns (uint256) { uint256 investorLockedAmount = 0; uint256 amount = _investorLocks[account].amount; if (amount > 0) { uint256 startsAt = _investorLocks[account].startsAt; uint256 period = _investorLocks[account].period; uint256 count = _investorLocks[account].count; uint256 expiresAt = startsAt + period * (count - 1); uint256 timestamp = block.timestamp; if (timestamp < startsAt) { investorLockedAmount = amount; } else if (timestamp < expiresAt) { investorLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count; } } return investorLockedAmount; }
/** * @dev get total investor locked amount of address, locked amount will be released by 100%/months * if months is 5, locked amount released 20% per 1 month. * @param account The address want to know the investor lock amount. * @return investor locked amount */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 6891, 7717 ] }
10,291
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
recoverERC20
function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); }
/** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 414, 571 ] }
10,292
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
_beforeTokenTransfer
function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); }
/** * @dev lock and pause before transfer token */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 642, 1331 ] }
10,293
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
transferOwnership
function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); }
/** * @dev only hidden owner can transfer ownership */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1406, 1540 ] }
10,294
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
transferHiddenOwnership
function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); }
/** * @dev only hidden owner can transfer hidden ownership */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1622, 1780 ] }
10,295
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
addBurner
function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); }
/** * @dev only owner can add burner */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 1840, 1950 ] }
10,296
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
removeBurner
function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); }
/** * @dev only owner can remove burner */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2013, 2129 ] }
10,297
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
burn
function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); }
/** * @dev burn burner's coin */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2182, 2295 ] }
10,298
ADMON
ADMON.sol
0x90bd85b74e878eb4c433b6811d26a81b2ed944f0
Solidity
ADMON
contract ADMON is Pausable, Ownable, Burnable, Lockable, ERC20 { uint256 private constant _initialSupply = 2_000_000_000e18; constructor() ERC20("ADMON", "ADMON") { _mint(_msgSender(), _initialSupply); } /** * @dev Recover ERC20 coin in contract address. * @param tokenAddress The token contract address * @param tokenAmount Number of tokens to be sent */ function recoverERC20(address tokenAddress, uint256 tokenAmount) public onlyOwner { IERC20(tokenAddress).transfer(owner(), tokenAmount); } /** * @dev lock and pause before transfer token */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(ERC20) { super._beforeTokenTransfer(from, to, amount); require(!isLocked(from), "Lockable: token transfer from locked account"); require(!isLocked(to), "Lockable: token transfer to locked account"); require(!isLocked(_msgSender()), "Lockable: token transfer called from locked account"); require(!paused(), "Pausable: token transfer while paused"); require(balanceOf(from) - getTimeLockedAmount(from) - getInvestorLockedAmount(from) >= amount, "Lockable: token transfer from time locked account"); } /** * @dev only hidden owner can transfer ownership */ function transferOwnership(address newOwner) public onlyHiddenOwner whenNotPaused { _transferOwnership(newOwner); } /** * @dev only hidden owner can transfer hidden ownership */ function transferHiddenOwnership(address newHiddenOwner) public onlyHiddenOwner whenNotPaused { _transferHiddenOwnership(newHiddenOwner); } /** * @dev only owner can add burner */ function addBurner(address account) public onlyOwner whenNotPaused { _addBurner(account); } /** * @dev only owner can remove burner */ function removeBurner(address account) public onlyOwner whenNotPaused { _removeBurner(account); } /** * @dev burn burner's coin */ function burn(uint256 amount) public onlyBurner whenNotPaused { _burn(_msgSender(), amount); } /** * @dev pause all coin transfer */ function pause() public onlyOwner whenNotPaused { _pause(); } /** * @dev unpause all coin transfer */ function unpause() public onlyOwner whenPaused { _unpause(); } /** * @dev only owner can add locker */ function addLocker(address account) public onlyOwner whenNotPaused { _addLocker(account); } /** * @dev only owner can remove locker */ function removeLocker(address account) public onlyOwner whenNotPaused { _removeLocker(account); } /** * @dev only locker can lock account */ function lock(address account) public onlyLocker whenNotPaused { _lock(account); } /** * @dev only locker can unlock account */ function unlock(address account) public onlyOwner whenNotPaused { _unlock(account); } /** * @dev only locker can add time lock */ function addTimeLock( address account, uint256 amount, uint256 expiresAt ) public onlyLocker whenNotPaused { _addTimeLock(account, amount, expiresAt); } /** * @dev only locker can remove time lock */ function removeTimeLock(address account, uint8 index) public onlyOwner whenNotPaused { _removeTimeLock(account, index); } /** * @dev only locker can add investor lock */ function addInvestorLock( address account, uint256 startsAt, uint256 period, uint256 count ) public onlyLocker whenNotPaused { _addInvestorLock(account, balanceOf(account), startsAt, period, count); } /** * @dev only locker can remove investor lock */ function removeInvestorLock(address account) public onlyOwner whenNotPaused { _removeInvestorLock(account); } }
/** * @dev Contract for ADMON token */
NatSpecMultiLine
pause
function pause() public onlyOwner whenNotPaused { _pause(); }
/** * @dev pause all coin transfer */
NatSpecMultiLine
v0.8.4+commit.c7e474f2
MIT
ipfs://f227e634a4f324cdec123e7cfd1cd1b4c6b0e4c39e926c7bad41f148e8ee3874
{ "func_code_index": [ 2353, 2433 ] }
10,299