From e536e6fa8487740a913e045ab59c637325270315 Mon Sep 17 00:00:00 2001 From: ququzone Date: Wed, 27 Nov 2024 22:25:28 +0800 Subject: [PATCH] chore: clean code --- contracts/art/BokkyPooBahsDateTimeLibrary.sol | 357 --- contracts/art/PerlinNoise.sol | 2265 ----------------- contracts/art/Trig.sol | 891 ------- contracts/factories/GaugeFactory.sol | 2 +- contracts/factories/IncentivesFactory.sol | 2 +- test/TestGauge.t.sol | 2 - test/TestIncentive.sol | 10 +- test/TestVault.t.sol | 2 - 8 files changed, 7 insertions(+), 3524 deletions(-) delete mode 100644 contracts/art/BokkyPooBahsDateTimeLibrary.sol delete mode 100644 contracts/art/PerlinNoise.sol delete mode 100644 contracts/art/Trig.sol diff --git a/contracts/art/BokkyPooBahsDateTimeLibrary.sol b/contracts/art/BokkyPooBahsDateTimeLibrary.sol deleted file mode 100644 index 2552d08..0000000 --- a/contracts/art/BokkyPooBahsDateTimeLibrary.sol +++ /dev/null @@ -1,357 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.19; - -// ---------------------------------------------------------------------------- -// BokkyPooBah's DateTime Library v1.01 -// -// A gas-efficient Solidity date and time library -// -// https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary -// -// Tested date range 1970/01/01 to 2345/12/31 -// -// Conventions: -// Unit | Range | Notes -// :-------- |:-------------:|:----- -// timestamp | >= 0 | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC -// year | 1970 ... 2345 | -// month | 1 ... 12 | -// day | 1 ... 31 | -// hour | 0 ... 23 | -// minute | 0 ... 59 | -// second | 0 ... 59 | -// dayOfWeek | 1 ... 7 | 1 = Monday, ..., 7 = Sunday -// -// -// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018-2019. The MIT Licence. -// ---------------------------------------------------------------------------- - -library BokkyPooBahsDateTimeLibrary { - uint256 constant SECONDS_PER_DAY = 24 * 60 * 60; - uint256 constant SECONDS_PER_HOUR = 60 * 60; - uint256 constant SECONDS_PER_MINUTE = 60; - int256 constant OFFSET19700101 = 2440588; - - uint256 constant DOW_MON = 1; - uint256 constant DOW_TUE = 2; - uint256 constant DOW_WED = 3; - uint256 constant DOW_THU = 4; - uint256 constant DOW_FRI = 5; - uint256 constant DOW_SAT = 6; - uint256 constant DOW_SUN = 7; - - // ------------------------------------------------------------------------ - // Calculate the number of days from 1970/01/01 to year/month/day using - // the date conversion algorithm from - // https://aa.usno.navy.mil/faq/JD_formula.html - // and subtracting the offset 2440588 so that 1970/01/01 is day 0 - // - // days = day - // - 32075 - // + 1461 * (year + 4800 + (month - 14) / 12) / 4 - // + 367 * (month - 2 - (month - 14) / 12 * 12) / 12 - // - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4 - // - offset - // ------------------------------------------------------------------------ - function _daysFromDate(uint256 year, uint256 month, uint256 day) internal pure returns (uint256 _days) { - require(year >= 1970); - int256 _year = int256(year); - int256 _month = int256(month); - int256 _day = int256(day); - - int256 __days = _day - - 32075 + - (1461 * (_year + 4800 + (_month - 14) / 12)) / - 4 + - (367 * (_month - 2 - ((_month - 14) / 12) * 12)) / - 12 - - (3 * ((_year + 4900 + (_month - 14) / 12) / 100)) / - 4 - - OFFSET19700101; - - _days = uint256(__days); - } - - // ------------------------------------------------------------------------ - // Calculate year/month/day from the number of days since 1970/01/01 using - // the date conversion algorithm from - // http://aa.usno.navy.mil/faq/docs/JD_Formula.php - // and adding the offset 2440588 so that 1970/01/01 is day 0 - // - // int L = days + 68569 + offset - // int N = 4 * L / 146097 - // L = L - (146097 * N + 3) / 4 - // year = 4000 * (L + 1) / 1461001 - // L = L - 1461 * year / 4 + 31 - // month = 80 * L / 2447 - // dd = L - 2447 * month / 80 - // L = month / 11 - // month = month + 2 - 12 * L - // year = 100 * (N - 49) + year + L - // ------------------------------------------------------------------------ - function _daysToDate(uint256 _days) internal pure returns (uint256 year, uint256 month, uint256 day) { - int256 __days = int256(_days); - - int256 L = __days + 68569 + OFFSET19700101; - int256 N = (4 * L) / 146097; - L = L - (146097 * N + 3) / 4; - int256 _year = (4000 * (L + 1)) / 1461001; - L = L - (1461 * _year) / 4 + 31; - int256 _month = (80 * L) / 2447; - int256 _day = L - (2447 * _month) / 80; - L = _month / 11; - _month = _month + 2 - 12 * L; - _year = 100 * (N - 49) + _year + L; - - year = uint256(_year); - month = uint256(_month); - day = uint256(_day); - } - - function timestampFromDate(uint256 year, uint256 month, uint256 day) internal pure returns (uint256 timestamp) { - timestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY; - } - - function timestampFromDateTime( - uint256 year, - uint256 month, - uint256 day, - uint256 hour, - uint256 minute, - uint256 second - ) internal pure returns (uint256 timestamp) { - timestamp = - _daysFromDate(year, month, day) * - SECONDS_PER_DAY + - hour * - SECONDS_PER_HOUR + - minute * - SECONDS_PER_MINUTE + - second; - } - - function timestampToDate(uint256 timestamp) internal pure returns (uint256 year, uint256 month, uint256 day) { - (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); - } - - function timestampToDateTime( - uint256 timestamp - ) internal pure returns (uint256 year, uint256 month, uint256 day, uint256 hour, uint256 minute, uint256 second) { - (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); - uint256 secs = timestamp % SECONDS_PER_DAY; - hour = secs / SECONDS_PER_HOUR; - secs = secs % SECONDS_PER_HOUR; - minute = secs / SECONDS_PER_MINUTE; - second = secs % SECONDS_PER_MINUTE; - } - - function isValidDate(uint256 year, uint256 month, uint256 day) internal pure returns (bool valid) { - if (year >= 1970 && month > 0 && month <= 12) { - uint256 daysInMonth = _getDaysInMonth(year, month); - if (day > 0 && day <= daysInMonth) { - valid = true; - } - } - } - - function isValidDateTime( - uint256 year, - uint256 month, - uint256 day, - uint256 hour, - uint256 minute, - uint256 second - ) internal pure returns (bool valid) { - if (isValidDate(year, month, day)) { - if (hour < 24 && minute < 60 && second < 60) { - valid = true; - } - } - } - - function isLeapYear(uint256 timestamp) internal pure returns (bool leapYear) { - (uint256 year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY); - leapYear = _isLeapYear(year); - } - - function _isLeapYear(uint256 year) internal pure returns (bool leapYear) { - leapYear = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); - } - - function isWeekDay(uint256 timestamp) internal pure returns (bool weekDay) { - weekDay = getDayOfWeek(timestamp) <= DOW_FRI; - } - - function isWeekEnd(uint256 timestamp) internal pure returns (bool weekEnd) { - weekEnd = getDayOfWeek(timestamp) >= DOW_SAT; - } - - function getDaysInMonth(uint256 timestamp) internal pure returns (uint256 daysInMonth) { - (uint256 year, uint256 month, ) = _daysToDate(timestamp / SECONDS_PER_DAY); - daysInMonth = _getDaysInMonth(year, month); - } - - function _getDaysInMonth(uint256 year, uint256 month) internal pure returns (uint256 daysInMonth) { - if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { - daysInMonth = 31; - } else if (month != 2) { - daysInMonth = 30; - } else { - daysInMonth = _isLeapYear(year) ? 29 : 28; - } - } - // 1 = Monday, 7 = Sunday - - function getDayOfWeek(uint256 timestamp) internal pure returns (uint256 dayOfWeek) { - uint256 _days = timestamp / SECONDS_PER_DAY; - dayOfWeek = ((_days + 3) % 7) + 1; - } - - function getYear(uint256 timestamp) internal pure returns (uint256 year) { - (year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY); - } - - function getMonth(uint256 timestamp) internal pure returns (uint256 month) { - (, month, ) = _daysToDate(timestamp / SECONDS_PER_DAY); - } - - function getDay(uint256 timestamp) internal pure returns (uint256 day) { - (, , day) = _daysToDate(timestamp / SECONDS_PER_DAY); - } - - function getHour(uint256 timestamp) internal pure returns (uint256 hour) { - uint256 secs = timestamp % SECONDS_PER_DAY; - hour = secs / SECONDS_PER_HOUR; - } - - function getMinute(uint256 timestamp) internal pure returns (uint256 minute) { - uint256 secs = timestamp % SECONDS_PER_HOUR; - minute = secs / SECONDS_PER_MINUTE; - } - - function getSecond(uint256 timestamp) internal pure returns (uint256 second) { - second = timestamp % SECONDS_PER_MINUTE; - } - - function addYears(uint256 timestamp, uint256 _years) internal pure returns (uint256 newTimestamp) { - (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); - year += _years; - uint256 daysInMonth = _getDaysInMonth(year, month); - if (day > daysInMonth) { - day = daysInMonth; - } - newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); - require(newTimestamp >= timestamp); - } - - function addMonths(uint256 timestamp, uint256 _months) internal pure returns (uint256 newTimestamp) { - (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); - month += _months; - year += (month - 1) / 12; - month = ((month - 1) % 12) + 1; - uint256 daysInMonth = _getDaysInMonth(year, month); - if (day > daysInMonth) { - day = daysInMonth; - } - newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); - require(newTimestamp >= timestamp); - } - - function addDays(uint256 timestamp, uint256 _days) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp + _days * SECONDS_PER_DAY; - require(newTimestamp >= timestamp); - } - - function addHours(uint256 timestamp, uint256 _hours) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp + _hours * SECONDS_PER_HOUR; - require(newTimestamp >= timestamp); - } - - function addMinutes(uint256 timestamp, uint256 _minutes) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp + _minutes * SECONDS_PER_MINUTE; - require(newTimestamp >= timestamp); - } - - function addSeconds(uint256 timestamp, uint256 _seconds) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp + _seconds; - require(newTimestamp >= timestamp); - } - - function subYears(uint256 timestamp, uint256 _years) internal pure returns (uint256 newTimestamp) { - (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); - year -= _years; - uint256 daysInMonth = _getDaysInMonth(year, month); - if (day > daysInMonth) { - day = daysInMonth; - } - newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); - require(newTimestamp <= timestamp); - } - - function subMonths(uint256 timestamp, uint256 _months) internal pure returns (uint256 newTimestamp) { - (uint256 year, uint256 month, uint256 day) = _daysToDate(timestamp / SECONDS_PER_DAY); - uint256 yearMonth = year * 12 + (month - 1) - _months; - year = yearMonth / 12; - month = (yearMonth % 12) + 1; - uint256 daysInMonth = _getDaysInMonth(year, month); - if (day > daysInMonth) { - day = daysInMonth; - } - newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); - require(newTimestamp <= timestamp); - } - - function subDays(uint256 timestamp, uint256 _days) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp - _days * SECONDS_PER_DAY; - require(newTimestamp <= timestamp); - } - - function subHours(uint256 timestamp, uint256 _hours) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp - _hours * SECONDS_PER_HOUR; - require(newTimestamp <= timestamp); - } - - function subMinutes(uint256 timestamp, uint256 _minutes) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp - _minutes * SECONDS_PER_MINUTE; - require(newTimestamp <= timestamp); - } - - function subSeconds(uint256 timestamp, uint256 _seconds) internal pure returns (uint256 newTimestamp) { - newTimestamp = timestamp - _seconds; - require(newTimestamp <= timestamp); - } - - function diffYears(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _years) { - require(fromTimestamp <= toTimestamp); - (uint256 fromYear, , ) = _daysToDate(fromTimestamp / SECONDS_PER_DAY); - (uint256 toYear, , ) = _daysToDate(toTimestamp / SECONDS_PER_DAY); - _years = toYear - fromYear; - } - - function diffMonths(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _months) { - require(fromTimestamp <= toTimestamp); - (uint256 fromYear, uint256 fromMonth, ) = _daysToDate(fromTimestamp / SECONDS_PER_DAY); - (uint256 toYear, uint256 toMonth, ) = _daysToDate(toTimestamp / SECONDS_PER_DAY); - _months = toYear * 12 + toMonth - fromYear * 12 - fromMonth; - } - - function diffDays(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _days) { - require(fromTimestamp <= toTimestamp); - _days = (toTimestamp - fromTimestamp) / SECONDS_PER_DAY; - } - - function diffHours(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _hours) { - require(fromTimestamp <= toTimestamp); - _hours = (toTimestamp - fromTimestamp) / SECONDS_PER_HOUR; - } - - function diffMinutes(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _minutes) { - require(fromTimestamp <= toTimestamp); - _minutes = (toTimestamp - fromTimestamp) / SECONDS_PER_MINUTE; - } - - function diffSeconds(uint256 fromTimestamp, uint256 toTimestamp) internal pure returns (uint256 _seconds) { - require(fromTimestamp <= toTimestamp); - _seconds = toTimestamp - fromTimestamp; - } -} diff --git a/contracts/art/PerlinNoise.sol b/contracts/art/PerlinNoise.sol deleted file mode 100644 index 06ec856..0000000 --- a/contracts/art/PerlinNoise.sol +++ /dev/null @@ -1,2265 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.19; - -// Library by https://github.com/0x10f/solidity-perlin-noise - -/** - * @notice An implementation of Perlin Noise that uses 16 bit fixed point arithmetic. - * @notice Updated solidity version from 0.5.0 to 0.8.12. - */ -library PerlinNoise { - /** - * @notice Computes the noise value for a 2D point. - * - * @param x the x coordinate. - * @param y the y coordinate. - * - * @dev This function should be kept public. Inlining the bytecode for this function - * into other functions could explode its compiled size because of how `ftable` - * and `ptable` were written. - */ - function noise2d(int256 x, int256 y) public pure returns (int256) { - int256 temp = ptable((x >> 16) & 0xff /* Unit square X */); - - int256 a = ptable((temp >> 8) + ((y >> 16) & 0xff) /* Unit square Y */); - int256 b = ptable((temp & 0xff) + ((y >> 16) & 0xff)); - - x &= 0xffff; // Square relative X - y &= 0xffff; // Square relative Y - - int256 u = fade(x); - - int256 c = lerp(u, grad2(a >> 8, x, y), grad2(b >> 8, x - 0x10000, y)); - int256 d = lerp(u, grad2(a & 0xff, x, y - 0x10000), grad2(b & 0xff, x - 0x10000, y - 0x10000)); - - return lerp(fade(y), c, d); - } - - /** - * @notice Computes the noise value for a 3D point. - * - * @param x the x coordinate. - * @param y the y coordinate. - * @param z the z coordinate. - * - * @dev This function should be kept public. Inlining the bytecode for this function - * into other functions could explode its compiled size because of how `ftable` - * and `ptable` were written. - */ - function noise3d(int256 x, int256 y, int256 z) public pure returns (int256) { - int256[7] memory scratch = [ - (x >> 16) & 0xff, // Unit cube X - (y >> 16) & 0xff, // Unit cube Y - (z >> 16) & 0xff, // Unit cube Z - 0, - 0, - 0, - 0 - ]; - - x &= 0xffff; // Cube relative X - y &= 0xffff; // Cube relative Y - z &= 0xffff; // Cube relative Z - - // Temporary variables used for intermediate calculations. - int256 u; - int256 v; - - v = ptable(scratch[0]); - - u = ptable((v >> 8) + scratch[1]); - v = ptable((v & 0xff) + scratch[1]); - - scratch[3] = ptable((u >> 8) + scratch[2]); - scratch[4] = ptable((u & 0xff) + scratch[2]); - scratch[5] = ptable((v >> 8) + scratch[2]); - scratch[6] = ptable((v & 0xff) + scratch[2]); - - int256 a; - int256 b; - int256 c; - - u = fade(x); - v = fade(y); - - a = lerp(u, grad3(scratch[3] >> 8, x, y, z), grad3(scratch[5] >> 8, x - 0x10000, y, z)); - b = lerp(u, grad3(scratch[4] >> 8, x, y - 0x10000, z), grad3(scratch[6] >> 8, x - 0x10000, y - 0x10000, z)); - c = lerp(v, a, b); - - a = lerp(u, grad3(scratch[3] & 0xff, x, y, z - 0x10000), grad3(scratch[5] & 0xff, x - 0x10000, y, z - 0x10000)); - b = lerp( - u, - grad3(scratch[4] & 0xff, x, y - 0x10000, z - 0x10000), - grad3(scratch[6] & 0xff, x - 0x10000, y - 0x10000, z - 0x10000) - ); - - return lerp(fade(z), c, lerp(v, a, b)); - } - - /** - * @notice Computes the linear interpolation between two values, `a` and `b`, using fixed point arithmetic. - * - * @param t the time value of the equation. - * @param a the lower point. - * @param b the upper point. - */ - function lerp(int256 t, int256 a, int256 b) internal pure returns (int256) { - return a + ((t * (b - a)) >> 12); - } - - /** - * @notice Applies the fade function to a value. - * - * @param t the time value of the equation. - * - * @dev The polynomial for this function is: 6t^4-15t^4+10t^3. - */ - function fade(int256 t) internal pure returns (int256) { - int256 n = ftable(t >> 8); - - // Lerp between the two points grabbed from the fade table. - (int256 lower, int256 upper) = (n >> 12, n & 0xfff); - return lower + (((t & 0xff) * (upper - lower)) >> 8); - } - - /** - * @notice Computes the gradient value for a 2D point. - * - * @param h the hash value to use for picking the vector. - * @param x the x coordinate of the point. - * @param y the y coordinate of the point. - */ - function grad2(int256 h, int256 x, int256 y) internal pure returns (int256) { - h &= 3; - - int256 u; - if (h & 0x1 == 0) { - u = x; - } else { - u = -x; - } - - int256 v; - if (h < 2) { - v = y; - } else { - v = -y; - } - - return u + v; - } - - /** - * @notice Computes the gradient value for a 3D point. - * - * @param h the hash value to use for picking the vector. - * @param x the x coordinate of the point. - * @param y the y coordinate of the point. - * @param z the z coordinate of the point. - */ - function grad3(int256 h, int256 x, int256 y, int256 z) internal pure returns (int256) { - h &= 0xf; - - int256 u; - if (h < 8) { - u = x; - } else { - u = y; - } - - int256 v; - if (h < 4) { - v = y; - } else if (h == 12 || h == 14) { - v = x; - } else { - v = z; - } - - if ((h & 0x1) != 0) { - u = -u; - } - - if ((h & 0x2) != 0) { - v = -v; - } - - return u + v; - } - - /** - * @notice Gets a subsequent values in the permutation table at an index. The values are encoded - * into a single 24 bit integer with the value at the specified index being the most - * significant 12 bits and the subsequent value being the least significant 12 bits. - * - * @param i the index in the permutation table. - * - * @dev The values from the table are mapped out into a binary tree for faster lookups. - * Looking up any value in the table in this implementation is is O(8), in - * the implementation of sequential if statements it is O(255). - * - * @dev The body of this function is autogenerated. Check out the 'gen-ptable' script. - */ - function ptable(int256 i) internal pure returns (int256) { - i &= 0xff; - - if (i <= 127) { - if (i <= 63) { - if (i <= 31) { - if (i <= 15) { - if (i <= 7) { - if (i <= 3) { - if (i <= 1) { - if (i == 0) { - return 38816; - } else { - return 41097; - } - } else { - if (i == 2) { - return 35163; - } else { - return 23386; - } - } - } else { - if (i <= 5) { - if (i == 4) { - return 23055; - } else { - return 3971; - } - } else { - if (i == 6) { - return 33549; - } else { - return 3529; - } - } - } - } else { - if (i <= 11) { - if (i <= 9) { - if (i == 8) { - return 51551; - } else { - return 24416; - } - } else { - if (i == 10) { - return 24629; - } else { - return 13762; - } - } - } else { - if (i <= 13) { - if (i == 12) { - return 49897; - } else { - return 59655; - } - } else { - if (i == 14) { - return 2017; - } else { - return 57740; - } - } - } - } - } else { - if (i <= 23) { - if (i <= 19) { - if (i <= 17) { - if (i == 16) { - return 35876; - } else { - return 9319; - } - } else { - if (i == 18) { - return 26398; - } else { - return 7749; - } - } - } else { - if (i <= 21) { - if (i == 20) { - return 17806; - } else { - return 36360; - } - } else { - if (i == 22) { - return 2147; - } else { - return 25381; - } - } - } - } else { - if (i <= 27) { - if (i <= 25) { - if (i == 24) { - return 9712; - } else { - return 61461; - } - } else { - if (i == 26) { - return 5386; - } else { - return 2583; - } - } - } else { - if (i <= 29) { - if (i == 28) { - return 6078; - } else { - return 48646; - } - } else { - if (i == 30) { - return 1684; - } else { - return 38135; - } - } - } - } - } - } else { - if (i <= 47) { - if (i <= 39) { - if (i <= 35) { - if (i <= 33) { - if (i == 32) { - return 63352; - } else { - return 30954; - } - } else { - if (i == 34) { - return 59979; - } else { - return 19200; - } - } - } else { - if (i <= 37) { - if (i == 36) { - return 26; - } else { - return 6853; - } - } else { - if (i == 38) { - return 50494; - } else { - return 15966; - } - } - } - } else { - if (i <= 43) { - if (i <= 41) { - if (i == 40) { - return 24316; - } else { - return 64731; - } - } else { - if (i == 42) { - return 56267; - } else { - return 52085; - } - } - } else { - if (i <= 45) { - if (i == 44) { - return 29987; - } else { - return 8971; - } - } else { - if (i == 46) { - return 2848; - } else { - return 8249; - } - } - } - } - } else { - if (i <= 55) { - if (i <= 51) { - if (i <= 49) { - if (i == 48) { - return 14769; - } else { - return 45345; - } - } else { - if (i == 50) { - return 8536; - } else { - return 22765; - } - } - } else { - if (i <= 53) { - if (i == 52) { - return 60821; - } else { - return 38200; - } - } else { - if (i == 54) { - return 14423; - } else { - return 22446; - } - } - } - } else { - if (i <= 59) { - if (i <= 57) { - if (i == 56) { - return 44564; - } else { - return 5245; - } - } else { - if (i == 58) { - return 32136; - } else { - return 34987; - } - } - } else { - if (i <= 61) { - if (i == 60) { - return 43944; - } else { - return 43076; - } - } else { - if (i == 62) { - return 17583; - } else { - return 44874; - } - } - } - } - } - } - } else { - if (i <= 95) { - if (i <= 79) { - if (i <= 71) { - if (i <= 67) { - if (i <= 65) { - if (i == 64) { - return 19109; - } else { - return 42311; - } - } else { - if (i == 66) { - return 18310; - } else { - return 34443; - } - } - } else { - if (i <= 69) { - if (i == 68) { - return 35632; - } else { - return 12315; - } - } else { - if (i == 70) { - return 7078; - } else { - return 42573; - } - } - } - } else { - if (i <= 75) { - if (i <= 73) { - if (i == 72) { - return 19858; - } else { - return 37534; - } - } else { - if (i == 74) { - return 40679; - } else { - return 59219; - } - } - } else { - if (i <= 77) { - if (i == 76) { - return 21359; - } else { - return 28645; - } - } else { - if (i == 78) { - return 58746; - } else { - return 31292; - } - } - } - } - } else { - if (i <= 87) { - if (i <= 83) { - if (i <= 81) { - if (i == 80) { - return 15571; - } else { - return 54149; - } - } else { - if (i == 82) { - return 34278; - } else { - return 59100; - } - } - } else { - if (i <= 85) { - if (i == 84) { - return 56425; - } else { - return 26972; - } - } else { - if (i == 86) { - return 23593; - } else { - return 10551; - } - } - } - } else { - if (i <= 91) { - if (i <= 89) { - if (i == 88) { - return 14126; - } else { - return 12021; - } - } else { - if (i == 90) { - return 62760; - } else { - return 10484; - } - } - } else { - if (i <= 93) { - if (i == 92) { - return 62566; - } else { - return 26255; - } - } else { - if (i == 94) { - return 36662; - } else { - return 13889; - } - } - } - } - } - } else { - if (i <= 111) { - if (i <= 103) { - if (i <= 99) { - if (i <= 97) { - if (i == 96) { - return 16665; - } else { - return 6463; - } - } else { - if (i == 98) { - return 16289; - } else { - return 41217; - } - } - } else { - if (i <= 101) { - if (i == 100) { - return 472; - } else { - return 55376; - } - } else { - if (i == 102) { - return 20553; - } else { - return 18897; - } - } - } - } else { - if (i <= 107) { - if (i <= 105) { - if (i == 104) { - return 53580; - } else { - return 19588; - } - } else { - if (i == 106) { - return 33979; - } else { - return 48080; - } - } - } else { - if (i <= 109) { - if (i == 108) { - return 53337; - } else { - return 22802; - } - } else { - if (i == 110) { - return 4777; - } else { - return 43464; - } - } - } - } - } else { - if (i <= 119) { - if (i <= 115) { - if (i <= 113) { - if (i == 112) { - return 51396; - } else { - return 50311; - } - } else { - if (i == 114) { - return 34690; - } else { - return 33396; - } - } - } else { - if (i <= 117) { - if (i == 116) { - return 29884; - } else { - return 48287; - } - } else { - if (i == 118) { - return 40790; - } else { - return 22180; - } - } - } - } else { - if (i <= 123) { - if (i <= 121) { - if (i == 120) { - return 42084; - } else { - return 25709; - } - } else { - if (i == 122) { - return 28102; - } else { - return 50861; - } - } - } else { - if (i <= 125) { - if (i == 124) { - return 44474; - } else { - return 47619; - } - } else { - if (i == 126) { - return 832; - } else { - return 16436; - } - } - } - } - } - } - } - } else { - if (i <= 191) { - if (i <= 159) { - if (i <= 143) { - if (i <= 135) { - if (i <= 131) { - if (i <= 129) { - if (i == 128) { - return 13529; - } else { - return 55778; - } - } else { - if (i == 130) { - return 58106; - } else { - return 64124; - } - } - } else { - if (i <= 133) { - if (i == 132) { - return 31867; - } else { - return 31493; - } - } else { - if (i == 134) { - return 1482; - } else { - return 51750; - } - } - } - } else { - if (i <= 139) { - if (i <= 137) { - if (i == 136) { - return 9875; - } else { - return 37750; - } - } else { - if (i == 138) { - return 30334; - } else { - return 32511; - } - } - } else { - if (i <= 141) { - if (i == 140) { - return 65362; - } else { - return 21077; - } - } else { - if (i == 142) { - return 21972; - } else { - return 54479; - } - } - } - } - } else { - if (i <= 151) { - if (i <= 147) { - if (i <= 145) { - if (i == 144) { - return 53198; - } else { - return 52795; - } - } else { - if (i == 146) { - return 15331; - } else { - return 58159; - } - } - } else { - if (i <= 149) { - if (i == 148) { - return 12048; - } else { - return 4154; - } - } else { - if (i == 150) { - return 14865; - } else { - return 4534; - } - } - } - } else { - if (i <= 155) { - if (i <= 153) { - if (i == 152) { - return 46781; - } else { - return 48412; - } - } else { - if (i == 154) { - return 7210; - } else { - return 10975; - } - } - } else { - if (i <= 157) { - if (i == 156) { - return 57271; - } else { - return 47018; - } - } else { - if (i == 158) { - return 43733; - } else { - return 54647; - } - } - } - } - } - } else { - if (i <= 175) { - if (i <= 167) { - if (i <= 163) { - if (i <= 161) { - if (i == 160) { - return 30712; - } else { - return 63640; - } - } else { - if (i == 162) { - return 38914; - } else { - return 556; - } - } - } else { - if (i <= 165) { - if (i == 164) { - return 11418; - } else { - return 39587; - } - } else { - if (i == 166) { - return 41798; - } else { - return 18141; - } - } - } - } else { - if (i <= 171) { - if (i <= 169) { - if (i == 168) { - return 56729; - } else { - return 39269; - } - } else { - if (i == 170) { - return 26011; - } else { - return 39847; - } - } - } else { - if (i <= 173) { - if (i == 172) { - return 42795; - } else { - return 11180; - } - } else { - if (i == 174) { - return 44041; - } else { - return 2433; - } - } - } - } - } else { - if (i <= 183) { - if (i <= 179) { - if (i <= 177) { - if (i == 176) { - return 33046; - } else { - return 5671; - } - } else { - if (i == 178) { - return 10237; - } else { - return 64787; - } - } - } else { - if (i <= 181) { - if (i == 180) { - return 4962; - } else { - return 25196; - } - } else { - if (i == 182) { - return 27758; - } else { - return 28239; - } - } - } - } else { - if (i <= 187) { - if (i <= 185) { - if (i == 184) { - return 20337; - } else { - return 29152; - } - } else { - if (i == 186) { - return 57576; - } else { - return 59570; - } - } - } else { - if (i <= 189) { - if (i == 188) { - return 45753; - } else { - return 47472; - } - } else { - if (i == 190) { - return 28776; - } else { - return 26842; - } - } - } - } - } - } - } else { - if (i <= 223) { - if (i <= 207) { - if (i <= 199) { - if (i <= 195) { - if (i <= 193) { - if (i == 192) { - return 56054; - } else { - return 63073; - } - } else { - if (i == 194) { - return 25060; - } else { - return 58619; - } - } - } else { - if (i <= 197) { - if (i == 196) { - return 64290; - } else { - return 8946; - } - } else { - if (i == 198) { - return 62145; - } else { - return 49646; - } - } - } - } else { - if (i <= 203) { - if (i <= 201) { - if (i == 200) { - return 61138; - } else { - return 53904; - } - } else { - if (i == 202) { - return 36876; - } else { - return 3263; - } - } - } else { - if (i <= 205) { - if (i == 204) { - return 49075; - } else { - return 45986; - } - } else { - if (i == 206) { - return 41713; - } else { - return 61777; - } - } - } - } - } else { - if (i <= 215) { - if (i <= 211) { - if (i <= 209) { - if (i == 208) { - return 20787; - } else { - return 13201; - } - } else { - if (i == 210) { - return 37355; - } else { - return 60409; - } - } - } else { - if (i <= 213) { - if (i == 212) { - return 63758; - } else { - return 3823; - } - } else { - if (i == 214) { - return 61291; - } else { - return 27441; - } - } - } - } else { - if (i <= 219) { - if (i <= 217) { - if (i == 216) { - return 12736; - } else { - return 49366; - } - } else { - if (i == 218) { - return 54815; - } else { - return 8117; - } - } - } else { - if (i <= 221) { - if (i == 220) { - return 46535; - } else { - return 51050; - } - } else { - if (i == 222) { - return 27293; - } else { - return 40376; - } - } - } - } - } - } else { - if (i <= 239) { - if (i <= 231) { - if (i <= 227) { - if (i <= 225) { - if (i == 224) { - return 47188; - } else { - return 21708; - } - } else { - if (i == 226) { - return 52400; - } else { - return 45171; - } - } - } else { - if (i <= 229) { - if (i == 228) { - return 29561; - } else { - return 31026; - } - } else { - if (i == 230) { - return 12845; - } else { - return 11647; - } - } - } - } else { - if (i <= 235) { - if (i <= 233) { - if (i == 232) { - return 32516; - } else { - return 1174; - } - } else { - if (i == 234) { - return 38654; - } else { - return 65162; - } - } - } else { - if (i <= 237) { - if (i == 236) { - return 35564; - } else { - return 60621; - } - } else { - if (i == 238) { - return 52573; - } else { - return 24030; - } - } - } - } - } else { - if (i <= 247) { - if (i <= 243) { - if (i <= 241) { - if (i == 240) { - return 56946; - } else { - return 29251; - } - } else { - if (i == 242) { - return 17181; - } else { - return 7448; - } - } - } else { - if (i <= 245) { - if (i == 244) { - return 6216; - } else { - return 18675; - } - } else { - if (i == 246) { - return 62349; - } else { - return 36224; - } - } - } - } else { - if (i <= 251) { - if (i <= 249) { - if (i == 248) { - return 32963; - } else { - return 49998; - } - } else { - if (i == 250) { - return 20034; - } else { - return 17111; - } - } - } else { - if (i <= 253) { - if (i == 252) { - return 55101; - } else { - return 15772; - } - } else { - if (i == 254) { - return 40116; - } else { - return 46231; - } - } - } - } - } - } - } - } - } - - /** - * @notice Gets subsequent values in the fade table at an index. The values are encoded - * into a single 16 bit integer with the value at the specified index being the most - * significant 8 bits and the subsequent value being the least significant 8 bits. - * - * @param i the index in the fade table. - * - * @dev The values from the table are mapped out into a binary tree for faster lookups. - * Looking up any value in the table in this implementation is is O(8), in - * the implementation of sequential if statements it is O(256). - * - * @dev The body of this function is autogenerated. Check out the 'gen-ftable' script. - */ - function ftable(int256 i) internal pure returns (int256) { - if (i <= 127) { - if (i <= 63) { - if (i <= 31) { - if (i <= 15) { - if (i <= 7) { - if (i <= 3) { - if (i <= 1) { - if (i == 0) { - return 0; - } else { - return 0; - } - } else { - if (i == 2) { - return 0; - } else { - return 0; - } - } - } else { - if (i <= 5) { - if (i == 4) { - return 0; - } else { - return 0; - } - } else { - if (i == 6) { - return 0; - } else { - return 1; - } - } - } - } else { - if (i <= 11) { - if (i <= 9) { - if (i == 8) { - return 4097; - } else { - return 4098; - } - } else { - if (i == 10) { - return 8195; - } else { - return 12291; - } - } - } else { - if (i <= 13) { - if (i == 12) { - return 12292; - } else { - return 16390; - } - } else { - if (i == 14) { - return 24583; - } else { - return 28681; - } - } - } - } - } else { - if (i <= 23) { - if (i <= 19) { - if (i <= 17) { - if (i == 16) { - return 36874; - } else { - return 40972; - } - } else { - if (i == 18) { - return 49166; - } else { - return 57361; - } - } - } else { - if (i <= 21) { - if (i == 20) { - return 69651; - } else { - return 77846; - } - } else { - if (i == 22) { - return 90137; - } else { - return 102429; - } - } - } - } else { - if (i <= 27) { - if (i <= 25) { - if (i == 24) { - return 118816; - } else { - return 131108; - } - } else { - if (i == 26) { - return 147496; - } else { - return 163885; - } - } - } else { - if (i <= 29) { - if (i == 28) { - return 184369; - } else { - return 200758; - } - } else { - if (i == 30) { - return 221244; - } else { - return 245825; - } - } - } - } - } - } else { - if (i <= 47) { - if (i <= 39) { - if (i <= 35) { - if (i <= 33) { - if (i == 32) { - return 266311; - } else { - return 290893; - } - } else { - if (i == 34) { - return 315476; - } else { - return 344155; - } - } - } else { - if (i <= 37) { - if (i == 36) { - return 372834; - } else { - return 401513; - } - } else { - if (i == 38) { - return 430193; - } else { - return 462969; - } - } - } - } else { - if (i <= 43) { - if (i <= 41) { - if (i == 40) { - return 495746; - } else { - return 532619; - } - } else { - if (i == 42) { - return 569492; - } else { - return 606366; - } - } - } else { - if (i <= 45) { - if (i == 44) { - return 647335; - } else { - return 684210; - } - } else { - if (i == 46) { - return 729276; - } else { - return 770247; - } - } - } - } - } else { - if (i <= 55) { - if (i <= 51) { - if (i <= 49) { - if (i == 48) { - return 815315; - } else { - return 864478; - } - } else { - if (i == 50) { - return 909546; - } else { - return 958711; - } - } - } else { - if (i <= 53) { - if (i == 52) { - return 1011971; - } else { - return 1061137; - } - } else { - if (i == 54) { - return 1118494; - } else { - return 1171756; - } - } - } - } else { - if (i <= 59) { - if (i <= 57) { - if (i == 56) { - return 1229114; - } else { - return 1286473; - } - } else { - if (i == 58) { - return 1347928; - } else { - return 1409383; - } - } - } else { - if (i <= 61) { - if (i == 60) { - return 1470838; - } else { - return 1532294; - } - } else { - if (i == 62) { - return 1597847; - } else { - return 1667496; - } - } - } - } - } - } - } else { - if (i <= 95) { - if (i <= 79) { - if (i <= 71) { - if (i <= 67) { - if (i <= 65) { - if (i == 64) { - return 1737145; - } else { - return 1806794; - } - } else { - if (i == 66) { - return 1876444; - } else { - return 1950190; - } - } - } else { - if (i <= 69) { - if (i == 68) { - return 2023936; - } else { - return 2097683; - } - } else { - if (i == 70) { - return 2175526; - } else { - return 2253370; - } - } - } - } else { - if (i <= 75) { - if (i <= 73) { - if (i == 72) { - return 2335309; - } else { - return 2413153; - } - } else { - if (i == 74) { - return 2495094; - } else { - return 2581131; - } - } - } else { - if (i <= 77) { - if (i == 76) { - return 2667168; - } else { - return 2753205; - } - } else { - if (i == 78) { - return 2839243; - } else { - return 2929377; - } - } - } - } - } else { - if (i <= 87) { - if (i <= 83) { - if (i <= 81) { - if (i == 80) { - return 3019511; - } else { - return 3109646; - } - } else { - if (i == 82) { - return 3203877; - } else { - return 3298108; - } - } - } else { - if (i <= 85) { - if (i == 84) { - return 3392339; - } else { - return 3486571; - } - } else { - if (i == 86) { - return 3584899; - } else { - return 3683227; - } - } - } - } else { - if (i <= 91) { - if (i <= 89) { - if (i == 88) { - return 3781556; - } else { - return 3883981; - } - } else { - if (i == 90) { - return 3986406; - } else { - return 4088831; - } - } - } else { - if (i <= 93) { - if (i == 92) { - return 4191257; - } else { - return 4297778; - } - } else { - if (i == 94) { - return 4400204; - } else { - return 4506727; - } - } - } - } - } - } else { - if (i <= 111) { - if (i <= 103) { - if (i <= 99) { - if (i <= 97) { - if (i == 96) { - return 4617345; - } else { - return 4723868; - } - } else { - if (i == 98) { - return 4834487; - } else { - return 4945106; - } - } - } else { - if (i <= 101) { - if (i == 100) { - return 5055725; - } else { - return 5166345; - } - } else { - if (i == 102) { - return 5281060; - } else { - return 5391680; - } - } - } - } else { - if (i <= 107) { - if (i <= 105) { - if (i == 104) { - return 5506396; - } else { - return 5621112; - } - } else { - if (i == 106) { - return 5735829; - } else { - return 5854641; - } - } - } else { - if (i <= 109) { - if (i == 108) { - return 5969358; - } else { - return 6088171; - } - } else { - if (i == 110) { - return 6206983; - } else { - return 6321700; - } - } - } - } - } else { - if (i <= 119) { - if (i <= 115) { - if (i <= 113) { - if (i == 112) { - return 6440514; - } else { - return 6563423; - } - } else { - if (i == 114) { - return 6682236; - } else { - return 6801050; - } - } - } else { - if (i <= 117) { - if (i == 116) { - return 6923959; - } else { - return 7042773; - } - } else { - if (i == 118) { - return 7165682; - } else { - return 7284496; - } - } - } - } else { - if (i <= 123) { - if (i <= 121) { - if (i == 120) { - return 7407406; - } else { - return 7530316; - } - } else { - if (i == 122) { - return 7653226; - } else { - return 7776136; - } - } - } else { - if (i <= 125) { - if (i == 124) { - return 7899046; - } else { - return 8021956; - } - } else { - if (i == 126) { - return 8144866; - } else { - return 8267776; - } - } - } - } - } - } - } - } else { - if (i <= 191) { - if (i <= 159) { - if (i <= 143) { - if (i <= 135) { - if (i <= 131) { - if (i <= 129) { - if (i == 128) { - return 8390685; - } else { - return 8509499; - } - } else { - if (i == 130) { - return 8632409; - } else { - return 8755319; - } - } - } else { - if (i <= 133) { - if (i == 132) { - return 8878229; - } else { - return 9001139; - } - } else { - if (i == 134) { - return 9124049; - } else { - return 9246959; - } - } - } - } else { - if (i <= 139) { - if (i <= 137) { - if (i == 136) { - return 9369869; - } else { - return 9492778; - } - } else { - if (i == 138) { - return 9611592; - } else { - return 9734501; - } - } - } else { - if (i <= 141) { - if (i == 140) { - return 9853315; - } else { - return 9976224; - } - } else { - if (i == 142) { - return 10095037; - } else { - return 10213851; - } - } - } - } - } else { - if (i <= 151) { - if (i <= 147) { - if (i <= 145) { - if (i == 144) { - return 10336760; - } else { - return 10455572; - } - } else { - if (i == 146) { - return 10570289; - } else { - return 10689102; - } - } - } else { - if (i <= 149) { - if (i == 148) { - return 10807914; - } else { - return 10922631; - } - } else { - if (i == 150) { - return 11041443; - } else { - return 11156159; - } - } - } - } else { - if (i <= 155) { - if (i <= 153) { - if (i == 152) { - return 11270875; - } else { - return 11385590; - } - } else { - if (i == 154) { - return 11496210; - } else { - return 11610925; - } - } - } else { - if (i <= 157) { - if (i == 156) { - return 11721544; - } else { - return 11832163; - } - } else { - if (i == 158) { - return 11942782; - } else { - return 12053400; - } - } - } - } - } - } else { - if (i <= 175) { - if (i <= 167) { - if (i <= 163) { - if (i <= 161) { - if (i == 160) { - return 12159923; - } else { - return 12270541; - } - } else { - if (i == 162) { - return 12377062; - } else { - return 12479488; - } - } - } else { - if (i <= 165) { - if (i == 164) { - return 12586009; - } else { - return 12688434; - } - } else { - if (i == 166) { - return 12790859; - } else { - return 12893284; - } - } - } - } else { - if (i <= 171) { - if (i <= 169) { - if (i == 168) { - return 12995708; - } else { - return 13094036; - } - } else { - if (i == 170) { - return 13192364; - } else { - return 13290691; - } - } - } else { - if (i <= 173) { - if (i == 172) { - return 13384922; - } else { - return 13479153; - } - } else { - if (i == 174) { - return 13573384; - } else { - return 13667614; - } - } - } - } - } else { - if (i <= 183) { - if (i <= 179) { - if (i <= 177) { - if (i == 176) { - return 13757748; - } else { - return 13847882; - } - } else { - if (i == 178) { - return 13938015; - } else { - return 14024052; - } - } - } else { - if (i <= 181) { - if (i == 180) { - return 14110089; - } else { - return 14196126; - } - } else { - if (i == 182) { - return 14282162; - } else { - return 14364101; - } - } - } - } else { - if (i <= 187) { - if (i <= 185) { - if (i == 184) { - return 14441945; - } else { - return 14523884; - } - } else { - if (i == 186) { - return 14601727; - } else { - return 14679569; - } - } - } else { - if (i <= 189) { - if (i == 188) { - return 14753315; - } else { - return 14827061; - } - } else { - if (i == 190) { - return 14900806; - } else { - return 14970456; - } - } - } - } - } - } - } else { - if (i <= 223) { - if (i <= 207) { - if (i <= 199) { - if (i <= 195) { - if (i <= 193) { - if (i == 192) { - return 15044200; - } else { - return 15109753; - } - } else { - if (i == 194) { - return 15179401; - } else { - return 15244952; - } - } - } else { - if (i <= 197) { - if (i == 196) { - return 15306407; - } else { - return 15367862; - } - } else { - if (i == 198) { - return 15429317; - } else { - return 15490771; - } - } - } - } else { - if (i <= 203) { - if (i <= 201) { - if (i == 200) { - return 15548129; - } else { - return 15605486; - } - } else { - if (i == 202) { - return 15658748; - } else { - return 15716104; - } - } - } else { - if (i <= 205) { - if (i == 204) { - return 15765269; - } else { - return 15818529; - } - } else { - if (i == 206) { - return 15867692; - } else { - return 15912760; - } - } - } - } - } else { - if (i <= 215) { - if (i <= 211) { - if (i <= 209) { - if (i == 208) { - return 15961923; - } else { - return 16006989; - } - } else { - if (i == 210) { - return 16047960; - } else { - return 16093025; - } - } - } else { - if (i <= 213) { - if (i == 212) { - return 16129899; - } else { - return 16170868; - } - } else { - if (i == 214) { - return 16207741; - } else { - return 16244614; - } - } - } - } else { - if (i <= 219) { - if (i <= 217) { - if (i == 216) { - return 16281486; - } else { - return 16314262; - } - } else { - if (i == 218) { - return 16347037; - } else { - return 16375716; - } - } - } else { - if (i <= 221) { - if (i == 220) { - return 16404395; - } else { - return 16433074; - } - } else { - if (i == 222) { - return 16461752; - } else { - return 16486334; - } - } - } - } - } - } else { - if (i <= 239) { - if (i <= 231) { - if (i <= 227) { - if (i <= 225) { - if (i == 224) { - return 16510915; - } else { - return 16531401; - } - } else { - if (i == 226) { - return 16555982; - } else { - return 16576466; - } - } - } else { - if (i <= 229) { - if (i == 228) { - return 16592855; - } else { - return 16613339; - } - } else { - if (i == 230) { - return 16629727; - } else { - return 16646114; - } - } - } - } else { - if (i <= 235) { - if (i <= 233) { - if (i == 232) { - return 16658406; - } else { - return 16674793; - } - } else { - if (i == 234) { - return 16687084; - } else { - return 16699374; - } - } - } else { - if (i <= 237) { - if (i == 236) { - return 16707569; - } else { - return 16719859; - } - } else { - if (i == 238) { - return 16728053; - } else { - return 16736246; - } - } - } - } - } else { - if (i <= 247) { - if (i <= 243) { - if (i <= 241) { - if (i == 240) { - return 16740344; - } else { - return 16748537; - } - } else { - if (i == 242) { - return 16752635; - } else { - return 16760828; - } - } - } else { - if (i <= 245) { - if (i == 244) { - return 16764924; - } else { - return 16764925; - } - } else { - if (i == 246) { - return 16769022; - } else { - return 16773118; - } - } - } - } else { - if (i <= 251) { - if (i <= 249) { - if (i == 248) { - return 16773119; - } else { - return 16777215; - } - } else { - if (i == 250) { - return 16777215; - } else { - return 16777215; - } - } - } else { - if (i <= 253) { - if (i == 252) { - return 16777215; - } else { - return 16777215; - } - } else { - if (i == 254) { - return 16777215; - } else { - return 16777215; - } - } - } - } - } - } - } - } - } -} diff --git a/contracts/art/Trig.sol b/contracts/art/Trig.sol deleted file mode 100644 index c3ad3bf..0000000 --- a/contracts/art/Trig.sol +++ /dev/null @@ -1,891 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.19; - -library Trig { - /*--- - Trigonometry - Implementation 1 - ---*/ - - // Implementation 1 requires wrapping inputs between 2 * PI and 4 * PI to avoid precision errors, but it is more accurate than Implementation 2. - - /* - * Implementation by Matt Solomon, found here: https://github.com/mds1/solidity-trigonometry - * - * Solidity library offering basic trigonometry functions where inputs and outputs are - * integers. Inputs are specified in radians scaled by 1e18, and similarly outputs are scaled by 1e18. - * - * This implementation is based off the Solidity trigonometry library written by Lefteris Karapetsas - * which can be found here: https://github.com/Sikorkaio/sikorka/blob/e75c91925c914beaedf4841c0336a806f2b5f66d/contracts/trigonometry.sol - * - * Compared to Lefteris' implementation, this version makes the following changes: - * - Uses a 32 bits instead of 16 bits for improved accuracy - * - Updated for Solidity 0.8.x - * - Various gas optimizations - * - Change inputs/outputs to standard trig format (scaled by 1e18) instead of requiring the - * integer format used by the algorithm - * - * Lefertis' implementation is based off Dave Dribin's trigint C library - * http://www.dribin.org/dave/trigint/ - * - * Which in turn is based from a now deleted article which can be found in the Wayback Machine: - * http://web.archive.org/web/20120301144605/http://www.dattalo.com/technical/software/pic/picsine.html - */ - - // Table index into the trigonometric table - uint256 constant INDEX_WIDTH = 8; - // Interpolation between successive entries in the table - uint256 constant INTERP_WIDTH = 16; - uint256 constant INDEX_OFFSET = 28 - INDEX_WIDTH; - uint256 constant INTERP_OFFSET = INDEX_OFFSET - INTERP_WIDTH; - uint32 constant ANGLES_IN_CYCLE = 1073741824; - uint32 constant QUADRANT_HIGH_MASK = 536870912; - uint32 constant QUADRANT_LOW_MASK = 268435456; - uint256 constant SINE_TABLE_SIZE = 256; - - // Pi as an 18 decimal value, which is plenty of accuracy: "For JPL's highest accuracy calculations, which are for - // interplanetary navigation, we use 3.141592653589793: https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/ - uint256 constant PI = 3141592653589793238; - uint256 constant TWO_PI = 2 * PI; - uint256 constant PI_OVER_TWO = PI / 2; - - // The constant sine lookup table was generated by generate_trigonometry.py. We must use a constant - // bytes array because constant arrays are not supported in Solidity. Each entry in the lookup - // table is 4 bytes. Since we're using 32-bit parameters for the lookup table, we get a table size - // of 2^(32/4) + 1 = 257, where the first and last entries are equivalent (hence the table size of - // 256 defined above) - uint8 constant entry_bytes = 4; // each entry in the lookup table is 4 bytes - uint256 constant entry_mask = ((1 << (8 * entry_bytes)) - 1); // mask used to cast bytes32 -> lookup table entry - bytes constant sin_table = - hex"0000000000c90f8801921d20025b26d703242abf03ed26e604b6195d057f00350647d97c0710a34507d95b9e08a2009a096a90490a3308bc0afb68050bc3ac350c8bd35e0d53db920e1bc2e40ee387660fab272b1072a0481139f0cf120116d512c8106e138edbb1145576b1151bdf8515e2144416a81305176dd9de183366e818f8b83c19bdcbf31a82a0251b4732ef1c0b826a1ccf8cb31d934fe51e56ca1e1f19f97b1fdcdc1b209f701c2161b39f2223a4c522e541af23a6887e2467775725280c5d25e845b626a8218527679df42826b92828e5714a29a3c4852a61b1012b1f34eb2bdc4e6f2c98fbba2d553afb2e110a622ecc681e2f8752623041c76030fbc54d31b54a5d326e54c73326e2c233def2873496824f354d905636041ad936ba2013376f9e46382493b038d8fe93398cdd323a402dd13af2eeb73ba51e293c56ba703d07c1d53db832a53e680b2c3f1749b73fc5ec974073f21d4121589a41ce1e64427a41d04325c13543d09aec447acd50452456bc45cd358f46756827471cece647c3c22e4869e664490f57ee49b415334a581c9d4afb6c974b9e038f4c3fdff34ce100344d8162c34e2106174ebfe8a44f5e08e24ffb654c5097fc5e5133cc9451ced46e5269126e53028517539b2aef5433027d54ca0a4a556040e255f5a4d2568a34a9571deef957b0d2555842dd5458d40e8c5964649759f3de125a8279995b1035ce5b9d11535c290acc5cb420df5d3e52365dc79d7b5e50015d5ed77c895f5e0db25fe3b38d60686cce60ec382f616f146b61f1003e6271fa6862f201ac637114cc63ef328f646c59bf64e889256563bf9165ddfbd266573cbb66cf811f6746c7d767bd0fbc683257aa68a69e806919e31f698c246b69fd614a6a6d98a36adcc9646b4af2786bb812d06c24295f6c8f351b6cf934fb6d6227f96dca0d146e30e3496e96a99c6efb5f116f5f02b16fc1938470231099708378fe70e2cbc571410804719e2cd171fa394872552c8472af05a67307c3cf735f662573b5ebd0740b53fa745f9dd074b2c8837504d3447555bd4b75a585ce75f42c0a7641af3c768e0ea576d9498877235f2c776c4eda77b417df77fab988784033287884841378c7aba17909a92c794a7c11798a23b079c89f6d7a05eeac7a4210d87a7d055a7ab6cba37aef63237b26cb4e7b5d039d7b920b887bc5e28f7bf8882f7c29fbed7c5a3d4f7c894bdd7cb727237ce3ceb17d0f42177d3980eb7d628ac57d8a5f3f7db0fdf77dd6668e7dfa98a77e1d93e97e3f57fe7e5fe4927e7f39567e9d55fb7eba3a387ed5e5c57ef0585f7f0991c37f2191b37f3857f57f4de4507f62368e7f754e7f7f872bf27f97cebc7fa736b37fb563b27fc255957fce0c3d7fd8878d7fe1c76a7fe9cbbf7ff094777ff621817ffa72d07ffd88597fff62157fffffff"; - - /** - * @notice Return the sine of a value, specified in radians scaled by 1e18 - * @dev This algorithm for converting sine only uses integer values, and it works by dividing the - * circle into 30 bit angles, i.e. there are 1,073,741,824 (2^30) angle units, instead of the - * standard 360 degrees (2pi radians). From there, we get an output in range -2,147,483,647 to - * 2,147,483,647, (which is the max value of an int32) which is then converted back to the standard - * range of -1 to 1, again scaled by 1e18 - * @param _angle Angle to convert - * @return Result scaled by 1e18 - */ - function sin(uint256 _angle) public pure returns (int256) { - unchecked { - // Convert angle from from arbitrary radian value (range of 0 to 2pi) to the algorithm's range - // of 0 to 1,073,741,824 - _angle = (ANGLES_IN_CYCLE * (_angle % TWO_PI)) / TWO_PI; - - // Apply a mask on an integer to extract a certain number of bits, where angle is the integer - // whose bits we want to get, the width is the width of the bits (in bits) we want to extract, - // and the offset is the offset of the bits (in bits) we want to extract. The result is an - // integer containing _width bits of _value starting at the offset bit - uint256 interp = (_angle >> INTERP_OFFSET) & ((1 << INTERP_WIDTH) - 1); - uint256 index = (_angle >> INDEX_OFFSET) & ((1 << INDEX_WIDTH) - 1); - - // The lookup table only contains data for one quadrant (since sin is symmetric around both - // axes), so here we figure out which quadrant we're in, then we lookup the values in the - // table then modify values accordingly - bool is_odd_quadrant = (_angle & QUADRANT_LOW_MASK) == 0; - bool is_negative_quadrant = (_angle & QUADRANT_HIGH_MASK) != 0; - - if (!is_odd_quadrant) { - index = SINE_TABLE_SIZE - 1 - index; - } - - bytes memory table = sin_table; - // We are looking for two consecutive indices in our lookup table - // Since EVM is left aligned, to read n bytes of data from idx i, we must read from `i * data_len` + `n` - // therefore, to read two entries of size entry_bytes `index * entry_bytes` + `entry_bytes * 2` - uint256 offset1_2 = (index + 2) * entry_bytes; - - // This following snippet will function for any entry_bytes <= 15 - uint256 x1_2; - assembly { - // mload will grab one word worth of bytes (32), as that is the minimum size in EVM - x1_2 := mload(add(table, offset1_2)) - } - - // We now read the last two numbers of size entry_bytes from x1_2 - // in example: entry_bytes = 4; x1_2 = 0x00...12345678abcdefgh - // therefore: entry_mask = 0xFFFFFFFF - - // 0x00...12345678abcdefgh >> 8*4 = 0x00...12345678 - // 0x00...12345678 & 0xFFFFFFFF = 0x12345678 - uint256 x1 = (x1_2 >> (8 * entry_bytes)) & entry_mask; - // 0x00...12345678abcdefgh & 0xFFFFFFFF = 0xabcdefgh - uint256 x2 = x1_2 & entry_mask; - - // Approximate angle by interpolating in the table, accounting for the quadrant - uint256 approximation = ((x2 - x1) * interp) >> INTERP_WIDTH; - int256 sine = is_odd_quadrant ? int256(x1) + int256(approximation) : int256(x2) - int256(approximation); - if (is_negative_quadrant) { - sine *= -1; - } - - // Bring result from the range of -2,147,483,647 through 2,147,483,647 to -1e18 through 1e18. - // This can never overflow because sine is bounded by the above values - return (sine * 1e18) / 2_147_483_647; - } - } - - /** - * @notice Return the cosine of a value, specified in radians scaled by 1e18 - * @dev This is identical to the sin() method, and just computes the value by delegating to the - * sin() method using the identity cos(x) = sin(x + pi/2) - * @dev Overflow when `angle + PI_OVER_TWO > type(uint256).max` is ok, results are still accurate - * @param _angle Angle to convert - * @return Result scaled by 1e18 - */ - function cos(uint256 _angle) public pure returns (int256) { - unchecked { - return sin(_angle + PI_OVER_TWO); - } - } - - /*--- - Trigonometry - Implementation 2 - ---*/ - - // Implementation 2 is less accurate than Implementation 1, but it allows for unbounded input in degrees. Output should be downscaled by 1e6. Sintable array loaded twice to avoid stack too deep errors. - - //Computes sine using degrees unit input. - function dsin(int256 degrees) external pure returns (int256) { - int256[360] memory sintable = [ - int256(0), - 17452, - 34899, - 52336, - 69756, - 87156, - 104528, - 121869, - 139173, - 156434, - 173648, - 190809, - 207912, - 224951, - 241922, - 258819, - 275637, - 292372, - 309017, - 325568, - 342020, - 358368, - 374607, - 390731, - 406737, - 422618, - 438371, - 453990, - 469472, - 484810, - 500000, - 515038, - 529919, - 544639, - 559193, - 573576, - 587785, - 601815, - 615661, - 629320, - 642788, - 656059, - 669131, - 681998, - 694658, - 707107, - 719340, - 731354, - 743145, - 754710, - 766044, - 777146, - 788011, - 798636, - 809017, - 819152, - 829038, - 838671, - 848048, - 857167, - 866025, - 874620, - 882948, - 891007, - 898794, - 906308, - 913545, - 920505, - 927184, - 933580, - 939693, - 945519, - 951057, - 956305, - 961262, - 965926, - 970296, - 974370, - 978148, - 981627, - 984808, - 987688, - 990268, - 992546, - 994522, - 996195, - 997564, - 998630, - 999391, - 999848, - 1000000, - 999848, - 999391, - 998630, - 997564, - 996195, - 994522, - 992546, - 990268, - 987688, - 984808, - 981627, - 978148, - 974370, - 970296, - 965926, - 961262, - 956305, - 951057, - 945519, - 939693, - 933580, - 927184, - 920505, - 913545, - 906308, - 898794, - 891007, - 882948, - 874620, - 866025, - 857167, - 848048, - 838671, - 829038, - 819152, - 809017, - 798636, - 788011, - 777146, - 766044, - 754710, - 743145, - 731354, - 719340, - 707107, - 694658, - 681998, - 669131, - 656059, - 642788, - 629320, - 615661, - 601815, - 587785, - 573576, - 559193, - 544639, - 529919, - 515038, - 500000, - 484810, - 469472, - 453990, - 438371, - 422618, - 406737, - 390731, - 374607, - 358368, - 342020, - 325568, - 309017, - 292372, - 275637, - 258819, - 241922, - 224951, - 207912, - 190809, - 173648, - 156434, - 139173, - 121869, - 104528, - 87156, - 69756, - 52336, - 34899, - 17452, - 0, - -17452, - -34899, - -52336, - -69756, - -87156, - -104528, - -121869, - -139173, - -156434, - -173648, - -190809, - -207912, - -224951, - -241922, - -258819, - -275637, - -292372, - -309017, - -325568, - -342020, - -358368, - -374607, - -390731, - -406737, - -422618, - -438371, - -453990, - -469472, - -484810, - -500000, - -515038, - -529919, - -544639, - -559193, - -573576, - -587785, - -601815, - -615661, - -629320, - -642788, - -656059, - -669131, - -681998, - -694658, - -707107, - -719340, - -731354, - -743145, - -754710, - -766044, - -777146, - -788011, - -798636, - -809017, - -819152, - -829038, - -838671, - -848048, - -857167, - -866025, - -874620, - -882948, - -891007, - -898794, - -906308, - -913545, - -920505, - -927184, - -933580, - -939693, - -945519, - -951057, - -956305, - -961262, - -965926, - -970296, - -974370, - -978148, - -981627, - -984808, - -987688, - -990268, - -992546, - -994522, - -996195, - -997564, - -998630, - -999391, - -999848, - -1000000, - -999848, - -999391, - -998630, - -997564, - -996195, - -994522, - -992546, - -990268, - -987688, - -984808, - -981627, - -978148, - -974370, - -970296, - -965926, - -961262, - -956305, - -951057, - -945519, - -939693, - -933580, - -927184, - -920505, - -913545, - -906308, - -898794, - -891007, - -882948, - -874620, - -866025, - -857167, - -848048, - -838671, - -829038, - -819152, - -809017, - -798636, - -788011, - -777146, - -766044, - -754710, - -743145, - -731354, - -719340, - -707107, - -694658, - -681998, - -669131, - -656059, - -642788, - -629320, - -615661, - -601815, - -587785, - -573576, - -559193, - -544639, - -529919, - -515038, - -500000, - -484810, - -469472, - -453990, - -438371, - -422618, - -406737, - -390731, - -374607, - -358368, - -342020, - -325568, - -309017, - -292372, - -275637, - -258819, - -241922, - -224951, - -207912, - -190809, - -173648, - -156434, - -139173, - -121869, - -104528, - -87156, - -69756, - -52336, - -34899, - -17452 - ]; - if (degrees > -1) { - return sintable[uint256(degrees) % 360]; - } else { - return sintable[uint256(degrees * -1) % 360] * -1; - } - } - - //Computes cosine with degrees unit input. - function dcos(int256 degrees) external pure returns (int256) { - int256[360] memory sintable = [ - int256(0), - 17452, - 34899, - 52336, - 69756, - 87156, - 104528, - 121869, - 139173, - 156434, - 173648, - 190809, - 207912, - 224951, - 241922, - 258819, - 275637, - 292372, - 309017, - 325568, - 342020, - 358368, - 374607, - 390731, - 406737, - 422618, - 438371, - 453990, - 469472, - 484810, - 500000, - 515038, - 529919, - 544639, - 559193, - 573576, - 587785, - 601815, - 615661, - 629320, - 642788, - 656059, - 669131, - 681998, - 694658, - 707107, - 719340, - 731354, - 743145, - 754710, - 766044, - 777146, - 788011, - 798636, - 809017, - 819152, - 829038, - 838671, - 848048, - 857167, - 866025, - 874620, - 882948, - 891007, - 898794, - 906308, - 913545, - 920505, - 927184, - 933580, - 939693, - 945519, - 951057, - 956305, - 961262, - 965926, - 970296, - 974370, - 978148, - 981627, - 984808, - 987688, - 990268, - 992546, - 994522, - 996195, - 997564, - 998630, - 999391, - 999848, - 1000000, - 999848, - 999391, - 998630, - 997564, - 996195, - 994522, - 992546, - 990268, - 987688, - 984808, - 981627, - 978148, - 974370, - 970296, - 965926, - 961262, - 956305, - 951057, - 945519, - 939693, - 933580, - 927184, - 920505, - 913545, - 906308, - 898794, - 891007, - 882948, - 874620, - 866025, - 857167, - 848048, - 838671, - 829038, - 819152, - 809017, - 798636, - 788011, - 777146, - 766044, - 754710, - 743145, - 731354, - 719340, - 707107, - 694658, - 681998, - 669131, - 656059, - 642788, - 629320, - 615661, - 601815, - 587785, - 573576, - 559193, - 544639, - 529919, - 515038, - 500000, - 484810, - 469472, - 453990, - 438371, - 422618, - 406737, - 390731, - 374607, - 358368, - 342020, - 325568, - 309017, - 292372, - 275637, - 258819, - 241922, - 224951, - 207912, - 190809, - 173648, - 156434, - 139173, - 121869, - 104528, - 87156, - 69756, - 52336, - 34899, - 17452, - 0, - -17452, - -34899, - -52336, - -69756, - -87156, - -104528, - -121869, - -139173, - -156434, - -173648, - -190809, - -207912, - -224951, - -241922, - -258819, - -275637, - -292372, - -309017, - -325568, - -342020, - -358368, - -374607, - -390731, - -406737, - -422618, - -438371, - -453990, - -469472, - -484810, - -500000, - -515038, - -529919, - -544639, - -559193, - -573576, - -587785, - -601815, - -615661, - -629320, - -642788, - -656059, - -669131, - -681998, - -694658, - -707107, - -719340, - -731354, - -743145, - -754710, - -766044, - -777146, - -788011, - -798636, - -809017, - -819152, - -829038, - -838671, - -848048, - -857167, - -866025, - -874620, - -882948, - -891007, - -898794, - -906308, - -913545, - -920505, - -927184, - -933580, - -939693, - -945519, - -951057, - -956305, - -961262, - -965926, - -970296, - -974370, - -978148, - -981627, - -984808, - -987688, - -990268, - -992546, - -994522, - -996195, - -997564, - -998630, - -999391, - -999848, - -1000000, - -999848, - -999391, - -998630, - -997564, - -996195, - -994522, - -992546, - -990268, - -987688, - -984808, - -981627, - -978148, - -974370, - -970296, - -965926, - -961262, - -956305, - -951057, - -945519, - -939693, - -933580, - -927184, - -920505, - -913545, - -906308, - -898794, - -891007, - -882948, - -874620, - -866025, - -857167, - -848048, - -838671, - -829038, - -819152, - -809017, - -798636, - -788011, - -777146, - -766044, - -754710, - -743145, - -731354, - -719340, - -707107, - -694658, - -681998, - -669131, - -656059, - -642788, - -629320, - -615661, - -601815, - -587785, - -573576, - -559193, - -544639, - -529919, - -515038, - -500000, - -484810, - -469472, - -453990, - -438371, - -422618, - -406737, - -390731, - -374607, - -358368, - -342020, - -325568, - -309017, - -292372, - -275637, - -258819, - -241922, - -224951, - -207912, - -190809, - -173648, - -156434, - -139173, - -121869, - -104528, - -87156, - -69756, - -52336, - -34899, - -17452 - ]; - if ((degrees + 90) > -1) { - return sintable[uint256(degrees + 90) % 360]; - } else { - return sintable[uint256((degrees + 90) * -1) % 360] * -1; - } - } -} diff --git a/contracts/factories/GaugeFactory.sol b/contracts/factories/GaugeFactory.sol index e52de1e..aa503de 100644 --- a/contracts/factories/GaugeFactory.sol +++ b/contracts/factories/GaugeFactory.sol @@ -44,7 +44,7 @@ contract GaugeFactory is IGaugeFactory { gauge = address(new DeviceGauge(_forwarder, _deviceNFT, msg.sender, _incentives)); } - function createWithdrawalGauge(address _guage) internal returns (address gauge) { + function createWithdrawalGauge(address _guage) internal pure returns (address gauge) { gauge = _guage; } } diff --git a/contracts/factories/IncentivesFactory.sol b/contracts/factories/IncentivesFactory.sol index 0cca28d..488f079 100644 --- a/contracts/factories/IncentivesFactory.sol +++ b/contracts/factories/IncentivesFactory.sol @@ -6,7 +6,7 @@ import {Incentives} from "../rewards/Incentive.sol"; contract IncentivesFactory is IIncentivesFactory { /// @inheritdoc IIncentivesFactory - function createRewards(address _forwarder, address _pool) external returns (address incentiveReward) { + function createRewards(address _forwarder, address /**_pool**/) external returns (address incentiveReward) { incentiveReward = address(new Incentives(_forwarder, msg.sender, new address[](0))); } } diff --git a/test/TestGauge.t.sol b/test/TestGauge.t.sol index 14c5892..b070afa 100644 --- a/test/TestGauge.t.sol +++ b/test/TestGauge.t.sol @@ -21,8 +21,6 @@ contract TestERC20Gauge is Test { Voter public voter; TestStrategyManager public strategyManager; - fallback() external payable {} - function setUp() public { pool = new TestToken("lp_pool", "pool"); forwarder = new DAOForwarder(); diff --git a/test/TestIncentive.sol b/test/TestIncentive.sol index a42dd9c..a4b4a44 100644 --- a/test/TestIncentive.sol +++ b/test/TestIncentive.sol @@ -30,11 +30,11 @@ contract TestIncentive is Test { Incentives public dinti; function onERC721Received( - address operator, - address from, - uint256 tokenId, - bytes calldata data - ) external returns (bytes4) { + address /**operator**/, + address /**from**/, + uint256 /**tokenId**/, + bytes calldata /**data**/ + ) external pure returns (bytes4) { return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")); } diff --git a/test/TestVault.t.sol b/test/TestVault.t.sol index b061061..01daaf7 100644 --- a/test/TestVault.t.sol +++ b/test/TestVault.t.sol @@ -84,6 +84,4 @@ contract TestVault is Test { assertEq(address(strategyManager).balance, vault.weekly() / 10); assertEq(address(voter).balance, (90 * vault.weekly()) / 100); } - - fallback() external payable {} }