BEP-20
Source Code
Overview
Max Total Supply
245,377.6138sOSP
Holders
9,721
Transfers
-
0
Market
Price
$0.00 @ 0.000000 BNB
Onchain Market Cap
-
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Loading...
Loading
Loading...
Loading
Loading...
Loading
Contract Name:
Staking
Compiler Version
v0.8.22+commit.4fc1097e
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {UD60x18, ud} from "@prb/math/src/UD60x18.sol";
import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Pair} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import {IOSP} from "./interface/IOSP.sol";
import {IPool} from "./interface/IPool.sol";
import {IReferral} from "./interface/IReferral.sol";
import {Owned} from "solmate/src/auth/Owned.sol";
import {_OSK, _ROUTER} from "./Const.sol";
contract Staking is Owned {
uint256[] public levelThresholds;
uint256[] public levelSelfStakeThresholds;
uint256[] public teamLevelRates;
uint256 public maxReferralDepth = 50;
event Staked(
address indexed user,
uint256 amount,
uint256 timestamp,
uint256 index,
uint256 stakeTime
);
event RewardPaid(
address indexed user,
uint256 reward,
uint40 timestamp,
uint256 index
);
event Transfer(address indexed from, address indexed to, uint256 amount);
uint256[5] rates = [1000000069236900000,1000000092224200000,1000000115165900000,
1000000138062200000,1000000160913300000]; // test: 1000099706164955000,1000132811646172000,1000165852599575000,1000198829278342000,1000231741934164000
uint256[5] stakeDays = [7 days,15 days,30 days,45 days,60 days]; // test: minutes
IUniswapV2Router02 constant ROUTER = IUniswapV2Router02(_ROUTER);
IERC20 constant OSK = IERC20(_OSK);
IOSP public OSP;
IReferral public REFERRAL;
address marketingAddress;
address public s5Address;
address public s6Address;
address public s7Address;
address public s8Address;
uint256 public s5Count;
uint256 public s6Count;
uint256 public s7Count;
uint256 public s8Count;
uint256 public s5Rate = 3;
uint256 public s6Rate = 1;
uint256 public s7Rate = 1;
uint256 public s8Rate = 2;
uint8 public constant decimals = 18;
string public constant name = "Staked OSP";
string public constant symbol = "sOSP";
uint256 public totalSupply;
mapping(address => uint256) public balances;
mapping(address => uint256) public userIndex;
mapping(address => Record[]) public userStakeRecord;
mapping(address => uint256) public teamTotalInvestValue;
mapping(address => uint256) public teamVirtuallyInvestValue;
mapping(address => uint256) public teamVirtuallySelfStake;
mapping(address => bool) public whitelist;
// uint8 immutable maxD = 30;
RecordTT[] public t_supply;
// Risk Control Params
uint256 public networkInTimeLimit = 6 minutes;
uint256 public maxStakeAbsLimit = 100 ether;
uint256 public maxStakeRatio = 100; // Basis points: 100 = 1%
uint256 public maxPoolOSKAmount = 100000 * 1e18;
uint256 public extraStakeLimit = 0.5 * 1e18;
uint256 public unstakeTimeWindow = 1 days;
uint256 public unstakeRate = 1000; // 100 = 1%
RecordTT[] public t_out;
uint256 public totalUnstaked;
uint256 public returnPrincipalOSPRatio;
uint256 public preacherThreshold = 3e18;
address public operator;
struct RecordTT {
uint40 stakeTime;
uint160 tamount;
}
struct Record {
uint40 stakeTime;
uint160 amount;
bool status;
uint8 stakeIndex;
uint256 finalReward; // Reward at the time of unstake
uint256 id;
}
modifier onlyEOA() {
require(tx.origin == msg.sender, "EOA");
_;
}
modifier onlyOperatorOrOwner() {
require(msg.sender == owner || msg.sender == operator, "Not authorized");
_;
}
constructor(address REFERRAL_,address marketingAddress_) Owned(msg.sender) {
REFERRAL = IReferral(REFERRAL_);
marketingAddress = marketingAddress_;
OSK.approve(address(ROUTER), type(uint256).max);
// Initialize default thresholds
levelThresholds = [
30 * 10**18, // test: 30
300 * 10**18, // test: 60
1000 * 10**18, // test: 90
5000 * 10**18, // test: 120
10000 * 10**18, // test: 150
30000 * 10**18, // test: 180
50000 * 10**18, // test: 210
1000000 * 10**18 // test: 240
];
levelSelfStakeThresholds = [
0,
0,
0,
0,
0,
0,
0,
0
];
// Initialize default rates
teamLevelRates = [4, 8, 12, 16, 20, 24, 28, 28];
}
function setLevelThresholds(uint256[] memory newThresholds) external onlyOperatorOrOwner {
require(newThresholds.length == 8, "Length must be 8");
levelThresholds = newThresholds;
}
function setLevelSelfStakeThresholds(uint256[] memory newThresholds) external onlyOperatorOrOwner {
require(newThresholds.length == 8, "Length must be 8");
levelSelfStakeThresholds = newThresholds;
}
function setTeamLevelRates(uint256[] memory newRates) external onlyOperatorOrOwner {
require(newRates.length == 8, "Length must be 8");
teamLevelRates = newRates;
}
function setProductConfig(uint256[] memory _stakeDays, uint256[] memory _rates) external onlyOperatorOrOwner {
require(_stakeDays.length == 5, "Length must be 5");
require(_rates.length == 5, "Length must be 5");
for (uint256 i = 0; i < 5; i++) {
stakeDays[i] = _stakeDays[i];
rates[i] = _rates[i];
}
}
function setMaxReferralDepth(uint256 _depth) external onlyOperatorOrOwner {
maxReferralDepth = _depth;
}
function setOSP(address _osp) external onlyOwner {
OSP = IOSP(_osp);
OSP.approve(address(ROUTER), type(uint256).max);
}
function setTeamVirtuallyInvestValue(address _user, uint256 _value)
external
onlyOperatorOrOwner
{
uint256 oldKpi = getTeamKpi(_user);
uint256 currentStake = getSelfStake(_user);
teamVirtuallyInvestValue[_user] = _value;
uint256 newKpi = teamTotalInvestValue[_user] + _value;
_updateLevelChange(_user, oldKpi, newKpi, currentStake, currentStake);
}
function setTeamVirtuallySelfStake(address _user, uint256 _value)
external
onlyOperatorOrOwner
{
uint256 currentKpi = getTeamKpi(_user);
uint256 oldStake = getSelfStake(_user);
teamVirtuallySelfStake[_user] = _value;
uint256 newStake = balances[_user] + _value;
_updateLevelChange(_user, currentKpi, currentKpi, oldStake, newStake);
}
function setWhitelist(address[] memory users, bool status) external onlyOperatorOrOwner {
for (uint256 i = 0; i < users.length; i++) {
whitelist[users[i]] = status;
}
}
function setMarketingAddress(address _account) external onlyOwner{
marketingAddress = _account;
}
function setS5Address(address _addr) external onlyOwner {
s5Address = _addr;
}
function setS6Address(address _addr) external onlyOwner {
s6Address = _addr;
}
function setS7Address(address _addr) external onlyOwner {
s7Address = _addr;
}
function setS8Address(address _addr) external onlyOwner {
s8Address = _addr;
}
function setPoolRates(uint256 _s5Rate, uint256 _s6Rate, uint256 _s7Rate, uint256 _s8Rate) external onlyOperatorOrOwner {
s5Rate = _s5Rate;
s6Rate = _s6Rate;
s7Rate = _s7Rate;
s8Rate = _s8Rate;
}
function setOperator(address _operator) external onlyOwner {
operator = _operator;
}
function setReturnPrincipalOSPRatio(uint256 _ratio) external onlyOperatorOrOwner {
require(_ratio <= 100, "Ratio <= 100");
returnPrincipalOSPRatio = _ratio;
}
function setUnstakeConfig(
uint256 _timeWindow,
uint256 _rate
) external onlyOperatorOrOwner {
unstakeTimeWindow = _timeWindow;
unstakeRate = _rate;
}
function setRiskParameters(
uint256 _networkInTimeLimit,
uint256 _maxStakeAbsLimit,
uint256 _maxStakeRatio,
uint256 _extraStakeLimit
) external onlyOperatorOrOwner {
networkInTimeLimit = _networkInTimeLimit;
maxStakeAbsLimit = _maxStakeAbsLimit;
maxStakeRatio = _maxStakeRatio;
extraStakeLimit = _extraStakeLimit;
}
function setMaxPoolOSKAmount(uint256 _maxPoolOSKAmount) external onlyOperatorOrOwner {
maxPoolOSKAmount = _maxPoolOSKAmount;
}
function setPreacherThreshold(uint256 _threshold) external onlyOperatorOrOwner {
preacherThreshold = _threshold;
}
function network1In() public view returns (uint256 value) {
uint256 len = t_supply.length;
if (len == 0) return 0;
uint256 one_last_time = block.timestamp - networkInTimeLimit;
uint256 last_supply = totalSupply;
// |
// t0 t1 | t2 t3 t4 t5
// |
for (uint256 i = len - 1; i >= 0; i--) {
RecordTT storage stake_tt = t_supply[i];
if (one_last_time > stake_tt.stakeTime) {
break;
} else {
last_supply = stake_tt.tamount;
}
if (i == 0) break;
}
return totalSupply - last_supply;
}
function maxStakeAmount() public view returns (uint256) {
uint256 lastIn = network1In();
uint112 reverseu = OSP.getReserveU();
uint256 currentPoolOSK = uint256(reverseu);
uint256 p1 = currentPoolOSK * maxStakeRatio / 10000;
uint256 limitByNetwork;
if (lastIn > p1) {
limitByNetwork = 0;
} else {
limitByNetwork = Math.min256(p1 - lastIn, maxStakeAbsLimit);
}
uint256 limitByCap;
if (currentPoolOSK < maxPoolOSKAmount) {
uint256 remaining = maxPoolOSKAmount - currentPoolOSK;
limitByCap = remaining > extraStakeLimit ? remaining : extraStakeLimit;
} else {
limitByCap = extraStakeLimit;
}
return Math.min256(limitByNetwork, limitByCap);
}
function network24hOut() public view returns (uint256 value) {
uint256 len = t_out.length;
if (len == 0) return 0;
uint256 one_day_ago = block.timestamp - unstakeTimeWindow;
uint256 baseline = 0;
for (uint256 i = len - 1; i >= 0; i--) {
RecordTT storage out_tt = t_out[i];
if (out_tt.stakeTime < one_day_ago) {
baseline = out_tt.tamount;
break;
}
if (i == 0) break;
}
return totalUnstaked - baseline;
}
function maxUnstakeAmount() public view returns (uint256) {
uint256 lastOut = network24hOut();
uint112 reverseu = OSP.getReserveU();
uint256 limit = uint256(reverseu) * unstakeRate / 10000;
if (lastOut >= limit) return 0;
else return limit - lastOut;
}
function stake(uint160 _amount, uint256 amountOutMin,uint8 _stakeIndex) external onlyEOA {
require(_amount <= maxStakeAmount(), "Over Limit");
require(_stakeIndex<=4,"<=4");
if (_stakeIndex == 4) {
require(whitelist[msg.sender], "Only whitelist");
}
swapAndAddLiquidity(_amount, amountOutMin);
mint(msg.sender, _amount,_stakeIndex);
}
function stakeWithInviter(
uint160 _amount,
uint256 amountOutMin,
uint8 _stakeIndex,
address parent
) external onlyEOA {
require(_amount <= maxStakeAmount(), "Over Limit");
require(_stakeIndex<=4,"<=4");
if (_stakeIndex == 4) {
require(whitelist[msg.sender], "Only whitelist");
}
swapAndAddLiquidity(_amount, amountOutMin);
address user = msg.sender;
if (!REFERRAL.isBindReferral(user) && REFERRAL.isBindReferral(parent)) {
REFERRAL.bindReferral(parent, user);
}
mint(user, _amount,_stakeIndex);
}
function swapAndAddLiquidity(uint160 _amount, uint256 amountOutMin)
private
{
OSK.transferFrom(msg.sender, address(this), _amount);
address[] memory path = new address[](2);
path = new address[](2);
path[0] = address(OSK);
path[1] = address(OSP);
uint256 balb = OSP.balanceOf(address(this));
ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
_amount / 2,
amountOutMin,
path,
address(this),
block.timestamp
);
uint256 bala = OSP.balanceOf(address(this));
ROUTER.addLiquidity(
address(OSK),
address(OSP),
_amount / 2,
bala - balb,
0, // slippage is unavoidable
0, // slippage is unavoidable
address(0),
block.timestamp
);
}
function mint(address sender, uint160 _amount,uint8 _stakeIndex) private {
require(REFERRAL.isBindReferral(sender),"!!bind");
RecordTT memory tsy;
tsy.stakeTime = uint40(block.timestamp);
tsy.tamount = uint160(totalSupply);
t_supply.push(tsy);
Record[] storage cord = userStakeRecord[sender];
uint256 stake_index = cord.length;
Record memory order;
order.stakeTime = uint40(block.timestamp);
order.amount = _amount;
order.status = false;
order.stakeIndex = _stakeIndex;
order.id = stake_index;
totalSupply += _amount;
balances[sender] += _amount;
cord.push(order);
address[] memory referrals = REFERRAL.getReferrals(sender, maxReferralDepth);
for (uint256 i = 0; i < referrals.length; i++) {
address referral = referrals[i];
uint256 oldKpi = getTeamKpi(referral);
uint256 referralSelfStake = getSelfStake(referral);
teamTotalInvestValue[referral] += _amount;
_updateLevelChange(referral, oldKpi, oldKpi + _amount, referralSelfStake, referralSelfStake);
}
uint256 senderOldKpi = getTeamKpi(sender);
uint256 currentStake = getSelfStake(sender);
// sender balance updated before call, so currentStake is the new stake
_updateLevelChange(sender, senderOldKpi, senderOldKpi, currentStake - _amount, currentStake);
emit Transfer(address(0), sender, _amount);
emit Staked(sender, _amount, block.timestamp, stake_index,stakeDays[_stakeIndex]);
}
function balanceOf(address account)
external
view
returns (uint256 balance)
{
Record[] storage cord = userStakeRecord[account];
if (cord.length > 0) {
for (uint256 i = cord.length - 1; i >= 0; i--) {
Record storage user_record = cord[i];
if (user_record.status == false) {
balance += caclItem(user_record);
}
// else {
// continue;
// }
if (i == 0) break;
}
}
}
function caclItem(Record storage user_record)
private
view
returns (uint256 reward)
{
UD60x18 stake_amount = ud(user_record.amount);
uint40 stake_time = user_record.stakeTime;
uint40 stake_period = (uint40(block.timestamp) - stake_time);
stake_period = Math.min(stake_period, uint40(stakeDays[user_record.stakeIndex]));
if (stake_period == 0) reward = UD60x18.unwrap(stake_amount);
else
reward = UD60x18.unwrap(
stake_amount.mul(ud(rates[user_record.stakeIndex]).powu(stake_period))
);
}
function rewardOfSlot(address user, uint256 index)
public
view
returns (uint256 reward)
{
Record storage user_record = userStakeRecord[user][index];
return caclItem(user_record);
}
function stakeCount(address user) external view returns (uint256 count) {
count = userStakeRecord[user].length;
}
function getUserRecords(
address _user,
uint256 _offset,
uint256 _limit,
uint8 _status // 0: ongoing, 1: redeemed
) external view returns (Record[] memory records, uint256 total) {
Record[] storage allRecords = userStakeRecord[_user];
uint256 allRecordsCount = allRecords.length;
bool targetStatus = (_status == 1);
Record[] memory resultPage = new Record[](_limit);
uint256 resultCount = 0;
uint256 totalFilteredCount = 0;
for (uint256 i = allRecordsCount; i > 0; i--) { // Newest first
uint256 index = i - 1;
if (allRecords[index].status == targetStatus) {
if (totalFilteredCount >= _offset && resultCount < _limit) {
resultPage[resultCount] = allRecords[index];
resultCount++;
}
totalFilteredCount++;
}
}
// Resize the array to the actual number of records found for the page.
records = new Record[](resultCount);
for (uint256 j = 0; j < resultCount; j++) {
records[j] = resultPage[j];
}
return (records, totalFilteredCount);
}
// Path A: Only Principal
function unstakePrincipalOnly(uint256 index) external onlyEOA {
_unstake(index, false);
}
// Path B: Principal + Interest (create new order internally)
function unstakeWithBonus(
uint256 index,
uint160 _amount,
uint256 amountOutMin,
uint8 _stakeIndex
) external onlyEOA {
Record storage oldOrder = userStakeRecord[msg.sender][index];
// 1. Verify Restake Conditions
require(_amount >= oldOrder.amount, "Insufficient amount");
require(stakeDays[_stakeIndex] >= stakeDays[oldOrder.stakeIndex], "Insufficient duration");
// 2. Perform Staking
require(_amount <= maxStakeAmount(), "Over Limit");
require(_stakeIndex <= 4, "<=4");
if (_stakeIndex == 4) {
require(whitelist[msg.sender], "Only whitelist");
}
swapAndAddLiquidity(_amount, amountOutMin);
mint(msg.sender, _amount, _stakeIndex);
// 3. Perform Unstake with Bonus
_unstake(index, true);
}
function unstakeWithBonusSplit(
uint256 index,
uint160[] memory _amounts,
uint256 amountOutMin,
uint8 _stakeIndex
) external onlyEOA {
Record storage oldOrder = userStakeRecord[msg.sender][index];
uint256 totalAmount = 0;
for (uint256 i = 0; i < _amounts.length; i++) {
totalAmount += _amounts[i];
}
require(totalAmount >= oldOrder.amount, "Insufficient amount");
require(stakeDays[_stakeIndex] >= stakeDays[oldOrder.stakeIndex], "Insufficient duration");
require(_stakeIndex <= 4, "<=4");
if (_stakeIndex == 4) {
require(whitelist[msg.sender], "Only whitelist");
}
swapAndAddLiquidity(uint160(totalAmount), amountOutMin);
for (uint256 i = 0; i < _amounts.length; i++) {
require(_amounts[i] <= maxStakeAmount(), "Over Limit");
mint(msg.sender, _amounts[i], _stakeIndex);
}
_unstake(index, true);
}
function _unstake(uint256 index, bool withBonus) private {
address sender = msg.sender;
if (!withBonus) {
require(userStakeRecord[sender][index].amount <= maxUnstakeAmount(), "Daily limit");
}
(uint256 reward, uint256 stake_amount) = burn(index, withBonus);
uint256 targetOsk = withBonus ? reward : stake_amount;
uint256 bal_this = OSP.balanceOf(address(this));
uint256 osk_this = OSK.balanceOf(address(this));
address[] memory path = new address[](2);
path[0] = address(OSP);
path[1] = address(OSK);
ROUTER.swapTokensForExactTokens(
targetOsk,
bal_this,
path,
address(this),
block.timestamp
);
uint256 bal_now = OSP.balanceOf(address(this));
uint256 osk_now = OSK.balanceOf(address(this));
uint256 amount_lab = bal_this - bal_now;
uint256 amount_osk = osk_now - osk_this;
uint256 interset = 0;
if (amount_osk > stake_amount) {
interset = amount_osk - stake_amount;
}
address[] memory referrals = REFERRAL.getReferrals(sender, maxReferralDepth);
if (withBonus && interset > 0) {
uint256 s_total_rate = s5Rate + s6Rate + s7Rate + s8Rate;
uint256 s_fee_osk = (interset * s_total_rate) / 100;
uint256 maxTeamRate = teamLevelRates[teamLevelRates.length - 1];
uint256 team_fee_osk = (interset * maxTeamRate) / 100;
uint256 total_dynamic_osk = s_fee_osk + team_fee_osk;
uint256 user_static_osk = interset - total_dynamic_osk;
uint256 total_swap_osk = total_dynamic_osk + user_static_osk;
if (total_swap_osk > 0) {
address[] memory path_osk_to_osp = new address[](2);
path_osk_to_osp[0] = address(OSK);
path_osk_to_osp[1] = address(OSP);
uint256[] memory amounts = ROUTER.getAmountsOut(
total_swap_osk,
path_osk_to_osp
);
uint256 amount_out_min = (amounts[1] * 90) / 100;
uint256 osp_bal_before_swap = OSP.balanceOf(address(this));
ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
total_swap_osk,
amount_out_min,
path_osk_to_osp,
address(this),
block.timestamp
);
uint256 osp_bal_after_swap = OSP.balanceOf(address(this));
uint256 total_osp_reward_amount = osp_bal_after_swap - osp_bal_before_swap;
if (total_osp_reward_amount > 0) {
uint256 user_osp = total_osp_reward_amount * user_static_osk / total_swap_osk;
if(user_osp > 0) {
OSP.transfer(sender, user_osp);
}
uint256 dynamic_osp = total_osp_reward_amount - user_osp;
if (dynamic_osp > 0) {
uint256 s_level_osp_total = (dynamic_osp * s_fee_osk) / total_dynamic_osk;
uint256 osp_distributed = 0;
if (s_total_rate > 0) {
address s5Target = (s5Count > 0 && s5Address != address(0)) ? s5Address : marketingAddress;
uint256 s5_osp = (s_level_osp_total * s5Rate) / s_total_rate;
OSP.transfer(s5Target, s5_osp);
if (s5Target == s5Address) { IPool(s5Address).addRewards(address(OSP), s5_osp); }
osp_distributed += s5_osp;
address s6Target = (s6Count > 0 && s6Address != address(0)) ? s6Address : marketingAddress;
uint256 s6_osp = (s_level_osp_total * s6Rate) / s_total_rate;
OSP.transfer(s6Target, s6_osp);
if (s6Target == s6Address) { IPool(s6Address).addRewards(address(OSP), s6_osp); }
osp_distributed += s6_osp;
address s7Target = (s7Count > 0 && s7Address != address(0)) ? s7Address : marketingAddress;
uint256 s7_osp = (s_level_osp_total * s7Rate) / s_total_rate;
OSP.transfer(s7Target, s7_osp);
if (s7Target == s7Address) { IPool(s7Address).addRewards(address(OSP), s7_osp); }
osp_distributed += s7_osp;
address s8Target = (s8Count > 0 && s8Address != address(0)) ? s8Address : marketingAddress;
uint256 s8_osp = s_level_osp_total - osp_distributed;
OSP.transfer(s8Target, s8_osp);
if (s8Target == s8Address) { IPool(s8Address).addRewards(address(OSP), s8_osp); }
}
uint256 team_level_osp_total = dynamic_osp - s_level_osp_total;
distributeTeamRewardOSP(referrals, interset, team_level_osp_total);
}
}
}
}
for (uint256 i = 0; i < referrals.length; i++) {
address referral = referrals[i];
uint256 oldKpi = getTeamKpi(referral);
uint256 referralSelfStake = getSelfStake(referral);
if (teamTotalInvestValue[referral] >= stake_amount) {
teamTotalInvestValue[referral] -= stake_amount;
} else {
teamTotalInvestValue[referral] = 0;
}
uint256 newKpi = getTeamKpi(referral);
_updateLevelChange(referral, oldKpi, newKpi, referralSelfStake, referralSelfStake);
}
uint256 senderOldKpi = getTeamKpi(sender);
uint256 currentStake = getSelfStake(sender);
// sender balance updated before call, so currentStake is the new stake
_updateLevelChange(sender, senderOldKpi, senderOldKpi, currentStake + stake_amount, currentStake);
uint256 sendOSK = stake_amount;
if (!withBonus && returnPrincipalOSPRatio > 0) {
uint256 ratio = returnPrincipalOSPRatio > 100 ? 100 : returnPrincipalOSPRatio;
uint256 oskToSwap = stake_amount * ratio / 100;
if (oskToSwap > 0) {
sendOSK -= oskToSwap;
address[] memory pathReturn = new address[](2);
pathReturn[0] = address(OSK);
pathReturn[1] = address(OSP);
// Swap OSK -> OSP and send to user
ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
oskToSwap,
0, // accept any amount of OSP
pathReturn,
sender,
block.timestamp
);
}
}
if (sendOSK > 0) {
OSK.transfer(sender, sendOSK);
}
OSP.recycle(amount_lab);
}
function burn(uint256 index, bool withReward)
private
returns (uint256 reward, uint256 amount)
{
address sender = msg.sender;
Record[] storage cord = userStakeRecord[sender];
Record storage user_record = cord[index];
uint256 stakeTime = user_record.stakeTime;
require(block.timestamp - stakeTime >= stakeDays[user_record.stakeIndex], "The time is not right");
require(user_record.status == false, "alw");
amount = user_record.amount;
totalSupply -= amount;
if (!withReward) {
totalUnstaked += amount;
RecordTT memory unstakeRecord;
unstakeRecord.stakeTime = uint40(block.timestamp);
unstakeRecord.tamount = uint160(totalUnstaked);
t_out.push(unstakeRecord);
}
balances[sender] -= amount;
emit Transfer(sender, address(0), amount);
if (withReward) {
reward = caclItem(user_record);
} else {
reward = 0;
}
user_record.finalReward = reward;
user_record.status = true;
userIndex[sender] = userIndex[sender] + 1;
emit RewardPaid(sender, reward, uint40(block.timestamp), index);
}
function getTeamKpi(address _user) public view returns (uint256) {
return teamTotalInvestValue[_user] + teamVirtuallyInvestValue[_user];
}
function getSelfStake(address _user) public view returns (uint256) {
return balances[_user] + teamVirtuallySelfStake[_user];
}
function isPreacher(address user) public view returns (bool) {
return balances[user] >= preacherThreshold;
}
function distributeTeamRewardOSP(
address[] memory referrals,
uint256 _interset,
uint256 total_team_osp
) private {
if (total_team_osp == 0) return;
uint256 maxTeamRate = teamLevelRates[teamLevelRates.length - 1];
uint256 total_team_osk = (_interset * maxTeamRate) / 100;
if (total_team_osk == 0) {
OSP.transfer(marketingAddress, total_team_osp);
return;
}
address top_team;
uint256 team_kpi;
uint256 spendRate = 0;
uint256 osp_distributed = 0;
for (uint256 i = 0; i < referrals.length; i++) {
top_team = referrals[i];
team_kpi = getTeamKpi(top_team);
if (!isPreacher(top_team)) {
continue;
}
uint256 userRate = 0;
// Iterate backwards from highest level to find the user's qualified level rate
for (int j = int(levelThresholds.length) - 1; j >= 0; j--) {
uint256 idx = uint256(j);
// check if kpi meets threshold
bool kpiMet = team_kpi >= levelThresholds[idx];
// check if self stake meets threshold
// getSelfStake(top_team) is expensive in loop, maybe optimize?
// but distributeTeamRewardOSP is already gas heavy.
// better to use getLevel logic but need to be careful about index matching
// Simplified: check if user qualifies for level j+1 (index j)
// idx 0 -> Level 1
// ...
// idx 7 -> Level 8
uint256 self_stake = getSelfStake(top_team);
bool selfMet = self_stake >= levelSelfStakeThresholds[idx];
if (kpiMet && selfMet) {
userRate = teamLevelRates[idx];
break;
}
}
if (userRate > spendRate) {
uint256 current_rate = userRate - spendRate;
uint256 reward_osp = (total_team_osp * current_rate) / maxTeamRate;
OSP.transfer(top_team, reward_osp);
osp_distributed += reward_osp;
spendRate = userRate;
if (spendRate >= maxTeamRate) {
break;
}
}
}
if (osp_distributed < total_team_osp) {
OSP.transfer(marketingAddress, total_team_osp - osp_distributed);
}
}
function getLevel(uint256 kpi, uint256 selfStake) public view returns (uint8) {
uint8 kpiLevel = 0;
if (kpi >= levelThresholds[7]) {
kpiLevel = 8;
} else if (kpi >= levelThresholds[6]) {
kpiLevel = 7;
} else if (kpi >= levelThresholds[5]) {
kpiLevel = 6;
} else if (kpi >= levelThresholds[4]) {
kpiLevel = 5;
} else if (kpi >= levelThresholds[3]) {
kpiLevel = 4;
} else if (kpi >= levelThresholds[2]) {
kpiLevel = 3;
} else if (kpi >= levelThresholds[1]) {
kpiLevel = 2;
} else if (kpi >= levelThresholds[0]) {
kpiLevel = 1;
}
uint8 selfLevel = 0;
// if self stake threshold is 0, it means no requirement
// we check from top to bottom
if (selfStake >= levelSelfStakeThresholds[7]) {
selfLevel = 8;
} else if (selfStake >= levelSelfStakeThresholds[6]) {
selfLevel = 7;
} else if (selfStake >= levelSelfStakeThresholds[5]) {
selfLevel = 6;
} else if (selfStake >= levelSelfStakeThresholds[4]) {
selfLevel = 5;
} else if (selfStake >= levelSelfStakeThresholds[3]) {
selfLevel = 4;
} else if (selfStake >= levelSelfStakeThresholds[2]) {
selfLevel = 3;
} else if (selfStake >= levelSelfStakeThresholds[1]) {
selfLevel = 2;
} else if (selfStake >= levelSelfStakeThresholds[0]) {
selfLevel = 1;
}
// FinalLevel = Min( LevelByTeamKPI, LevelBySelfStake )
return kpiLevel < selfLevel ? kpiLevel : selfLevel;
}
function _updateLevelChange(
address user,
uint256 oldKpi,
uint256 newKpi,
uint256 oldSelfStake,
uint256 newSelfStake
) private {
// Determine old level
uint8 oldLevel = getLevel(oldKpi, oldSelfStake);
uint8 newLevel = getLevel(newKpi, newSelfStake);
if (oldLevel == newLevel) {
return;
}
// Withdraw from old level's pool
if (oldLevel == 8) {
s8Count--;
if (s8Address != address(0)) {
IPool(s8Address).withdraw(user, 1e18);
}
} else if (oldLevel == 7) {
s7Count--;
if (s7Address != address(0)) {
IPool(s7Address).withdraw(user, 1e18);
}
} else if (oldLevel == 6) {
s6Count--;
if (s6Address != address(0)) {
IPool(s6Address).withdraw(user, 1e18);
}
} else if (oldLevel == 5) {
s5Count--;
if (s5Address != address(0)) {
IPool(s5Address).withdraw(user, 1e18);
}
}
// Deposit to new level's pool
if (newLevel == 8) {
s8Count++;
if (s8Address != address(0)) {
IPool(s8Address).deposit(user, 1e18);
}
} else if (newLevel == 7) {
s7Count++;
if (s7Address != address(0)) {
IPool(s7Address).deposit(user, 1e18);
}
} else if (newLevel == 6) {
s6Count++;
if (s6Address != address(0)) {
IPool(s6Address).deposit(user, 1e18);
}
} else if (newLevel == 5) {
s5Count++;
if (s5Address != address(0)) {
IPool(s5Address).deposit(user, 1e18);
}
}
}
function sync() external {
uint256 w_bal = IERC20(OSK).balanceOf(address(this));
address pair = OSP.uniswapV2Pair();
IERC20(OSK).transfer(pair, w_bal);
IUniswapV2Pair(pair).sync();
}
function emergencyWithdrawOSP(address to, uint256 _amount)
external
onlyOwner
{
OSP.transfer(to, _amount);
}
function importUserRecord(
address user,
Record[] calldata records,
uint256 _teamTotalInvestValue,
uint256 _teamVirtuallyInvestValue
) external onlyOwner {
Record[] storage cord = userStakeRecord[user];
for (uint256 i = 0; i < records.length; i++) {
cord.push(records[i]);
if (!records[i].status) {
balances[user] += records[i].amount;
totalSupply += records[i].amount;
}
}
teamTotalInvestValue[user] = _teamTotalInvestValue;
teamVirtuallyInvestValue[user] = _teamVirtuallyInvestValue;
}
function batchImportUserRecord(
address[] calldata users,
Record[][] calldata allRecords,
uint256[] calldata teamTotalInvestValues,
uint256[] calldata teamVirtuallyInvestValues
) external onlyOwner {
require(users.length == allRecords.length, "Length mismatch records");
require(users.length == teamTotalInvestValues.length, "Length mismatch total");
require(users.length == teamVirtuallyInvestValues.length, "Length mismatch virtual");
for (uint256 i = 0; i < users.length; i++) {
address user = users[i];
Record[] calldata records = allRecords[i];
Record[] storage cord = userStakeRecord[user];
for (uint256 j = 0; j < records.length; j++) {
cord.push(records[j]);
if (!records[j].status) {
balances[user] += records[j].amount;
totalSupply += records[j].amount;
}
}
teamTotalInvestValue[user] = teamTotalInvestValues[i];
teamVirtuallyInvestValue[user] = teamVirtuallyInvestValues[i];
}
}
function setGlobalCounts(uint256 _s5, uint256 _s6, uint256 _s7) external onlyOwner {
s5Count = _s5;
s6Count = _s6;
s7Count = _s7;
}
}
library Math {
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint40 a, uint40 b) internal pure returns (uint40) {
return a < b ? a : b;
}
function min256(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @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 Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
// Common.sol
//
// Common mathematical functions used in both SD59x18 and UD60x18. Note that these global functions do not
// always operate with SD59x18 and UD60x18 numbers.
/*//////////////////////////////////////////////////////////////////////////
CUSTOM ERRORS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Thrown when the resultant value in {mulDiv} overflows uint256.
error PRBMath_MulDiv_Overflow(uint256 x, uint256 y, uint256 denominator);
/// @notice Thrown when the resultant value in {mulDiv18} overflows uint256.
error PRBMath_MulDiv18_Overflow(uint256 x, uint256 y);
/// @notice Thrown when one of the inputs passed to {mulDivSigned} is `type(int256).min`.
error PRBMath_MulDivSigned_InputTooSmall();
/// @notice Thrown when the resultant value in {mulDivSigned} overflows int256.
error PRBMath_MulDivSigned_Overflow(int256 x, int256 y);
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @dev The maximum value a uint128 number can have.
uint128 constant MAX_UINT128 = type(uint128).max;
/// @dev The maximum value a uint40 number can have.
uint40 constant MAX_UINT40 = type(uint40).max;
/// @dev The maximum value a uint64 number can have.
uint64 constant MAX_UINT64 = type(uint64).max;
/// @dev The unit number, which the decimal precision of the fixed-point types.
uint256 constant UNIT = 1e18;
/// @dev The unit number inverted mod 2^256.
uint256 constant UNIT_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281;
/// @dev The the largest power of two that divides the decimal value of `UNIT`. The logarithm of this value is the least significant
/// bit in the binary representation of `UNIT`.
uint256 constant UNIT_LPOTD = 262144;
/*//////////////////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the binary exponent of x using the binary fraction method.
/// @dev Has to use 192.64-bit fixed-point numbers. See https://ethereum.stackexchange.com/a/96594/24693.
/// @param x The exponent as an unsigned 192.64-bit fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function exp2(uint256 x) pure returns (uint256 result) {
unchecked {
// Start from 0.5 in the 192.64-bit fixed-point format.
result = 0x800000000000000000000000000000000000000000000000;
// The following logic multiplies the result by $\sqrt{2^{-i}}$ when the bit at position i is 1. Key points:
//
// 1. Intermediate results will not overflow, as the starting point is 2^191 and all magic factors are under 2^65.
// 2. The rationale for organizing the if statements into groups of 8 is gas savings. If the result of performing
// a bitwise AND operation between x and any value in the array [0x80; 0x40; 0x20; 0x10; 0x08; 0x04; 0x02; 0x01] is 1,
// we know that `x & 0xFF` is also 1.
if (x & 0xFF00000000000000 > 0) {
if (x & 0x8000000000000000 > 0) {
result = (result * 0x16A09E667F3BCC909) >> 64;
}
if (x & 0x4000000000000000 > 0) {
result = (result * 0x1306FE0A31B7152DF) >> 64;
}
if (x & 0x2000000000000000 > 0) {
result = (result * 0x1172B83C7D517ADCE) >> 64;
}
if (x & 0x1000000000000000 > 0) {
result = (result * 0x10B5586CF9890F62A) >> 64;
}
if (x & 0x800000000000000 > 0) {
result = (result * 0x1059B0D31585743AE) >> 64;
}
if (x & 0x400000000000000 > 0) {
result = (result * 0x102C9A3E778060EE7) >> 64;
}
if (x & 0x200000000000000 > 0) {
result = (result * 0x10163DA9FB33356D8) >> 64;
}
if (x & 0x100000000000000 > 0) {
result = (result * 0x100B1AFA5ABCBED61) >> 64;
}
}
if (x & 0xFF000000000000 > 0) {
if (x & 0x80000000000000 > 0) {
result = (result * 0x10058C86DA1C09EA2) >> 64;
}
if (x & 0x40000000000000 > 0) {
result = (result * 0x1002C605E2E8CEC50) >> 64;
}
if (x & 0x20000000000000 > 0) {
result = (result * 0x100162F3904051FA1) >> 64;
}
if (x & 0x10000000000000 > 0) {
result = (result * 0x1000B175EFFDC76BA) >> 64;
}
if (x & 0x8000000000000 > 0) {
result = (result * 0x100058BA01FB9F96D) >> 64;
}
if (x & 0x4000000000000 > 0) {
result = (result * 0x10002C5CC37DA9492) >> 64;
}
if (x & 0x2000000000000 > 0) {
result = (result * 0x1000162E525EE0547) >> 64;
}
if (x & 0x1000000000000 > 0) {
result = (result * 0x10000B17255775C04) >> 64;
}
}
if (x & 0xFF0000000000 > 0) {
if (x & 0x800000000000 > 0) {
result = (result * 0x1000058B91B5BC9AE) >> 64;
}
if (x & 0x400000000000 > 0) {
result = (result * 0x100002C5C89D5EC6D) >> 64;
}
if (x & 0x200000000000 > 0) {
result = (result * 0x10000162E43F4F831) >> 64;
}
if (x & 0x100000000000 > 0) {
result = (result * 0x100000B1721BCFC9A) >> 64;
}
if (x & 0x80000000000 > 0) {
result = (result * 0x10000058B90CF1E6E) >> 64;
}
if (x & 0x40000000000 > 0) {
result = (result * 0x1000002C5C863B73F) >> 64;
}
if (x & 0x20000000000 > 0) {
result = (result * 0x100000162E430E5A2) >> 64;
}
if (x & 0x10000000000 > 0) {
result = (result * 0x1000000B172183551) >> 64;
}
}
if (x & 0xFF00000000 > 0) {
if (x & 0x8000000000 > 0) {
result = (result * 0x100000058B90C0B49) >> 64;
}
if (x & 0x4000000000 > 0) {
result = (result * 0x10000002C5C8601CC) >> 64;
}
if (x & 0x2000000000 > 0) {
result = (result * 0x1000000162E42FFF0) >> 64;
}
if (x & 0x1000000000 > 0) {
result = (result * 0x10000000B17217FBB) >> 64;
}
if (x & 0x800000000 > 0) {
result = (result * 0x1000000058B90BFCE) >> 64;
}
if (x & 0x400000000 > 0) {
result = (result * 0x100000002C5C85FE3) >> 64;
}
if (x & 0x200000000 > 0) {
result = (result * 0x10000000162E42FF1) >> 64;
}
if (x & 0x100000000 > 0) {
result = (result * 0x100000000B17217F8) >> 64;
}
}
if (x & 0xFF000000 > 0) {
if (x & 0x80000000 > 0) {
result = (result * 0x10000000058B90BFC) >> 64;
}
if (x & 0x40000000 > 0) {
result = (result * 0x1000000002C5C85FE) >> 64;
}
if (x & 0x20000000 > 0) {
result = (result * 0x100000000162E42FF) >> 64;
}
if (x & 0x10000000 > 0) {
result = (result * 0x1000000000B17217F) >> 64;
}
if (x & 0x8000000 > 0) {
result = (result * 0x100000000058B90C0) >> 64;
}
if (x & 0x4000000 > 0) {
result = (result * 0x10000000002C5C860) >> 64;
}
if (x & 0x2000000 > 0) {
result = (result * 0x1000000000162E430) >> 64;
}
if (x & 0x1000000 > 0) {
result = (result * 0x10000000000B17218) >> 64;
}
}
if (x & 0xFF0000 > 0) {
if (x & 0x800000 > 0) {
result = (result * 0x1000000000058B90C) >> 64;
}
if (x & 0x400000 > 0) {
result = (result * 0x100000000002C5C86) >> 64;
}
if (x & 0x200000 > 0) {
result = (result * 0x10000000000162E43) >> 64;
}
if (x & 0x100000 > 0) {
result = (result * 0x100000000000B1721) >> 64;
}
if (x & 0x80000 > 0) {
result = (result * 0x10000000000058B91) >> 64;
}
if (x & 0x40000 > 0) {
result = (result * 0x1000000000002C5C8) >> 64;
}
if (x & 0x20000 > 0) {
result = (result * 0x100000000000162E4) >> 64;
}
if (x & 0x10000 > 0) {
result = (result * 0x1000000000000B172) >> 64;
}
}
if (x & 0xFF00 > 0) {
if (x & 0x8000 > 0) {
result = (result * 0x100000000000058B9) >> 64;
}
if (x & 0x4000 > 0) {
result = (result * 0x10000000000002C5D) >> 64;
}
if (x & 0x2000 > 0) {
result = (result * 0x1000000000000162E) >> 64;
}
if (x & 0x1000 > 0) {
result = (result * 0x10000000000000B17) >> 64;
}
if (x & 0x800 > 0) {
result = (result * 0x1000000000000058C) >> 64;
}
if (x & 0x400 > 0) {
result = (result * 0x100000000000002C6) >> 64;
}
if (x & 0x200 > 0) {
result = (result * 0x10000000000000163) >> 64;
}
if (x & 0x100 > 0) {
result = (result * 0x100000000000000B1) >> 64;
}
}
if (x & 0xFF > 0) {
if (x & 0x80 > 0) {
result = (result * 0x10000000000000059) >> 64;
}
if (x & 0x40 > 0) {
result = (result * 0x1000000000000002C) >> 64;
}
if (x & 0x20 > 0) {
result = (result * 0x10000000000000016) >> 64;
}
if (x & 0x10 > 0) {
result = (result * 0x1000000000000000B) >> 64;
}
if (x & 0x8 > 0) {
result = (result * 0x10000000000000006) >> 64;
}
if (x & 0x4 > 0) {
result = (result * 0x10000000000000003) >> 64;
}
if (x & 0x2 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
if (x & 0x1 > 0) {
result = (result * 0x10000000000000001) >> 64;
}
}
// In the code snippet below, two operations are executed simultaneously:
//
// 1. The result is multiplied by $(2^n + 1)$, where $2^n$ represents the integer part, and the additional 1
// accounts for the initial guess of 0.5. This is achieved by subtracting from 191 instead of 192.
// 2. The result is then converted to an unsigned 60.18-decimal fixed-point format.
//
// The underlying logic is based on the relationship $2^{191-ip} = 2^{ip} / 2^{191}$, where $ip$ denotes the,
// integer part, $2^n$.
result *= UNIT;
result >>= (191 - (x >> 64));
}
}
/// @notice Finds the zero-based index of the first 1 in the binary representation of x.
///
/// @dev See the note on "msb" in this Wikipedia article: https://en.wikipedia.org/wiki/Find_first_set
///
/// Each step in this implementation is equivalent to this high-level code:
///
/// ```solidity
/// if (x >= 2 ** 128) {
/// x >>= 128;
/// result += 128;
/// }
/// ```
///
/// Where 128 is replaced with each respective power of two factor. See the full high-level implementation here:
/// https://gist.github.com/PaulRBerg/f932f8693f2733e30c4d479e8e980948
///
/// The Yul instructions used below are:
///
/// - "gt" is "greater than"
/// - "or" is the OR bitwise operator
/// - "shl" is "shift left"
/// - "shr" is "shift right"
///
/// @param x The uint256 number for which to find the index of the most significant bit.
/// @return result The index of the most significant bit as a uint256.
/// @custom:smtchecker abstract-function-nondet
function msb(uint256 x) pure returns (uint256 result) {
// 2^128
assembly ("memory-safe") {
let factor := shl(7, gt(x, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^64
assembly ("memory-safe") {
let factor := shl(6, gt(x, 0xFFFFFFFFFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^32
assembly ("memory-safe") {
let factor := shl(5, gt(x, 0xFFFFFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^16
assembly ("memory-safe") {
let factor := shl(4, gt(x, 0xFFFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^8
assembly ("memory-safe") {
let factor := shl(3, gt(x, 0xFF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^4
assembly ("memory-safe") {
let factor := shl(2, gt(x, 0xF))
x := shr(factor, x)
result := or(result, factor)
}
// 2^2
assembly ("memory-safe") {
let factor := shl(1, gt(x, 0x3))
x := shr(factor, x)
result := or(result, factor)
}
// 2^1
// No need to shift x any more.
assembly ("memory-safe") {
let factor := gt(x, 0x1)
result := or(result, factor)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev Credits to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - The denominator must not be zero.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as a uint256.
/// @param y The multiplier as a uint256.
/// @param denominator The divisor as a uint256.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function mulDiv(uint256 x, uint256 y, uint256 denominator) pure returns (uint256 result) {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512-bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
unchecked {
return prod0 / denominator;
}
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (prod1 >= denominator) {
revert PRBMath_MulDiv_Overflow(x, y, denominator);
}
////////////////////////////////////////////////////////////////////////////
// 512 by 256 division
////////////////////////////////////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using the mulmod Yul instruction.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512-bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
unchecked {
// Calculate the largest power of two divisor of the denominator using the unary operator ~. This operation cannot overflow
// because the denominator cannot be zero at this point in the function execution. The result is always >= 1.
// For more detail, see https://cs.stackexchange.com/q/138556/92363.
uint256 lpotdod = denominator & (~denominator + 1);
uint256 flippedLpotdod;
assembly ("memory-safe") {
// Factor powers of two out of denominator.
denominator := div(denominator, lpotdod)
// Divide [prod1 prod0] by lpotdod.
prod0 := div(prod0, lpotdod)
// Get the flipped value `2^256 / lpotdod`. If the `lpotdod` is zero, the flipped value is one.
// `sub(0, lpotdod)` produces the two's complement version of `lpotdod`, which is equivalent to flipping all the bits.
// However, `div` interprets this value as an unsigned value: https://ethereum.stackexchange.com/q/147168/24693
flippedLpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * flippedLpotdod;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
}
}
/// @notice Calculates x*y÷1e18 with 512-bit precision.
///
/// @dev A variant of {mulDiv} with constant folding, i.e. in which the denominator is hard coded to 1e18.
///
/// Notes:
/// - The body is purposely left uncommented; to understand how this works, see the documentation in {mulDiv}.
/// - The result is rounded toward zero.
/// - We take as an axiom that the result cannot be `MAX_UINT256` when x and y solve the following system of equations:
///
/// $$
/// \begin{cases}
/// x * y = MAX\_UINT256 * UNIT \\
/// (x * y) \% UNIT \geq \frac{UNIT}{2}
/// \end{cases}
/// $$
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - The result must fit in uint256.
///
/// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
/// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
/// @return result The result as an unsigned 60.18-decimal fixed-point number.
/// @custom:smtchecker abstract-function-nondet
function mulDiv18(uint256 x, uint256 y) pure returns (uint256 result) {
uint256 prod0;
uint256 prod1;
assembly ("memory-safe") {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
unchecked {
return prod0 / UNIT;
}
}
if (prod1 >= UNIT) {
revert PRBMath_MulDiv18_Overflow(x, y);
}
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(x, y, UNIT)
result :=
mul(
or(
div(sub(prod0, remainder), UNIT_LPOTD),
mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, UNIT_LPOTD), UNIT_LPOTD), 1))
),
UNIT_INVERSE
)
}
}
/// @notice Calculates x*y÷denominator with 512-bit precision.
///
/// @dev This is an extension of {mulDiv} for signed numbers, which works by computing the signs and the absolute values separately.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {mulDiv}.
/// - None of the inputs can be `type(int256).min`.
/// - The result must fit in int256.
///
/// @param x The multiplicand as an int256.
/// @param y The multiplier as an int256.
/// @param denominator The divisor as an int256.
/// @return result The result as an int256.
/// @custom:smtchecker abstract-function-nondet
function mulDivSigned(int256 x, int256 y, int256 denominator) pure returns (int256 result) {
if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
revert PRBMath_MulDivSigned_InputTooSmall();
}
// Get hold of the absolute values of x, y and the denominator.
uint256 xAbs;
uint256 yAbs;
uint256 dAbs;
unchecked {
xAbs = x < 0 ? uint256(-x) : uint256(x);
yAbs = y < 0 ? uint256(-y) : uint256(y);
dAbs = denominator < 0 ? uint256(-denominator) : uint256(denominator);
}
// Compute the absolute value of x*y÷denominator. The result must fit in int256.
uint256 resultAbs = mulDiv(xAbs, yAbs, dAbs);
if (resultAbs > uint256(type(int256).max)) {
revert PRBMath_MulDivSigned_Overflow(x, y);
}
// Get the signs of x, y and the denominator.
uint256 sx;
uint256 sy;
uint256 sd;
assembly ("memory-safe") {
// "sgt" is the "signed greater than" assembly instruction and "sub(0,1)" is -1 in two's complement.
sx := sgt(x, sub(0, 1))
sy := sgt(y, sub(0, 1))
sd := sgt(denominator, sub(0, 1))
}
// XOR over sx, sy and sd. What this does is to check whether there are 1 or 3 negative signs in the inputs.
// If there are, the result should be negative. Otherwise, it should be positive.
unchecked {
result = sx ^ sy ^ sd == 0 ? -int256(resultAbs) : int256(resultAbs);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - If x is not a perfect square, the result is rounded down.
/// - Credits to OpenZeppelin for the explanations in comments below.
///
/// @param x The uint256 number for which to calculate the square root.
/// @return result The result as a uint256.
/// @custom:smtchecker abstract-function-nondet
function sqrt(uint256 x) pure returns (uint256 result) {
if (x == 0) {
return 0;
}
// For our first guess, we calculate the biggest power of 2 which is smaller than the square root of x.
//
// We know that the "msb" (most significant bit) of x is a power of 2 such that we have:
//
// $$
// msb(x) <= x <= 2*msb(x)$
// $$
//
// We write $msb(x)$ as $2^k$, and we get:
//
// $$
// k = log_2(x)
// $$
//
// Thus, we can write the initial inequality as:
//
// $$
// 2^{log_2(x)} <= x <= 2*2^{log_2(x)+1} \\
// sqrt(2^k) <= sqrt(x) < sqrt(2^{k+1}) \\
// 2^{k/2} <= sqrt(x) < 2^{(k+1)/2} <= 2^{(k/2)+1}
// $$
//
// Consequently, $2^{log_2(x) /2} is a good first approximation of sqrt(x) with at least one correct bit.
uint256 xAux = uint256(x);
result = 1;
if (xAux >= 2 ** 128) {
xAux >>= 128;
result <<= 64;
}
if (xAux >= 2 ** 64) {
xAux >>= 64;
result <<= 32;
}
if (xAux >= 2 ** 32) {
xAux >>= 32;
result <<= 16;
}
if (xAux >= 2 ** 16) {
xAux >>= 16;
result <<= 8;
}
if (xAux >= 2 ** 8) {
xAux >>= 8;
result <<= 4;
}
if (xAux >= 2 ** 4) {
xAux >>= 4;
result <<= 2;
}
if (xAux >= 2 ** 2) {
result <<= 1;
}
// At this point, `result` is an estimation with at least one bit of precision. We know the true value has at
// most 128 bits, since it is the square root of a uint256. Newton's method converges quadratically (precision
// doubles at every iteration). We thus need at most 7 iteration to turn our partial result with one bit of
// precision into the expected uint128 result.
unchecked {
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
result = (result + x / result) >> 1;
// If x is not a perfect square, round the result toward zero.
uint256 roundedResult = x / result;
if (result >= roundedResult) {
result = roundedResult;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as CastingErrors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD1x18 } from "./ValueType.sol";
/// @notice Casts an SD1x18 number into SD59x18.
/// @dev There is no overflow check because SD1x18 ⊆ SD59x18.
function intoSD59x18(SD1x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(SD1x18.unwrap(x)));
}
/// @notice Casts an SD1x18 number into UD60x18.
/// @dev Requirements:
/// - x ≥ 0
function intoUD60x18(SD1x18 x) pure returns (UD60x18 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint128.
/// @dev Requirements:
/// - x ≥ 0
function intoUint128(SD1x18 x) pure returns (uint128 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint128_Underflow(x);
}
result = uint128(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint256.
/// @dev Requirements:
/// - x ≥ 0
function intoUint256(SD1x18 x) pure returns (uint256 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint256_Underflow(x);
}
result = uint256(uint64(xInt));
}
/// @notice Casts an SD1x18 number into uint40.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ MAX_UINT40
function intoUint40(SD1x18 x) pure returns (uint40 result) {
int64 xInt = SD1x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Underflow(x);
}
if (xInt > int64(uint64(Common.MAX_UINT40))) {
revert CastingErrors.PRBMath_SD1x18_ToUint40_Overflow(x);
}
result = uint40(uint64(xInt));
}
/// @notice Alias for {wrap}.
function sd1x18(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}
/// @notice Unwraps an SD1x18 number into int64.
function unwrap(SD1x18 x) pure returns (int64 result) {
result = SD1x18.unwrap(x);
}
/// @notice Wraps an int64 number into SD1x18.
function wrap(int64 x) pure returns (SD1x18 result) {
result = SD1x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @dev Euler's number as an SD1x18 number.
SD1x18 constant E = SD1x18.wrap(2_718281828459045235);
/// @dev The maximum value an SD1x18 number can have.
int64 constant uMAX_SD1x18 = 9_223372036854775807;
SD1x18 constant MAX_SD1x18 = SD1x18.wrap(uMAX_SD1x18);
/// @dev The minimum value an SD1x18 number can have.
int64 constant uMIN_SD1x18 = -9_223372036854775808;
SD1x18 constant MIN_SD1x18 = SD1x18.wrap(uMIN_SD1x18);
/// @dev PI as an SD1x18 number.
SD1x18 constant PI = SD1x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD1x18.
SD1x18 constant UNIT = SD1x18.wrap(1e18);
int64 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD1x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in UD60x18.
error PRBMath_SD1x18_ToUD60x18_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint128.
error PRBMath_SD1x18_ToUint128_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint256.
error PRBMath_SD1x18_ToUint256_Underflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Overflow(SD1x18 x);
/// @notice Thrown when trying to cast an SD1x18 number that doesn't fit in uint40.
error PRBMath_SD1x18_ToUint40_Underflow(SD1x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The signed 1.18-decimal fixed-point number representation, which can have up to 1 digit and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int64. This is useful when end users want to use int64 to save gas, e.g. with tight variable packing in contract
/// storage.
type SD1x18 is int64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for SD1x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as CastingErrors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD21x18 } from "./ValueType.sol";
/// @notice Casts an SD21x18 number into SD59x18.
/// @dev There is no overflow check because SD21x18 ⊆ SD59x18.
function intoSD59x18(SD21x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(SD21x18.unwrap(x)));
}
/// @notice Casts an SD21x18 number into UD60x18.
/// @dev Requirements:
/// - x ≥ 0
function intoUD60x18(SD21x18 x) pure returns (UD60x18 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint128(xInt));
}
/// @notice Casts an SD21x18 number into uint128.
/// @dev Requirements:
/// - x ≥ 0
function intoUint128(SD21x18 x) pure returns (uint128 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUint128_Underflow(x);
}
result = uint128(xInt);
}
/// @notice Casts an SD21x18 number into uint256.
/// @dev Requirements:
/// - x ≥ 0
function intoUint256(SD21x18 x) pure returns (uint256 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUint256_Underflow(x);
}
result = uint256(uint128(xInt));
}
/// @notice Casts an SD21x18 number into uint40.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ MAX_UINT40
function intoUint40(SD21x18 x) pure returns (uint40 result) {
int128 xInt = SD21x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD21x18_ToUint40_Underflow(x);
}
if (xInt > int128(uint128(Common.MAX_UINT40))) {
revert CastingErrors.PRBMath_SD21x18_ToUint40_Overflow(x);
}
result = uint40(uint128(xInt));
}
/// @notice Alias for {wrap}.
function sd21x18(int128 x) pure returns (SD21x18 result) {
result = SD21x18.wrap(x);
}
/// @notice Unwraps an SD21x18 number into int128.
function unwrap(SD21x18 x) pure returns (int128 result) {
result = SD21x18.unwrap(x);
}
/// @notice Wraps an int128 number into SD21x18.
function wrap(int128 x) pure returns (SD21x18 result) {
result = SD21x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD21x18 } from "./ValueType.sol";
/// @dev Euler's number as an SD21x18 number.
SD21x18 constant E = SD21x18.wrap(2_718281828459045235);
/// @dev The maximum value an SD21x18 number can have.
int128 constant uMAX_SD21x18 = 170141183460469231731_687303715884105727;
SD21x18 constant MAX_SD21x18 = SD21x18.wrap(uMAX_SD21x18);
/// @dev The minimum value an SD21x18 number can have.
int128 constant uMIN_SD21x18 = -170141183460469231731_687303715884105728;
SD21x18 constant MIN_SD21x18 = SD21x18.wrap(uMIN_SD21x18);
/// @dev PI as an SD21x18 number.
SD21x18 constant PI = SD21x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD21x18.
SD21x18 constant UNIT = SD21x18.wrap(1e18);
int128 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD21x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint128.
error PRBMath_SD21x18_ToUint128_Underflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in UD60x18.
error PRBMath_SD21x18_ToUD60x18_Underflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint256.
error PRBMath_SD21x18_ToUint256_Underflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
error PRBMath_SD21x18_ToUint40_Overflow(SD21x18 x);
/// @notice Thrown when trying to cast an SD21x18 number that doesn't fit in uint40.
error PRBMath_SD21x18_ToUint40_Underflow(SD21x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The signed 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int128. This is useful when end users want to use int128 to save gas, e.g. with tight variable packing in contract
/// storage.
type SD21x18 is int128;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for SD21x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18, uMIN_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_SD21x18, uMIN_SD21x18 } from "../sd21x18/Constants.sol";
import { SD21x18 } from "../sd21x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
import { UD21x18 } from "../ud21x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Casts an SD59x18 number into int256.
/// @dev This is basically a functional alias for {unwrap}.
function intoInt256(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Casts an SD59x18 number into SD1x18.
/// @dev Requirements:
/// - x ≥ uMIN_SD1x18
/// - x ≤ uMAX_SD1x18
function intoSD1x18(SD59x18 x) pure returns (SD1x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < uMIN_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Underflow(x);
}
if (xInt > uMAX_SD1x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(xInt));
}
/// @notice Casts an SD59x18 number into SD21x18.
/// @dev Requirements:
/// - x ≥ uMIN_SD21x18
/// - x ≤ uMAX_SD21x18
function intoSD21x18(SD59x18 x) pure returns (SD21x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < uMIN_SD21x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Underflow(x);
}
if (xInt > uMAX_SD21x18) {
revert CastingErrors.PRBMath_SD59x18_IntoSD21x18_Overflow(x);
}
result = SD21x18.wrap(int128(xInt));
}
/// @notice Casts an SD59x18 number into UD2x18.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ uMAX_UD2x18
function intoUD2x18(SD59x18 x) pure returns (UD2x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Underflow(x);
}
if (xInt > int256(uint256(uMAX_UD2x18))) {
revert CastingErrors.PRBMath_SD59x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(uint256(xInt)));
}
/// @notice Casts an SD59x18 number into UD21x18.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ uMAX_UD21x18
function intoUD21x18(SD59x18 x) pure returns (UD21x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Underflow(x);
}
if (xInt > int256(uint256(uMAX_UD21x18))) {
revert CastingErrors.PRBMath_SD59x18_IntoUD21x18_Overflow(x);
}
result = UD21x18.wrap(uint128(uint256(xInt)));
}
/// @notice Casts an SD59x18 number into UD60x18.
/// @dev Requirements:
/// - x ≥ 0
function intoUD60x18(SD59x18 x) pure returns (UD60x18 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUD60x18_Underflow(x);
}
result = UD60x18.wrap(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint256.
/// @dev Requirements:
/// - x ≥ 0
function intoUint256(SD59x18 x) pure returns (uint256 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint256_Underflow(x);
}
result = uint256(xInt);
}
/// @notice Casts an SD59x18 number into uint128.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ uMAX_UINT128
function intoUint128(SD59x18 x) pure returns (uint128 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT128))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint128_Overflow(x);
}
result = uint128(uint256(xInt));
}
/// @notice Casts an SD59x18 number into uint40.
/// @dev Requirements:
/// - x ≥ 0
/// - x ≤ MAX_UINT40
function intoUint40(SD59x18 x) pure returns (uint40 result) {
int256 xInt = SD59x18.unwrap(x);
if (xInt < 0) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Underflow(x);
}
if (xInt > int256(uint256(MAX_UINT40))) {
revert CastingErrors.PRBMath_SD59x18_IntoUint40_Overflow(x);
}
result = uint40(uint256(xInt));
}
/// @notice Alias for {wrap}.
function sd(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Alias for {wrap}.
function sd59x18(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}
/// @notice Unwraps an SD59x18 number into int256.
function unwrap(SD59x18 x) pure returns (int256 result) {
result = SD59x18.unwrap(x);
}
/// @notice Wraps an int256 number into SD59x18.
function wrap(int256 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as an SD59x18 number.
SD59x18 constant E = SD59x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
int256 constant uEXP_MAX_INPUT = 133_084258667509499440;
SD59x18 constant EXP_MAX_INPUT = SD59x18.wrap(uEXP_MAX_INPUT);
/// @dev Any value less than this returns 0 in {exp}.
int256 constant uEXP_MIN_THRESHOLD = -41_446531673892822322;
SD59x18 constant EXP_MIN_THRESHOLD = SD59x18.wrap(uEXP_MIN_THRESHOLD);
/// @dev The maximum input permitted in {exp2}.
int256 constant uEXP2_MAX_INPUT = 192e18 - 1;
SD59x18 constant EXP2_MAX_INPUT = SD59x18.wrap(uEXP2_MAX_INPUT);
/// @dev Any value less than this returns 0 in {exp2}.
int256 constant uEXP2_MIN_THRESHOLD = -59_794705707972522261;
SD59x18 constant EXP2_MIN_THRESHOLD = SD59x18.wrap(uEXP2_MIN_THRESHOLD);
/// @dev Half the UNIT number.
int256 constant uHALF_UNIT = 0.5e18;
SD59x18 constant HALF_UNIT = SD59x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as an SD59x18 number.
int256 constant uLOG2_10 = 3_321928094887362347;
SD59x18 constant LOG2_10 = SD59x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as an SD59x18 number.
int256 constant uLOG2_E = 1_442695040888963407;
SD59x18 constant LOG2_E = SD59x18.wrap(uLOG2_E);
/// @dev The maximum value an SD59x18 number can have.
int256 constant uMAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967;
SD59x18 constant MAX_SD59x18 = SD59x18.wrap(uMAX_SD59x18);
/// @dev The maximum whole value an SD59x18 number can have.
int256 constant uMAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MAX_WHOLE_SD59x18 = SD59x18.wrap(uMAX_WHOLE_SD59x18);
/// @dev The minimum value an SD59x18 number can have.
int256 constant uMIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968;
SD59x18 constant MIN_SD59x18 = SD59x18.wrap(uMIN_SD59x18);
/// @dev The minimum whole value an SD59x18 number can have.
int256 constant uMIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000;
SD59x18 constant MIN_WHOLE_SD59x18 = SD59x18.wrap(uMIN_WHOLE_SD59x18);
/// @dev PI as an SD59x18 number.
SD59x18 constant PI = SD59x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of SD59x18.
int256 constant uUNIT = 1e18;
SD59x18 constant UNIT = SD59x18.wrap(1e18);
/// @dev The unit number squared.
int256 constant uUNIT_SQUARED = 1e36;
SD59x18 constant UNIT_SQUARED = SD59x18.wrap(uUNIT_SQUARED);
/// @dev Zero as an SD59x18 number.
SD59x18 constant ZERO = SD59x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { SD59x18 } from "./ValueType.sol";
/// @notice Thrown when taking the absolute value of `MIN_SD59x18`.
error PRBMath_SD59x18_Abs_MinSD59x18();
/// @notice Thrown when ceiling a number overflows SD59x18.
error PRBMath_SD59x18_Ceil_Overflow(SD59x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMath_SD59x18_Convert_Overflow(int256 x);
/// @notice Thrown when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMath_SD59x18_Convert_Underflow(int256 x);
/// @notice Thrown when dividing two numbers and one of them is `MIN_SD59x18`.
error PRBMath_SD59x18_Div_InputTooSmall();
/// @notice Thrown when dividing two numbers and one of the intermediary unsigned results overflows SD59x18.
error PRBMath_SD59x18_Div_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_SD59x18_Exp_InputTooBig(SD59x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_SD59x18_Exp2_InputTooBig(SD59x18 x);
/// @notice Thrown when flooring a number underflows SD59x18.
error PRBMath_SD59x18_Floor_Underflow(SD59x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and their product is negative.
error PRBMath_SD59x18_Gm_NegativeProduct(SD59x18 x, SD59x18 y);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows SD59x18.
error PRBMath_SD59x18_Gm_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD1x18.
error PRBMath_SD59x18_IntoSD1x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
error PRBMath_SD59x18_IntoSD21x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in SD21x18.
error PRBMath_SD59x18_IntoSD21x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD2x18.
error PRBMath_SD59x18_IntoUD2x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
error PRBMath_SD59x18_IntoUD21x18_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD21x18.
error PRBMath_SD59x18_IntoUD21x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in UD60x18.
error PRBMath_SD59x18_IntoUD60x18_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint128.
error PRBMath_SD59x18_IntoUint128_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint256.
error PRBMath_SD59x18_IntoUint256_Underflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Overflow(SD59x18 x);
/// @notice Thrown when trying to cast an SD59x18 number that doesn't fit in uint40.
error PRBMath_SD59x18_IntoUint40_Underflow(SD59x18 x);
/// @notice Thrown when taking the logarithm of a number less than or equal to zero.
error PRBMath_SD59x18_Log_InputTooSmall(SD59x18 x);
/// @notice Thrown when multiplying two numbers and one of the inputs is `MIN_SD59x18`.
error PRBMath_SD59x18_Mul_InputTooSmall();
/// @notice Thrown when multiplying two numbers and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Mul_Overflow(SD59x18 x, SD59x18 y);
/// @notice Thrown when raising a number to a power and the intermediary absolute result overflows SD59x18.
error PRBMath_SD59x18_Powu_Overflow(SD59x18 x, uint256 y);
/// @notice Thrown when taking the square root of a negative number.
error PRBMath_SD59x18_Sqrt_NegativeInput(SD59x18 x);
/// @notice Thrown when the calculating the square root overflows SD59x18.
error PRBMath_SD59x18_Sqrt_Overflow(SD59x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the SD59x18 type.
function add(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and(SD59x18 x, int256 bits) pure returns (SD59x18 result) {
return wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the SD59x18 type.
function and2(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
return wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal (=) operation in the SD59x18 type.
function eq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the SD59x18 type.
function gt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the SD59x18 type.
function gte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the SD59x18 type.
function isZero(SD59x18 x) pure returns (bool result) {
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the SD59x18 type.
function lshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the SD59x18 type.
function lt(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the SD59x18 type.
function lte(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the unchecked modulo operation (%) in the SD59x18 type.
function mod(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the SD59x18 type.
function neq(SD59x18 x, SD59x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the SD59x18 type.
function not(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the SD59x18 type.
function or(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the SD59x18 type.
function rshift(SD59x18 x, uint256 bits) pure returns (SD59x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the SD59x18 type.
function sub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the checked unary minus operation (-) in the SD59x18 type.
function unary(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(-x.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the SD59x18 type.
function uncheckedAdd(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the SD59x18 type.
function uncheckedSub(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the unchecked unary minus operation (-) in the SD59x18 type.
function uncheckedUnary(SD59x18 x) pure returns (SD59x18 result) {
unchecked {
result = wrap(-x.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the SD59x18 type.
function xor(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uEXP_MIN_THRESHOLD,
uEXP2_MIN_THRESHOLD,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_SD59x18,
uMAX_WHOLE_SD59x18,
uMIN_SD59x18,
uMIN_WHOLE_SD59x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { wrap } from "./Helpers.sol";
import { SD59x18 } from "./ValueType.sol";
/// @notice Calculates the absolute value of x.
///
/// @dev Requirements:
/// - x > MIN_SD59x18.
///
/// @param x The SD59x18 number for which to calculate the absolute value.
/// @return result The absolute value of x as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function abs(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Abs_MinSD59x18();
}
result = xInt < 0 ? wrap(-xInt) : x;
}
/// @notice Calculates the arithmetic average of x and y.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The arithmetic average as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
unchecked {
// This operation is equivalent to `x / 2 + y / 2`, and it can never overflow.
int256 sum = (xInt >> 1) + (yInt >> 1);
if (sum < 0) {
// If at least one of x and y is odd, add 1 to the result, because shifting negative numbers to the right
// rounds toward negative infinity. The right part is equivalent to `sum + (x % 2 == 1 || y % 2 == 1)`.
assembly ("memory-safe") {
result := add(sum, and(or(xInt, yInt), 1))
}
} else {
// Add 1 if both x and y are odd to account for the double 0.5 remainder truncated after shifting.
result = wrap(sum + (xInt & yInt & 1));
}
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x ≤ MAX_WHOLE_SD59x18
///
/// @param x The SD59x18 number to ceil.
/// @return result The smallest whole number greater than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt > uMAX_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Ceil_Overflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt > 0) {
resultInt += uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Divides two SD59x18 numbers, returning a new SD59x18 number.
///
/// @dev This is an extension of {Common.mulDiv} for signed numbers, which works by computing the signs and the absolute
/// values separately.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The denominator must not be zero.
/// - The result must fit in SD59x18.
///
/// @param x The numerator as an SD59x18 number.
/// @param y The denominator as an SD59x18 number.
/// @return result The quotient as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Div_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*UNIT÷y). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv(xAbs, uint256(uUNIT), yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Div_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}.
///
/// Requirements:
/// - Refer to the requirements in {exp2}.
/// - x < 133_084258667509499441.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
// Any input less than the threshold returns zero.
// This check also prevents an overflow for very small numbers.
if (xInt < uEXP_MIN_THRESHOLD) {
return ZERO;
}
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xInt > uEXP_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
int256 doubleUnitProduct = xInt * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method using the following formula:
///
/// $$
/// 2^{-x} = \frac{1}{2^x}
/// $$
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693.
///
/// Notes:
/// - If x < -59_794705707972522261, the result is zero.
///
/// Requirements:
/// - x < 192e18.
/// - The result must fit in SD59x18.
///
/// @param x The exponent as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
// The inverse of any number less than the threshold is truncated to zero.
if (xInt < uEXP2_MIN_THRESHOLD) {
return ZERO;
}
unchecked {
// Inline the fixed-point inversion to save gas.
result = wrap(uUNIT_SQUARED / exp2(wrap(-xInt)).unwrap());
}
} else {
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xInt > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_SD59x18_Exp2_InputTooBig(x);
}
unchecked {
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = uint256((xInt << 64) / uUNIT);
// It is safe to cast the result to int256 due to the checks above.
result = wrap(int256(Common.exp2(x_192x64)));
}
}
}
/// @notice Yields the greatest whole number less than or equal to x.
///
/// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x ≥ MIN_WHOLE_SD59x18
///
/// @param x The SD59x18 number to floor.
/// @return result The greatest whole number less than or equal to x, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < uMIN_WHOLE_SD59x18) {
revert Errors.PRBMath_SD59x18_Floor_Underflow(x);
}
int256 remainder = xInt % uUNIT;
if (remainder == 0) {
result = x;
} else {
unchecked {
// Solidity uses C fmod style, which returns a modulus with the same sign as x.
int256 resultInt = xInt - remainder;
if (xInt < 0) {
resultInt -= uUNIT;
}
result = wrap(resultInt);
}
}
}
/// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right.
/// of the radix point for negative numbers.
/// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
/// @param x The SD59x18 number to get the fractional part of.
/// @return result The fractional part of x as an SD59x18 number.
function frac(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(x.unwrap() % uUNIT);
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x * y must fit in SD59x18.
/// - x * y must not be negative, since complex numbers are not supported.
///
/// @param x The first operand as an SD59x18 number.
/// @param y The second operand as an SD59x18 number.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == 0 || yInt == 0) {
return ZERO;
}
unchecked {
// Equivalent to `xy / x != y`. Checking for overflow this way is faster than letting Solidity do it.
int256 xyInt = xInt * yInt;
if (xyInt / xInt != yInt) {
revert Errors.PRBMath_SD59x18_Gm_Overflow(x, y);
}
// The product must not be negative, since complex numbers are not supported.
if (xyInt < 0) {
revert Errors.PRBMath_SD59x18_Gm_NegativeProduct(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
uint256 resultUint = Common.sqrt(uint256(xyInt));
result = wrap(int256(resultUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The SD59x18 number for which to calculate the inverse.
/// @return result The inverse as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(SD59x18 x) pure returns (SD59x18 result) {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(SD59x18 x) pure returns (SD59x18 result) {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~195_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The SD59x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this block is the standard multiplication operation, not {SD59x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
default { result := uMAX_SD59x18 }
}
if (result.unwrap() == uMAX_SD59x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation.
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x > 0
///
/// @param x The SD59x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt <= 0) {
revert Errors.PRBMath_SD59x18_Log_InputTooSmall(x);
}
unchecked {
int256 sign;
if (xInt >= uUNIT) {
sign = 1;
} else {
sign = -1;
// Inline the fixed-point inversion to save gas.
xInt = uUNIT_SQUARED / xInt;
}
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(uint256(xInt / uUNIT));
// This is the integer part of the logarithm as an SD59x18 number. The operation can't overflow
// because n is at most 255, `UNIT` is 1e18, and the sign is either 1 or -1.
int256 resultInt = int256(n) * uUNIT;
// Calculate $y = x * 2^{-n}$.
int256 y = xInt >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultInt * sign);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
int256 DOUBLE_UNIT = 2e18;
for (int256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultInt = resultInt + delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
resultInt *= sign;
result = wrap(resultInt);
}
}
/// @notice Multiplies two SD59x18 numbers together, returning a new SD59x18 number.
///
/// @dev Notes:
/// - Refer to the notes in {Common.mulDiv18}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv18}.
/// - None of the inputs can be `MIN_SD59x18`.
/// - The result must fit in SD59x18.
///
/// @param x The multiplicand as an SD59x18 number.
/// @param y The multiplier as an SD59x18 number.
/// @return result The product as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
if (xInt == uMIN_SD59x18 || yInt == uMIN_SD59x18) {
revert Errors.PRBMath_SD59x18_Mul_InputTooSmall();
}
// Get hold of the absolute values of x and y.
uint256 xAbs;
uint256 yAbs;
unchecked {
xAbs = xInt < 0 ? uint256(-xInt) : uint256(xInt);
yAbs = yInt < 0 ? uint256(-yInt) : uint256(yInt);
}
// Compute the absolute value (x*y÷UNIT). The resulting value must fit in SD59x18.
uint256 resultAbs = Common.mulDiv18(xAbs, yAbs);
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Mul_Overflow(x, y);
}
// Check if x and y have the same sign using two's complement representation. The left-most bit represents the sign (1 for
// negative, 0 for positive or zero).
bool sameSign = (xInt ^ yInt) > -1;
// If the inputs have the same sign, the result should be positive. Otherwise, it should be negative.
unchecked {
result = wrap(sameSign ? int256(resultAbs) : -int256(resultAbs));
}
}
/// @notice Raises x to the power of y using the following formula:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {exp2}, {log2}, and {mul}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as an SD59x18 number.
/// @param y Exponent to raise x to, as an SD59x18 number
/// @return result x raised to power y, as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(SD59x18 x, SD59x18 y) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
int256 yInt = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xInt == 0) {
return yInt == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xInt == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yInt == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yInt == uUNIT) {
return x;
}
// Calculate the result using the formula.
result = exp2(mul(log2(x), y));
}
/// @notice Raises x (an SD59x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - Refer to the requirements in {abs} and {Common.mulDiv18}.
/// - The result must fit in SD59x18.
///
/// @param x The base as an SD59x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(SD59x18 x, uint256 y) pure returns (SD59x18 result) {
uint256 xAbs = uint256(abs(x).unwrap());
// Calculate the first iteration of the loop in advance.
uint256 resultAbs = y & 1 > 0 ? xAbs : uint256(uUNIT);
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
uint256 yAux = y;
for (yAux >>= 1; yAux > 0; yAux >>= 1) {
xAbs = Common.mulDiv18(xAbs, xAbs);
// Equivalent to `y % 2 == 1`.
if (yAux & 1 > 0) {
resultAbs = Common.mulDiv18(resultAbs, xAbs);
}
}
// The result must fit in SD59x18.
if (resultAbs > uint256(uMAX_SD59x18)) {
revert Errors.PRBMath_SD59x18_Powu_Overflow(x, y);
}
unchecked {
// Is the base negative and the exponent odd? If yes, the result should be negative.
int256 resultInt = int256(resultAbs);
bool isNegative = x.unwrap() < 0 && y & 1 == 1;
if (isNegative) {
resultInt = -resultInt;
}
result = wrap(resultInt);
}
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - Only the positive root is returned.
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x ≥ 0, since complex numbers are not supported.
/// - x ≤ MAX_SD59x18 / UNIT
///
/// @param x The SD59x18 number for which to calculate the square root.
/// @return result The result as an SD59x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(SD59x18 x) pure returns (SD59x18 result) {
int256 xInt = x.unwrap();
if (xInt < 0) {
revert Errors.PRBMath_SD59x18_Sqrt_NegativeInput(x);
}
if (xInt > uMAX_SD59x18 / uUNIT) {
revert Errors.PRBMath_SD59x18_Sqrt_Overflow(x);
}
unchecked {
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two SD59x18 numbers.
// In this case, the two numbers are both the square root.
uint256 resultUint = Common.sqrt(uint256(xInt * uUNIT));
result = wrap(int256(resultUint));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The signed 59.18-decimal fixed-point number representation, which can have up to 59 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type int256.
type SD59x18 is int256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoInt256,
Casting.intoSD1x18,
Casting.intoSD21x18,
Casting.intoUD2x18,
Casting.intoUD21x18,
Casting.intoUD60x18,
Casting.intoUint256,
Casting.intoUint128,
Casting.intoUint40,
Casting.unwrap
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Math.abs,
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.log10,
Math.log2,
Math.ln,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.uncheckedUnary,
Helpers.xor
} for SD59x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the SD59x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.or as |,
Helpers.sub as -,
Helpers.unary as -,
Helpers.xor as ^
} for SD59x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { UD21x18 } from "./ValueType.sol";
/// @notice Casts a UD21x18 number into SD59x18.
/// @dev There is no overflow check because UD21x18 ⊆ SD59x18.
function intoSD59x18(UD21x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(uint256(UD21x18.unwrap(x))));
}
/// @notice Casts a UD21x18 number into UD60x18.
/// @dev There is no overflow check because UD21x18 ⊆ UD60x18.
function intoUD60x18(UD21x18 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(UD21x18.unwrap(x));
}
/// @notice Casts a UD21x18 number into uint128.
/// @dev This is basically an alias for {unwrap}.
function intoUint128(UD21x18 x) pure returns (uint128 result) {
result = UD21x18.unwrap(x);
}
/// @notice Casts a UD21x18 number into uint256.
/// @dev There is no overflow check because UD21x18 ⊆ uint256.
function intoUint256(UD21x18 x) pure returns (uint256 result) {
result = uint256(UD21x18.unwrap(x));
}
/// @notice Casts a UD21x18 number into uint40.
/// @dev Requirements:
/// - x ≤ MAX_UINT40
function intoUint40(UD21x18 x) pure returns (uint40 result) {
uint128 xUint = UD21x18.unwrap(x);
if (xUint > uint128(Common.MAX_UINT40)) {
revert Errors.PRBMath_UD21x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud21x18(uint128 x) pure returns (UD21x18 result) {
result = UD21x18.wrap(x);
}
/// @notice Unwrap a UD21x18 number into uint128.
function unwrap(UD21x18 x) pure returns (uint128 result) {
result = UD21x18.unwrap(x);
}
/// @notice Wraps a uint128 number into UD21x18.
function wrap(uint128 x) pure returns (UD21x18 result) {
result = UD21x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD21x18 } from "./ValueType.sol";
/// @dev Euler's number as a UD21x18 number.
UD21x18 constant E = UD21x18.wrap(2_718281828459045235);
/// @dev The maximum value a UD21x18 number can have.
uint128 constant uMAX_UD21x18 = 340282366920938463463_374607431768211455;
UD21x18 constant MAX_UD21x18 = UD21x18.wrap(uMAX_UD21x18);
/// @dev PI as a UD21x18 number.
UD21x18 constant PI = UD21x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD21x18.
uint256 constant uUNIT = 1e18;
UD21x18 constant UNIT = UD21x18.wrap(1e18);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD21x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a UD21x18 number that doesn't fit in uint40.
error PRBMath_UD21x18_IntoUint40_Overflow(UD21x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The unsigned 21.18-decimal fixed-point number representation, which can have up to 21 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type uint128. This is useful when end users want to use uint128 to save gas, e.g. with tight variable packing in contract
/// storage.
type UD21x18 is uint128;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD21x18 global;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { UD60x18 } from "../ud60x18/ValueType.sol";
import { UD2x18 } from "./ValueType.sol";
/// @notice Casts a UD2x18 number into SD59x18.
/// @dev There is no overflow check because UD2x18 ⊆ SD59x18.
function intoSD59x18(UD2x18 x) pure returns (SD59x18 result) {
result = SD59x18.wrap(int256(uint256(UD2x18.unwrap(x))));
}
/// @notice Casts a UD2x18 number into UD60x18.
/// @dev There is no overflow check because UD2x18 ⊆ UD60x18.
function intoUD60x18(UD2x18 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint128.
/// @dev There is no overflow check because UD2x18 ⊆ uint128.
function intoUint128(UD2x18 x) pure returns (uint128 result) {
result = uint128(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint256.
/// @dev There is no overflow check because UD2x18 ⊆ uint256.
function intoUint256(UD2x18 x) pure returns (uint256 result) {
result = uint256(UD2x18.unwrap(x));
}
/// @notice Casts a UD2x18 number into uint40.
/// @dev Requirements:
/// - x ≤ MAX_UINT40
function intoUint40(UD2x18 x) pure returns (uint40 result) {
uint64 xUint = UD2x18.unwrap(x);
if (xUint > uint64(Common.MAX_UINT40)) {
revert Errors.PRBMath_UD2x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud2x18(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}
/// @notice Unwrap a UD2x18 number into uint64.
function unwrap(UD2x18 x) pure returns (uint64 result) {
result = UD2x18.unwrap(x);
}
/// @notice Wraps a uint64 number into UD2x18.
function wrap(uint64 x) pure returns (UD2x18 result) {
result = UD2x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @dev Euler's number as a UD2x18 number.
UD2x18 constant E = UD2x18.wrap(2_718281828459045235);
/// @dev The maximum value a UD2x18 number can have.
uint64 constant uMAX_UD2x18 = 18_446744073709551615;
UD2x18 constant MAX_UD2x18 = UD2x18.wrap(uMAX_UD2x18);
/// @dev PI as a UD2x18 number.
UD2x18 constant PI = UD2x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD2x18.
UD2x18 constant UNIT = UD2x18.wrap(1e18);
uint64 constant uUNIT = 1e18;// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD2x18 } from "./ValueType.sol";
/// @notice Thrown when trying to cast a UD2x18 number that doesn't fit in uint40.
error PRBMath_UD2x18_IntoUint40_Overflow(UD2x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
/// @notice The unsigned 2.18-decimal fixed-point number representation, which can have up to 2 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the underlying Solidity
/// type uint64. This is useful when end users want to use uint64 to save gas, e.g. with tight variable packing in contract
/// storage.
type UD2x18 is uint64;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD59x18,
Casting.intoUD60x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD2x18 global;// SPDX-License-Identifier: MIT pragma solidity >=0.8.19; /* ██████╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ████████╗██╗ ██╗ ██╔══██╗██╔══██╗██╔══██╗████╗ ████║██╔══██╗╚══██╔══╝██║ ██║ ██████╔╝██████╔╝██████╔╝██╔████╔██║███████║ ██║ ███████║ ██╔═══╝ ██╔══██╗██╔══██╗██║╚██╔╝██║██╔══██║ ██║ ██╔══██║ ██║ ██║ ██║██████╔╝██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ██╗ ██╗██████╗ ██████╗ ██████╗ ██╗ ██╗ ██╗ █████╗ ██║ ██║██╔══██╗██╔════╝ ██╔═████╗╚██╗██╔╝███║██╔══██╗ ██║ ██║██║ ██║███████╗ ██║██╔██║ ╚███╔╝ ╚██║╚█████╔╝ ██║ ██║██║ ██║██╔═══██╗████╔╝██║ ██╔██╗ ██║██╔══██╗ ╚██████╔╝██████╔╝╚██████╔╝╚██████╔╝██╔╝ ██╗ ██║╚█████╔╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚════╝ */ import "./ud60x18/Casting.sol"; import "./ud60x18/Constants.sol"; import "./ud60x18/Conversions.sol"; import "./ud60x18/Errors.sol"; import "./ud60x18/Helpers.sol"; import "./ud60x18/Math.sol"; import "./ud60x18/ValueType.sol";
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Errors.sol" as CastingErrors;
import { MAX_UINT128, MAX_UINT40 } from "../Common.sol";
import { uMAX_SD1x18 } from "../sd1x18/Constants.sol";
import { SD1x18 } from "../sd1x18/ValueType.sol";
import { uMAX_SD21x18 } from "../sd21x18/Constants.sol";
import { SD21x18 } from "../sd21x18/ValueType.sol";
import { uMAX_SD59x18 } from "../sd59x18/Constants.sol";
import { SD59x18 } from "../sd59x18/ValueType.sol";
import { uMAX_UD2x18 } from "../ud2x18/Constants.sol";
import { uMAX_UD21x18 } from "../ud21x18/Constants.sol";
import { UD2x18 } from "../ud2x18/ValueType.sol";
import { UD21x18 } from "../ud21x18/ValueType.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Casts a UD60x18 number into SD1x18.
/// @dev Requirements:
/// - x ≤ uMAX_SD1x18
function intoSD1x18(UD60x18 x) pure returns (SD1x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(int256(uMAX_SD1x18))) {
revert CastingErrors.PRBMath_UD60x18_IntoSD1x18_Overflow(x);
}
result = SD1x18.wrap(int64(uint64(xUint)));
}
/// @notice Casts a UD60x18 number into SD21x18.
/// @dev Requirements:
/// - x ≤ uMAX_SD21x18
function intoSD21x18(UD60x18 x) pure returns (SD21x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(int256(uMAX_SD21x18))) {
revert CastingErrors.PRBMath_UD60x18_IntoSD21x18_Overflow(x);
}
result = SD21x18.wrap(int128(uint128(xUint)));
}
/// @notice Casts a UD60x18 number into UD2x18.
/// @dev Requirements:
/// - x ≤ uMAX_UD2x18
function intoUD2x18(UD60x18 x) pure returns (UD2x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uMAX_UD2x18) {
revert CastingErrors.PRBMath_UD60x18_IntoUD2x18_Overflow(x);
}
result = UD2x18.wrap(uint64(xUint));
}
/// @notice Casts a UD60x18 number into UD21x18.
/// @dev Requirements:
/// - x ≤ uMAX_UD21x18
function intoUD21x18(UD60x18 x) pure returns (UD21x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uMAX_UD21x18) {
revert CastingErrors.PRBMath_UD60x18_IntoUD21x18_Overflow(x);
}
result = UD21x18.wrap(uint128(xUint));
}
/// @notice Casts a UD60x18 number into SD59x18.
/// @dev Requirements:
/// - x ≤ uMAX_SD59x18
function intoSD59x18(UD60x18 x) pure returns (SD59x18 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > uint256(uMAX_SD59x18)) {
revert CastingErrors.PRBMath_UD60x18_IntoSD59x18_Overflow(x);
}
result = SD59x18.wrap(int256(xUint));
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev This is basically an alias for {unwrap}.
function intoUint256(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Casts a UD60x18 number into uint128.
/// @dev Requirements:
/// - x ≤ MAX_UINT128
function intoUint128(UD60x18 x) pure returns (uint128 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT128) {
revert CastingErrors.PRBMath_UD60x18_IntoUint128_Overflow(x);
}
result = uint128(xUint);
}
/// @notice Casts a UD60x18 number into uint40.
/// @dev Requirements:
/// - x ≤ MAX_UINT40
function intoUint40(UD60x18 x) pure returns (uint40 result) {
uint256 xUint = UD60x18.unwrap(x);
if (xUint > MAX_UINT40) {
revert CastingErrors.PRBMath_UD60x18_IntoUint40_Overflow(x);
}
result = uint40(xUint);
}
/// @notice Alias for {wrap}.
function ud(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Alias for {wrap}.
function ud60x18(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}
/// @notice Unwraps a UD60x18 number into uint256.
function unwrap(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x);
}
/// @notice Wraps a uint256 number into the UD60x18 value type.
function wrap(uint256 x) pure returns (UD60x18 result) {
result = UD60x18.wrap(x);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
// NOTICE: the "u" prefix stands for "unwrapped".
/// @dev Euler's number as a UD60x18 number.
UD60x18 constant E = UD60x18.wrap(2_718281828459045235);
/// @dev The maximum input permitted in {exp}.
uint256 constant uEXP_MAX_INPUT = 133_084258667509499440;
UD60x18 constant EXP_MAX_INPUT = UD60x18.wrap(uEXP_MAX_INPUT);
/// @dev The maximum input permitted in {exp2}.
uint256 constant uEXP2_MAX_INPUT = 192e18 - 1;
UD60x18 constant EXP2_MAX_INPUT = UD60x18.wrap(uEXP2_MAX_INPUT);
/// @dev Half the UNIT number.
uint256 constant uHALF_UNIT = 0.5e18;
UD60x18 constant HALF_UNIT = UD60x18.wrap(uHALF_UNIT);
/// @dev $log_2(10)$ as a UD60x18 number.
uint256 constant uLOG2_10 = 3_321928094887362347;
UD60x18 constant LOG2_10 = UD60x18.wrap(uLOG2_10);
/// @dev $log_2(e)$ as a UD60x18 number.
uint256 constant uLOG2_E = 1_442695040888963407;
UD60x18 constant LOG2_E = UD60x18.wrap(uLOG2_E);
/// @dev The maximum value a UD60x18 number can have.
uint256 constant uMAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935;
UD60x18 constant MAX_UD60x18 = UD60x18.wrap(uMAX_UD60x18);
/// @dev The maximum whole value a UD60x18 number can have.
uint256 constant uMAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000;
UD60x18 constant MAX_WHOLE_UD60x18 = UD60x18.wrap(uMAX_WHOLE_UD60x18);
/// @dev PI as a UD60x18 number.
UD60x18 constant PI = UD60x18.wrap(3_141592653589793238);
/// @dev The unit number, which gives the decimal precision of UD60x18.
uint256 constant uUNIT = 1e18;
UD60x18 constant UNIT = UD60x18.wrap(uUNIT);
/// @dev The unit number squared.
uint256 constant uUNIT_SQUARED = 1e36;
UD60x18 constant UNIT_SQUARED = UD60x18.wrap(uUNIT_SQUARED);
/// @dev Zero as a UD60x18 number.
UD60x18 constant ZERO = UD60x18.wrap(0);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { uMAX_UD60x18, uUNIT } from "./Constants.sol";
import { PRBMath_UD60x18_Convert_Overflow } from "./Errors.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Converts a UD60x18 number to a simple integer by dividing it by `UNIT`.
/// @dev The result is rounded toward zero.
/// @param x The UD60x18 number to convert.
/// @return result The same number in basic integer form.
function convert(UD60x18 x) pure returns (uint256 result) {
result = UD60x18.unwrap(x) / uUNIT;
}
/// @notice Converts a simple integer to UD60x18 by multiplying it by `UNIT`.
///
/// @dev Requirements:
/// - x ≤ MAX_UD60x18 / UNIT
///
/// @param x The basic integer to convert.
/// @return result The same number converted to UD60x18.
function convert(uint256 x) pure returns (UD60x18 result) {
if (x > uMAX_UD60x18 / uUNIT) {
revert PRBMath_UD60x18_Convert_Overflow(x);
}
unchecked {
result = UD60x18.wrap(x * uUNIT);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { UD60x18 } from "./ValueType.sol";
/// @notice Thrown when ceiling a number overflows UD60x18.
error PRBMath_UD60x18_Ceil_Overflow(UD60x18 x);
/// @notice Thrown when converting a basic integer to the fixed-point format overflows UD60x18.
error PRBMath_UD60x18_Convert_Overflow(uint256 x);
/// @notice Thrown when taking the natural exponent of a base greater than 133_084258667509499441.
error PRBMath_UD60x18_Exp_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the binary exponent of a base greater than 192e18.
error PRBMath_UD60x18_Exp2_InputTooBig(UD60x18 x);
/// @notice Thrown when taking the geometric mean of two numbers and multiplying them overflows UD60x18.
error PRBMath_UD60x18_Gm_Overflow(UD60x18 x, UD60x18 y);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD1x18.
error PRBMath_UD60x18_IntoSD1x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD21x18.
error PRBMath_UD60x18_IntoSD21x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in SD59x18.
error PRBMath_UD60x18_IntoSD59x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD2x18.
error PRBMath_UD60x18_IntoUD2x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in UD21x18.
error PRBMath_UD60x18_IntoUD21x18_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint128.
error PRBMath_UD60x18_IntoUint128_Overflow(UD60x18 x);
/// @notice Thrown when trying to cast a UD60x18 number that doesn't fit in uint40.
error PRBMath_UD60x18_IntoUint40_Overflow(UD60x18 x);
/// @notice Thrown when taking the logarithm of a number less than UNIT.
error PRBMath_UD60x18_Log_InputTooSmall(UD60x18 x);
/// @notice Thrown when calculating the square root overflows UD60x18.
error PRBMath_UD60x18_Sqrt_Overflow(UD60x18 x);// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import { wrap } from "./Casting.sol";
import { UD60x18 } from "./ValueType.sol";
/// @notice Implements the checked addition operation (+) in the UD60x18 type.
function add(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() + y.unwrap());
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & bits);
}
/// @notice Implements the AND (&) bitwise operation in the UD60x18 type.
function and2(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() & y.unwrap());
}
/// @notice Implements the equal operation (==) in the UD60x18 type.
function eq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() == y.unwrap();
}
/// @notice Implements the greater than operation (>) in the UD60x18 type.
function gt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() > y.unwrap();
}
/// @notice Implements the greater than or equal to operation (>=) in the UD60x18 type.
function gte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() >= y.unwrap();
}
/// @notice Implements a zero comparison check function in the UD60x18 type.
function isZero(UD60x18 x) pure returns (bool result) {
// This wouldn't work if x could be negative.
result = x.unwrap() == 0;
}
/// @notice Implements the left shift operation (<<) in the UD60x18 type.
function lshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() << bits);
}
/// @notice Implements the lower than operation (<) in the UD60x18 type.
function lt(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() < y.unwrap();
}
/// @notice Implements the lower than or equal to operation (<=) in the UD60x18 type.
function lte(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() <= y.unwrap();
}
/// @notice Implements the checked modulo operation (%) in the UD60x18 type.
function mod(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() % y.unwrap());
}
/// @notice Implements the not equal operation (!=) in the UD60x18 type.
function neq(UD60x18 x, UD60x18 y) pure returns (bool result) {
result = x.unwrap() != y.unwrap();
}
/// @notice Implements the NOT (~) bitwise operation in the UD60x18 type.
function not(UD60x18 x) pure returns (UD60x18 result) {
result = wrap(~x.unwrap());
}
/// @notice Implements the OR (|) bitwise operation in the UD60x18 type.
function or(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() | y.unwrap());
}
/// @notice Implements the right shift operation (>>) in the UD60x18 type.
function rshift(UD60x18 x, uint256 bits) pure returns (UD60x18 result) {
result = wrap(x.unwrap() >> bits);
}
/// @notice Implements the checked subtraction operation (-) in the UD60x18 type.
function sub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() - y.unwrap());
}
/// @notice Implements the unchecked addition operation (+) in the UD60x18 type.
function uncheckedAdd(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() + y.unwrap());
}
}
/// @notice Implements the unchecked subtraction operation (-) in the UD60x18 type.
function uncheckedSub(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
unchecked {
result = wrap(x.unwrap() - y.unwrap());
}
}
/// @notice Implements the XOR (^) bitwise operation in the UD60x18 type.
function xor(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(x.unwrap() ^ y.unwrap());
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "../Common.sol" as Common;
import "./Errors.sol" as Errors;
import { wrap } from "./Casting.sol";
import {
uEXP_MAX_INPUT,
uEXP2_MAX_INPUT,
uHALF_UNIT,
uLOG2_10,
uLOG2_E,
uMAX_UD60x18,
uMAX_WHOLE_UD60x18,
UNIT,
uUNIT,
uUNIT_SQUARED,
ZERO
} from "./Constants.sol";
import { UD60x18 } from "./ValueType.sol";
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Calculates the arithmetic average of x and y using the following formula:
///
/// $$
/// avg(x, y) = (x & y) + ((xUint ^ yUint) / 2)
/// $$
///
/// In English, this is what this formula does:
///
/// 1. AND x and y.
/// 2. Calculate half of XOR x and y.
/// 3. Add the two results together.
///
/// This technique is known as SWAR, which stands for "SIMD within a register". You can read more about it here:
/// https://devblogs.microsoft.com/oldnewthing/20220207-00/?p=106223
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The arithmetic average as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function avg(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
unchecked {
result = wrap((xUint & yUint) + ((xUint ^ yUint) >> 1));
}
}
/// @notice Yields the smallest whole number greater than or equal to x.
///
/// @dev This is optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional
/// counterparts. See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
///
/// Requirements:
/// - x ≤ MAX_WHOLE_UD60x18
///
/// @param x The UD60x18 number to ceil.
/// @return result The smallest whole number greater than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ceil(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint > uMAX_WHOLE_UD60x18) {
revert Errors.PRBMath_UD60x18_Ceil_Overflow(x);
}
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `UNIT - remainder`.
let delta := sub(uUNIT, remainder)
// Equivalent to `x + remainder > 0 ? delta : 0`.
result := add(x, mul(delta, gt(remainder, 0)))
}
}
/// @notice Divides two UD60x18 numbers, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @param x The numerator as a UD60x18 number.
/// @param y The denominator as a UD60x18 number.
/// @return result The quotient as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function div(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv(x.unwrap(), uUNIT, y.unwrap()));
}
/// @notice Calculates the natural exponent of x using the following formula:
///
/// $$
/// e^x = 2^{x * log_2{e}}
/// $$
///
/// @dev Requirements:
/// - x ≤ 133_084258667509499440
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// This check prevents values greater than 192e18 from being passed to {exp2}.
if (xUint > uEXP_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp_InputTooBig(x);
}
unchecked {
// Inline the fixed-point multiplication to save gas.
uint256 doubleUnitProduct = xUint * uLOG2_E;
result = exp2(wrap(doubleUnitProduct / uUNIT));
}
}
/// @notice Calculates the binary exponent of x using the binary fraction method.
///
/// @dev See https://ethereum.stackexchange.com/q/79903/24693
///
/// Requirements:
/// - x < 192e18
/// - The result must fit in UD60x18.
///
/// @param x The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function exp2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
// Numbers greater than or equal to 192e18 don't fit in the 192.64-bit format.
if (xUint > uEXP2_MAX_INPUT) {
revert Errors.PRBMath_UD60x18_Exp2_InputTooBig(x);
}
// Convert x to the 192.64-bit fixed-point format.
uint256 x_192x64 = (xUint << 64) / uUNIT;
// Pass x to the {Common.exp2} function, which uses the 192.64-bit fixed-point number representation.
result = wrap(Common.exp2(x_192x64));
}
/// @notice Yields the greatest whole number less than or equal to x.
/// @dev Optimized for fractional value inputs, because every whole value has (1e18 - 1) fractional counterparts.
/// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
/// @param x The UD60x18 number to floor.
/// @return result The greatest whole number less than or equal to x, as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function floor(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
// Equivalent to `x % UNIT`.
let remainder := mod(x, uUNIT)
// Equivalent to `x - remainder > 0 ? remainder : 0)`.
result := sub(x, mul(remainder, gt(remainder, 0)))
}
}
/// @notice Yields the excess beyond the floor of x using the odd function definition.
/// @dev See https://en.wikipedia.org/wiki/Fractional_part.
/// @param x The UD60x18 number to get the fractional part of.
/// @return result The fractional part of x as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function frac(UD60x18 x) pure returns (UD60x18 result) {
assembly ("memory-safe") {
result := mod(x, uUNIT)
}
}
/// @notice Calculates the geometric mean of x and y, i.e. $\sqrt{x * y}$, rounding down.
///
/// @dev Requirements:
/// - x * y must fit in UD60x18.
///
/// @param x The first operand as a UD60x18 number.
/// @param y The second operand as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function gm(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
if (xUint == 0 || yUint == 0) {
return ZERO;
}
unchecked {
// Checking for overflow this way is faster than letting Solidity do it.
uint256 xyUint = xUint * yUint;
if (xyUint / xUint != yUint) {
revert Errors.PRBMath_UD60x18_Gm_Overflow(x, y);
}
// We don't need to multiply the result by `UNIT` here because the x*y product picked up a factor of `UNIT`
// during multiplication. See the comments in {Common.sqrt}.
result = wrap(Common.sqrt(xyUint));
}
}
/// @notice Calculates the inverse of x.
///
/// @dev Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x must not be zero.
///
/// @param x The UD60x18 number for which to calculate the inverse.
/// @return result The inverse as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function inv(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
result = wrap(uUNIT_SQUARED / x.unwrap());
}
}
/// @notice Calculates the natural logarithm of x using the following formula:
///
/// $$
/// ln{x} = log_2{x} / log_2{e}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
/// - The precision isn't sufficiently fine-grained to return exactly `UNIT` when the input is `E`.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the natural logarithm.
/// @return result The natural logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function ln(UD60x18 x) pure returns (UD60x18 result) {
unchecked {
// Inline the fixed-point multiplication to save gas. This is overflow-safe because the maximum value that
// {log2} can return is ~196_205294292027477728.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_E);
}
}
/// @notice Calculates the common logarithm of x using the following formula:
///
/// $$
/// log_{10}{x} = log_2{x} / log_2{10}
/// $$
///
/// However, if x is an exact power of ten, a hard coded value is returned.
///
/// @dev Notes:
/// - Refer to the notes in {log2}.
///
/// Requirements:
/// - Refer to the requirements in {log2}.
///
/// @param x The UD60x18 number for which to calculate the common logarithm.
/// @return result The common logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log10(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
// Note that the `mul` in this assembly block is the standard multiplication operation, not {UD60x18.mul}.
// prettier-ignore
assembly ("memory-safe") {
switch x
case 1 { result := mul(uUNIT, sub(0, 18)) }
case 10 { result := mul(uUNIT, sub(1, 18)) }
case 100 { result := mul(uUNIT, sub(2, 18)) }
case 1000 { result := mul(uUNIT, sub(3, 18)) }
case 10000 { result := mul(uUNIT, sub(4, 18)) }
case 100000 { result := mul(uUNIT, sub(5, 18)) }
case 1000000 { result := mul(uUNIT, sub(6, 18)) }
case 10000000 { result := mul(uUNIT, sub(7, 18)) }
case 100000000 { result := mul(uUNIT, sub(8, 18)) }
case 1000000000 { result := mul(uUNIT, sub(9, 18)) }
case 10000000000 { result := mul(uUNIT, sub(10, 18)) }
case 100000000000 { result := mul(uUNIT, sub(11, 18)) }
case 1000000000000 { result := mul(uUNIT, sub(12, 18)) }
case 10000000000000 { result := mul(uUNIT, sub(13, 18)) }
case 100000000000000 { result := mul(uUNIT, sub(14, 18)) }
case 1000000000000000 { result := mul(uUNIT, sub(15, 18)) }
case 10000000000000000 { result := mul(uUNIT, sub(16, 18)) }
case 100000000000000000 { result := mul(uUNIT, sub(17, 18)) }
case 1000000000000000000 { result := 0 }
case 10000000000000000000 { result := uUNIT }
case 100000000000000000000 { result := mul(uUNIT, 2) }
case 1000000000000000000000 { result := mul(uUNIT, 3) }
case 10000000000000000000000 { result := mul(uUNIT, 4) }
case 100000000000000000000000 { result := mul(uUNIT, 5) }
case 1000000000000000000000000 { result := mul(uUNIT, 6) }
case 10000000000000000000000000 { result := mul(uUNIT, 7) }
case 100000000000000000000000000 { result := mul(uUNIT, 8) }
case 1000000000000000000000000000 { result := mul(uUNIT, 9) }
case 10000000000000000000000000000 { result := mul(uUNIT, 10) }
case 100000000000000000000000000000 { result := mul(uUNIT, 11) }
case 1000000000000000000000000000000 { result := mul(uUNIT, 12) }
case 10000000000000000000000000000000 { result := mul(uUNIT, 13) }
case 100000000000000000000000000000000 { result := mul(uUNIT, 14) }
case 1000000000000000000000000000000000 { result := mul(uUNIT, 15) }
case 10000000000000000000000000000000000 { result := mul(uUNIT, 16) }
case 100000000000000000000000000000000000 { result := mul(uUNIT, 17) }
case 1000000000000000000000000000000000000 { result := mul(uUNIT, 18) }
case 10000000000000000000000000000000000000 { result := mul(uUNIT, 19) }
case 100000000000000000000000000000000000000 { result := mul(uUNIT, 20) }
case 1000000000000000000000000000000000000000 { result := mul(uUNIT, 21) }
case 10000000000000000000000000000000000000000 { result := mul(uUNIT, 22) }
case 100000000000000000000000000000000000000000 { result := mul(uUNIT, 23) }
case 1000000000000000000000000000000000000000000 { result := mul(uUNIT, 24) }
case 10000000000000000000000000000000000000000000 { result := mul(uUNIT, 25) }
case 100000000000000000000000000000000000000000000 { result := mul(uUNIT, 26) }
case 1000000000000000000000000000000000000000000000 { result := mul(uUNIT, 27) }
case 10000000000000000000000000000000000000000000000 { result := mul(uUNIT, 28) }
case 100000000000000000000000000000000000000000000000 { result := mul(uUNIT, 29) }
case 1000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 30) }
case 10000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 31) }
case 100000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 32) }
case 1000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 33) }
case 10000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 34) }
case 100000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 35) }
case 1000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 36) }
case 10000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 37) }
case 100000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 38) }
case 1000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 39) }
case 10000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 40) }
case 100000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 41) }
case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 42) }
case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 43) }
case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 44) }
case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 45) }
case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 46) }
case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 47) }
case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 48) }
case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 49) }
case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 50) }
case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 51) }
case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 52) }
case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 53) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 54) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 55) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 56) }
case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 57) }
case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 58) }
case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(uUNIT, 59) }
default { result := uMAX_UD60x18 }
}
if (result.unwrap() == uMAX_UD60x18) {
unchecked {
// Inline the fixed-point division to save gas.
result = wrap(log2(x).unwrap() * uUNIT / uLOG2_10);
}
}
}
/// @notice Calculates the binary logarithm of x using the iterative approximation algorithm:
///
/// $$
/// log_2{x} = n + log_2{y}, \text{ where } y = x*2^{-n}, \ y \in [1, 2)
/// $$
///
/// For $0 \leq x \lt 1$, the input is inverted:
///
/// $$
/// log_2{x} = -log_2{\frac{1}{x}}
/// $$
///
/// @dev See https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
///
/// Notes:
/// - Due to the lossy precision of the iterative approximation, the results are not perfectly accurate to the last decimal.
///
/// Requirements:
/// - x ≥ UNIT
///
/// @param x The UD60x18 number for which to calculate the binary logarithm.
/// @return result The binary logarithm as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function log2(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
if (xUint < uUNIT) {
revert Errors.PRBMath_UD60x18_Log_InputTooSmall(x);
}
unchecked {
// Calculate the integer part of the logarithm.
uint256 n = Common.msb(xUint / uUNIT);
// This is the integer part of the logarithm as a UD60x18 number. The operation can't overflow because n
// n is at most 255 and UNIT is 1e18.
uint256 resultUint = n * uUNIT;
// Calculate $y = x * 2^{-n}$.
uint256 y = xUint >> n;
// If y is the unit number, the fractional part is zero.
if (y == uUNIT) {
return wrap(resultUint);
}
// Calculate the fractional part via the iterative approximation.
// The `delta >>= 1` part is equivalent to `delta /= 2`, but shifting bits is more gas efficient.
uint256 DOUBLE_UNIT = 2e18;
for (uint256 delta = uHALF_UNIT; delta > 0; delta >>= 1) {
y = (y * y) / uUNIT;
// Is y^2 >= 2e18 and so in the range [2e18, 4e18)?
if (y >= DOUBLE_UNIT) {
// Add the 2^{-m} factor to the logarithm.
resultUint += delta;
// Halve y, which corresponds to z/2 in the Wikipedia article.
y >>= 1;
}
}
result = wrap(resultUint);
}
}
/// @notice Multiplies two UD60x18 numbers together, returning a new UD60x18 number.
///
/// @dev Uses {Common.mulDiv} to enable overflow-safe multiplication and division.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv}.
///
/// Requirements:
/// - Refer to the requirements in {Common.mulDiv}.
///
/// @dev See the documentation in {Common.mulDiv18}.
/// @param x The multiplicand as a UD60x18 number.
/// @param y The multiplier as a UD60x18 number.
/// @return result The product as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function mul(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
result = wrap(Common.mulDiv18(x.unwrap(), y.unwrap()));
}
/// @notice Raises x to the power of y.
///
/// For $1 \leq x \leq \infty$, the following standard formula is used:
///
/// $$
/// x^y = 2^{log_2{x} * y}
/// $$
///
/// For $0 \leq x \lt 1$, since the unsigned {log2} is undefined, an equivalent formula is used:
///
/// $$
/// i = \frac{1}{x}
/// w = 2^{log_2{i} * y}
/// x^y = \frac{1}{w}
/// $$
///
/// @dev Notes:
/// - Refer to the notes in {log2} and {mul}.
/// - Returns `UNIT` for 0^0.
/// - It may not perform well with very small values of x. Consider using SD59x18 as an alternative.
///
/// Requirements:
/// - Refer to the requirements in {exp2}, {log2}, and {mul}.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a UD60x18 number.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function pow(UD60x18 x, UD60x18 y) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
uint256 yUint = y.unwrap();
// If both x and y are zero, the result is `UNIT`. If just x is zero, the result is always zero.
if (xUint == 0) {
return yUint == 0 ? UNIT : ZERO;
}
// If x is `UNIT`, the result is always `UNIT`.
else if (xUint == uUNIT) {
return UNIT;
}
// If y is zero, the result is always `UNIT`.
if (yUint == 0) {
return UNIT;
}
// If y is `UNIT`, the result is always x.
else if (yUint == uUNIT) {
return x;
}
// If x is > UNIT, use the standard formula.
if (xUint > uUNIT) {
result = exp2(mul(log2(x), y));
}
// Conversely, if x < UNIT, use the equivalent formula.
else {
UD60x18 i = wrap(uUNIT_SQUARED / xUint);
UD60x18 w = exp2(mul(log2(i), y));
result = wrap(uUNIT_SQUARED / w.unwrap());
}
}
/// @notice Raises x (a UD60x18 number) to the power y (an unsigned basic integer) using the well-known
/// algorithm "exponentiation by squaring".
///
/// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring.
///
/// Notes:
/// - Refer to the notes in {Common.mulDiv18}.
/// - Returns `UNIT` for 0^0.
///
/// Requirements:
/// - The result must fit in UD60x18.
///
/// @param x The base as a UD60x18 number.
/// @param y The exponent as a uint256.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function powu(UD60x18 x, uint256 y) pure returns (UD60x18 result) {
// Calculate the first iteration of the loop in advance.
uint256 xUint = x.unwrap();
uint256 resultUint = y & 1 > 0 ? xUint : uUNIT;
// Equivalent to `for(y /= 2; y > 0; y /= 2)`.
for (y >>= 1; y > 0; y >>= 1) {
xUint = Common.mulDiv18(xUint, xUint);
// Equivalent to `y % 2 == 1`.
if (y & 1 > 0) {
resultUint = Common.mulDiv18(resultUint, xUint);
}
}
result = wrap(resultUint);
}
/// @notice Calculates the square root of x using the Babylonian method.
///
/// @dev See https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
///
/// Notes:
/// - The result is rounded toward zero.
///
/// Requirements:
/// - x ≤ MAX_UD60x18 / UNIT
///
/// @param x The UD60x18 number for which to calculate the square root.
/// @return result The result as a UD60x18 number.
/// @custom:smtchecker abstract-function-nondet
function sqrt(UD60x18 x) pure returns (UD60x18 result) {
uint256 xUint = x.unwrap();
unchecked {
if (xUint > uMAX_UD60x18 / uUNIT) {
revert Errors.PRBMath_UD60x18_Sqrt_Overflow(x);
}
// Multiply x by `UNIT` to account for the factor of `UNIT` picked up when multiplying two UD60x18 numbers.
// In this case, the two numbers are both the square root.
result = wrap(Common.sqrt(xUint * uUNIT));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;
import "./Casting.sol" as Casting;
import "./Helpers.sol" as Helpers;
import "./Math.sol" as Math;
/// @notice The unsigned 60.18-decimal fixed-point number representation, which can have up to 60 digits and up to 18
/// decimals. The values of this are bound by the minimum and the maximum values permitted by the Solidity type uint256.
/// @dev The value type is defined here so it can be imported in all other files.
type UD60x18 is uint256;
/*//////////////////////////////////////////////////////////////////////////
CASTING
//////////////////////////////////////////////////////////////////////////*/
using {
Casting.intoSD1x18,
Casting.intoSD21x18,
Casting.intoSD59x18,
Casting.intoUD2x18,
Casting.intoUD21x18,
Casting.intoUint128,
Casting.intoUint256,
Casting.intoUint40,
Casting.unwrap
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
MATHEMATICAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Math.avg,
Math.ceil,
Math.div,
Math.exp,
Math.exp2,
Math.floor,
Math.frac,
Math.gm,
Math.inv,
Math.ln,
Math.log10,
Math.log2,
Math.mul,
Math.pow,
Math.powu,
Math.sqrt
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes the functions in this library callable on the UD60x18 type.
using {
Helpers.add,
Helpers.and,
Helpers.eq,
Helpers.gt,
Helpers.gte,
Helpers.isZero,
Helpers.lshift,
Helpers.lt,
Helpers.lte,
Helpers.mod,
Helpers.neq,
Helpers.not,
Helpers.or,
Helpers.rshift,
Helpers.sub,
Helpers.uncheckedAdd,
Helpers.uncheckedSub,
Helpers.xor
} for UD60x18 global;
/*//////////////////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////////////////*/
// The global "using for" directive makes it possible to use these operators on the UD60x18 type.
using {
Helpers.add as +,
Helpers.and2 as &,
Math.div as /,
Helpers.eq as ==,
Helpers.gt as >,
Helpers.gte as >=,
Helpers.lt as <,
Helpers.lte as <=,
Helpers.or as |,
Helpers.mod as %,
Math.mul as *,
Helpers.neq as !=,
Helpers.not as ~,
Helpers.sub as -,
Helpers.xor as ^
} for UD60x18 global;pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; // test: 0x598ebe75B49c9bd79230673d38FF7F581DCD1AeE address constant _OSK = 0xD98492fdc4b1853051dc251638ddA05FD2Ea0788; // test: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 address constant _ROUTER = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IOSP {
event Approval(address indexed owner, address indexed spender, uint256 amount);
event ExcludedFromFee(address account);
event IncludedToFee(address account);
event OwnershipTransferred(address indexed user, address indexed newOwner);
event Transfer(address indexed from, address indexed to, uint256 amount);
function allowance(address, address) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function balanceOf(address) external view returns (uint256);
function decimals() external view returns (uint8);
function distributor() external view returns (address);
function dividendToUsersLp() external;
function excludeFromDividend(address account) external;
function excludeFromFee(address account) external;
function excludeMultipleAccountsFromFee(address[] memory accounts) external;
// function getInviter(address user) external view returns (address);
function inSwapAndLiquify() external view returns (bool);
function includeInFee(address account) external;
function isDividendExempt(address) external view returns (bool);
function isExcludedFromFee(address account) external view returns (bool);
function isInShareholders(address) external view returns (bool);
function isPreacher(address user) external view returns (bool);
function is200Pair(address user) external view returns (bool);
function lastLPFeefenhongTime() external view returns (uint256);
function launchedAtTimestamp() external view returns (uint40);
function minDistribution() external view returns (uint256);
function minPeriod() external view returns (uint256);
function name() external view returns (string memory);
function owner() external view returns (address);
function presale() external view returns (bool);
function setDistributorGasForLp(uint256 _distributorGasForLp) external;
function setMinDistribution(uint256 _minDistribution) external;
function setMinPeriod(uint256 _minPeriod) external;
function setPresale() external;
function shareholderIndexes(address) external view returns (uint256);
function shareholders(uint256) external view returns (address);
function symbol() external view returns (string memory);
function tOwnedU(address user) external view returns (uint256 totalUbuy);
function totalSupply() external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function transferOwnership(address newOwner) external;
function uniswapV2Pair() external view returns (address);
function recycle(uint256 amount) external;
// function setInvite(address user, address parent) external;
// function inviter(address user) external view returns (address parent);
function getReserveU() external view returns (uint112);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IPool {
function addRewards(address token, uint256 amount) external;
function deposit(address user, uint256 amount) external;
function withdraw(address user, uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
interface IReferral{
event BindReferral(address indexed user,address parent);
function getReferral(address _address)external view returns(address);
function isBindReferral(address _address) external view returns(bool);
function getReferralCount(address _address) external view returns(uint256);
function bindReferral(address _referral,address _user) external;
function getReferrals(address _address,uint256 _num) external view returns(address[] memory);
function getRootAddress()external view returns(address);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OwnershipTransferred(address indexed user, address indexed newOwner);
/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
//////////////////////////////////////////////////////////////*/
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner) {
owner = _owner;
emit OwnershipTransferred(address(0), _owner);
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function transferOwnership(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}{
"viaIR": true,
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"REFERRAL_","type":"address"},{"internalType":"address","name":"marketingAddress_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"PRBMath_MulDiv18_Overflow","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint40","name":"timestamp","type":"uint40"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakeTime","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"OSP","outputs":[{"internalType":"contract IOSP","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REFERRAL","outputs":[{"internalType":"contract IReferral","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"},{"components":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"bool","name":"status","type":"bool"},{"internalType":"uint8","name":"stakeIndex","type":"uint8"},{"internalType":"uint256","name":"finalReward","type":"uint256"},{"internalType":"uint256","name":"id","type":"uint256"}],"internalType":"struct Staking.Record[][]","name":"allRecords","type":"tuple[][]"},{"internalType":"uint256[]","name":"teamTotalInvestValues","type":"uint256[]"},{"internalType":"uint256[]","name":"teamVirtuallyInvestValues","type":"uint256[]"}],"name":"batchImportUserRecord","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"emergencyWithdrawOSP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"extraStakeLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"kpi","type":"uint256"},{"internalType":"uint256","name":"selfStake","type":"uint256"}],"name":"getLevel","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getSelfStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getTeamKpi","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_offset","type":"uint256"},{"internalType":"uint256","name":"_limit","type":"uint256"},{"internalType":"uint8","name":"_status","type":"uint8"}],"name":"getUserRecords","outputs":[{"components":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"bool","name":"status","type":"bool"},{"internalType":"uint8","name":"stakeIndex","type":"uint8"},{"internalType":"uint256","name":"finalReward","type":"uint256"},{"internalType":"uint256","name":"id","type":"uint256"}],"internalType":"struct Staking.Record[]","name":"records","type":"tuple[]"},{"internalType":"uint256","name":"total","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"components":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"bool","name":"status","type":"bool"},{"internalType":"uint8","name":"stakeIndex","type":"uint8"},{"internalType":"uint256","name":"finalReward","type":"uint256"},{"internalType":"uint256","name":"id","type":"uint256"}],"internalType":"struct Staking.Record[]","name":"records","type":"tuple[]"},{"internalType":"uint256","name":"_teamTotalInvestValue","type":"uint256"},{"internalType":"uint256","name":"_teamVirtuallyInvestValue","type":"uint256"}],"name":"importUserRecord","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isPreacher","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"levelSelfStakeThresholds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"levelThresholds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxPoolOSKAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxReferralDepth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxStakeAbsLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxStakeAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxStakeRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxUnstakeAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"network1In","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"network24hOut","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"networkInTimeLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"preacherThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"returnPrincipalOSPRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"rewardOfSlot","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s5Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s5Count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s5Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s6Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s6Count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s6Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s7Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s7Count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s7Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s8Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s8Count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s8Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_s5","type":"uint256"},{"internalType":"uint256","name":"_s6","type":"uint256"},{"internalType":"uint256","name":"_s7","type":"uint256"}],"name":"setGlobalCounts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"newThresholds","type":"uint256[]"}],"name":"setLevelSelfStakeThresholds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"newThresholds","type":"uint256[]"}],"name":"setLevelThresholds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"setMarketingAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxPoolOSKAmount","type":"uint256"}],"name":"setMaxPoolOSKAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_depth","type":"uint256"}],"name":"setMaxReferralDepth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_osp","type":"address"}],"name":"setOSP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"setOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_s5Rate","type":"uint256"},{"internalType":"uint256","name":"_s6Rate","type":"uint256"},{"internalType":"uint256","name":"_s7Rate","type":"uint256"},{"internalType":"uint256","name":"_s8Rate","type":"uint256"}],"name":"setPoolRates","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"setPreacherThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_stakeDays","type":"uint256[]"},{"internalType":"uint256[]","name":"_rates","type":"uint256[]"}],"name":"setProductConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_ratio","type":"uint256"}],"name":"setReturnPrincipalOSPRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_networkInTimeLimit","type":"uint256"},{"internalType":"uint256","name":"_maxStakeAbsLimit","type":"uint256"},{"internalType":"uint256","name":"_maxStakeRatio","type":"uint256"},{"internalType":"uint256","name":"_extraStakeLimit","type":"uint256"}],"name":"setRiskParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"setS5Address","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"setS6Address","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"setS7Address","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"setS8Address","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"newRates","type":"uint256[]"}],"name":"setTeamLevelRates","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setTeamVirtuallyInvestValue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"setTeamVirtuallySelfStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_timeWindow","type":"uint256"},{"internalType":"uint256","name":"_rate","type":"uint256"}],"name":"setUnstakeConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint160","name":"_amount","type":"uint160"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint8","name":"_stakeIndex","type":"uint8"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"stakeCount","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint160","name":"_amount","type":"uint160"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint8","name":"_stakeIndex","type":"uint8"},{"internalType":"address","name":"parent","type":"address"}],"name":"stakeWithInviter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sync","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"t_out","outputs":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"tamount","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"t_supply","outputs":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"tamount","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"teamLevelRates","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"teamTotalInvestValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"teamVirtuallyInvestValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"teamVirtuallySelfStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalUnstaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"unstakePrincipalOnly","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unstakeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unstakeTimeWindow","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint160","name":"_amount","type":"uint160"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint8","name":"_stakeIndex","type":"uint8"}],"name":"unstakeWithBonus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"uint160[]","name":"_amounts","type":"uint160[]"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint8","name":"_stakeIndex","type":"uint8"}],"name":"unstakeWithBonusSplit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"userStakeRecord","outputs":[{"internalType":"uint40","name":"stakeTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"bool","name":"status","type":"bool"},{"internalType":"uint8","name":"stakeIndex","type":"uint8"},{"internalType":"uint256","name":"finalReward","type":"uint256"},{"internalType":"uint256","name":"id","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]Contract Creation Code
6080604081815234620004a7578082620064428038038091620000238285620004fb565b833981010312620004a75762000039826200051f565b916200004960208092016200051f565b9060018060a01b0319926000923385855416178455815133857f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a360326004556200009681620004ac565b670de0b6c3c63b40a08152670de0b6c920619d4084820152670de0b6ce77d02ce083820152670de0b6d3cc89fcc06060820152670de0b6d91e921a20608082015293805b60059586821015620001055780516001600160401b03169682019690965594840194600101620000da565b505083868885516200011781620004ac565b62093a8081526213c6808482015262278d0087820152623b53806060820152624f1a006080820152845b600581106200048e5750506003601a5560019485601b5585601c556002601d5561016860275568056bc75e2d63100000602855606460295569152d02c7e14af6800000602a556706f05b59d3b20000602b5562015180602c556103e8602d556729a2241af62c000060315560018060a01b0380921683601054161760105516906011541617601155835163095ea7b360e01b81527310ed43c718714eb63d5aa57b78b54704e256024e6004820152600019602482015281816044818673d98492fdc4b1853051dc251638dda05fd2ea07885af18015620004845762000442575b508351916200023083620004de565b6801a055690d9db800008352681043561a882930000082840152683635c9adc5dea000008584015269010f0cf064dd59200000606084015269021e19e0c9bab2400000608084015269065a4da25d3016c0000060a0840152690a968163f0a57b40000060c084015269d3c21bcecceda100000060e084015283549260089384865580851062000425575b508482528282209085835b8681106200040957505050508451620002de81620004de565b818152818382015281868201528160608201528160808201528160a08201528160c08201528160e082015260025484600255808510620003eb575b50600282528282209085835b868110620003d5575050505084516200033e81620004de565b600481528383820152600c868201526010606082015260146080820152601860a0820152601c60c0820152601c60e082015260035484600355808510620003b7575b509160038252808220915b848110620003a2578651615ef490816200054e8239f35b835160ff16838201559281019285016200038b565b60038352838320620003ce91810190860162000534565b8662000380565b8560ff8451169301928185015501869062000325565b600283528383206200040291810190860162000534565b8662000319565b82516001600160501b03168482015591850191879101620002c5565b8583528383206200043b91810190860162000534565b86620002ba565b8181813d83116200047c575b6200045a8183620004fb565b810103126200047857518015150362000474578462000221565b5080fd5b8280fd5b503d6200044e565b85513d85823e3d90fd5b815162ffffff16600a8201559084019060010162000141565b600080fd5b60a081019081106001600160401b03821117620004c857604052565b634e487b7160e01b600052604160045260246000fd5b61010081019081106001600160401b03821117620004c857604052565b601f909101601f19168101906001600160401b03821190821017620004c857604052565b51906001600160a01b0382168203620004a757565b81811062000540575050565b600081556001016200053456fe608080604052600436101561001357600080fd5b600090813560e01c9081630418925014612ead5750806304d1a25314612e6e57806306d9023614612db157806306fdde0314612d6e57806308adb4be14612cd8578063119b99f214612c5557806318160ddd14612c3757806326aff6af14612c1957806327e235e314612be0578063313ce56714612bc457806333060d9014612b8b57806338a0eb8214612b6d5780633c271a0514612a6257806341a6e407146129dc5780634211cb3b146128f4578063430b6580146128d657806344b714e7146128b85780634b413c2a1461287f5780634b788ba5146127735780634d090fc8146127295780634f4e72631461270e5780634f7f9782146125f75780634fde3fe6146125ad5780635235934d1461258f578063570ca7351461256657806357bae3f31461254857806359f0c0e7146124ff5780635a9f261d146124e15780635c445412146124b65780635d2aa01614611cc05780635d80ca3214611ca55780635e61da0814611c79578063626ec15f14611c01578063660fa4d814611be357806368623aea14611bc55780636d16671114611b8a5780636df77dda1461186d57806370a08231146117ac57806372fbab3b1461179157806377f72287146117735780637a1fe9571461171a5780637bc20284146116d05780637d5f8fd5146116a75780637fe205511461167e57806388ab07bf146116605780638af11b3e146115d55780638c1f7041146115b75780638d4536061461157d5780638da5cb5b14611556578063906e9dd01461150c578063916633bb146113cf57806391be855c1461138557806395af896d1461136757806395d89b4114611326578063988a931b146112925780639b19251a146112535780639f9854e51461122a578063a154f99d146111e4578063b006aed2146111a9578063b108b4cb14611170578063b3ab15fb14611126578063b628c2ee146110fd578063b774bbff146110c4578063baefdf3614610e85578063bb2ae6bf14610d84578063bdd6e34314610d66578063c63568c714610d3d578063c96679fe14610d05578063c980325a14610b01578063d0cc2a1f14610ac2578063d53c149d14610a87578063d667a7d214610a69578063d673587714610a4b578063daf786af1461099f578063df8b83fb14610984578063dff12e591461095b578063e28903281461093d578063e64af65814610902578063e86ad3a1146108c9578063eb27def6146108a4578063eb5921b014610886578063ecb91401146106c8578063f2fde38b1461065b578063f4fdf73214610637578063fbacfb7a146105f2578063fece707d146105c65763fff6cae9146103de57600080fd5b346104ea57806003193601126104ea576040516370a0823160e01b8152306004820152819073d98492fdc4b1853051dc251638dda05fd2ea07889060208082602481865afa9182156105bb578492610584575b50600f546040516324dead2f60e11b81526001600160a01b0394909183908390600490829089165afa9384156105795786928395610534575b5060405163a9059cbb60e01b81526001600160a01b038616600482015260248101919091529183918391829081604481015b03925af18015610529576104fb575b505016803b156104f85781809160046040518094819363fff6cae960e01b83525af180156104ed576104da5750f35b6104e390612f18565b6104ea5780f35b80fd5b6040513d84823e3d90fd5b50fd5b8161051a92903d10610522575b6105128183612f61565b8101906132fe565b5038806104ab565b503d610508565b6040513d87823e3d90fd5b84809296508194503d8311610572575b61054e8183612f61565b8101031261056e5761049c83916105658894613e1a565b9591509161046a565b8580fd5b503d610544565b6040513d88823e3d90fd5b809450818093503d83116105b4575b61059d8183612f61565b810103126105af578392519038610431565b600080fd5b503d610593565b6040513d86823e3d90fd5b50346104ea5760203660031901126104ea5760206105ea6105e5613042565b613df0565b604051908152f35b50346104ea57610601366131dd565b9061062060018060a01b03808554163314908115610629575b506131f3565b602c55602d5580f35b90506032541633143861061a565b50346104ea5760203660031901126104ea5760206105ea610656613042565b613dc6565b50346104ea5760203660031901126104ea57610675613042565b8154906001600160a01b039061068e33838516146132c3565b1680916001600160601b0360a01b16178255337f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b50346104ea5760803660031901126104ea576106e2613042565b906106eb6130ae565b6064356001600160a01b03818116918290036107f25761070c333214613463565b6107216107176135c3565b828716111561351b565b600460ff841661073382821115613554565b14610869575b61074560243586614183565b6010541690604051633bb1db8160e21b908181523360048201526020908181602481885afa90811561085e578791610841575b501591826107f6575b5050610797575b836107948487336144eb565b80f35b813b156107f2578391604483926040519485938492631ea690cf60e21b845260048401523360248401525af180156107e7576107d4575b80610788565b916107e161079493612f18565b916107ce565b6040513d85823e3d90fd5b8380fd5b9091506040519081528260048201528181602481875afa918215610579578692610824575b50503880610781565b61083a9250803d10610522576105128183612f61565b388061081b565b6108589150823d8411610522576105128183612f61565b38610778565b6040513d89823e3d90fd5b338452602560205261088160ff604086205416613586565b610739565b50346104ea57806003193601126104ea576020601654604051908152f35b50346104ea5760206108be6108b8366131dd565b90613982565b60ff60405191168152f35b50346104ea5760203660031901126104ea57600435906002548210156104ea5760206108f483613188565b90546040519160031b1c8152f35b50346104ea5760203660031901126104ea57805461093490336001600160a01b039182161490811561062957506131f3565b60043560315580f35b50346104ea57806003193601126104ea576020601854604051908152f35b50346104ea57806003193601126104ea576015546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea5760206105ea613905565b50346104ea5760203660031901126104ea578060206109bc613042565b82546001600160a01b0391906109d590831633146132c3565b16806001600160601b0360a01b600f541617600f5560446040518094819363095ea7b360e01b83527310ed43c718714eb63d5aa57b78b54704e256024e600484015260001960248401525af180156104ed57610a2f575080f35b610a479060203d602011610522576105128183612f61565b5080f35b50346104ea57806003193601126104ea576020601b54604051908152f35b50346104ea57806003193601126104ea576020603054604051908152f35b50346104ea5760603660031901126104ea57610aad60018060a01b0382541633146132c3565b60043560165560243560175560443560185580f35b50346104ea57610ad136612ec9565b92610af260018060a09594951b0380875416331490811561062957506131f3565b602755602855602955602b5580f35b50346104ea5760803660031901126104ea57600435602435916001600160401b0383116104ea57366023840112156104ea578260040135610b4181612f82565b93610b4f6040519586612f61565b8185526020916024602087019160051b83010191368311610d0157602401905b828210610cea5750505050610b8261309e565b92610b8e333214613463565b3382526021602052610ba3836040842061306c565b509282805b8351851015610bda57600190610bd2906001600160a01b03610bca888861328c565b5116906132a0565b940193610ba8565b945491946001600160a01b0394509091610bfc602882901c8616831015613495565b6005871015610cd65760ff87600a01549160d01c166005811015610cc257610c519291610c2e91600a015411156134d7565b600460ff8816610c4082821115613554565b14610ca5575b846044359116614183565b805b8251811015610c9b5780610c7e85610c6d6001948761328c565b5116610c776135c3565b101561351b565b610c958786610c8d848861328c565b5116336144eb565b01610c53565b506107948461495e565b3383526025602052610cbd60ff604085205416613586565b610c46565b634e487b7160e01b84526032600452602484fd5b634e487b7160e01b83526032600452602483fd5b838091610cf684613058565b815201910190610b6f565b8480fd5b50346104ea5760203660031901126104ea576020906040906001600160a01b03610d2d613042565b1681528280522054604051908152f35b50346104ea57806003193601126104ea576010546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea576020601a54604051908152f35b50346104ea57602080600319360112610e81576001600160401b036004358181116107f257610db7903690600401612f99565b91610dd560018060a01b0380865416331490811561062957506131f3565b610de26008845114613316565b8251918211610e6d57600160401b8211610e6d5760019260015483600155808410610e3d575b506020019060018552845b838110610e1e578580f35b8251600080516020615e9f833981519152820155918101918401610e13565b8484600080516020615e9f83398151915292830192015b828110610e62575050610e08565b878155018590610e54565b634e487b7160e01b84526041600452602484fd5b5080fd5b50346104ea5760803660031901126104ea57610e9f613042565b610ea761309e565b6001600160a01b03909116825260216020526040822080549190610ecc6044356138a6565b9184918594805b610fad57505050610ee3816138a6565b91845b828110610f83575050506040519160408301936040845282518095526060946020606086019401915b818110610f23578580868660208301520390f35b8251805164ffffffffff1686526020818101516001600160a01b0316818801526040808301511515908801528882015160ff16898801526080808301519088015260a0918201519187019190915260c09095019490920191600101610f0f565b80610f906001928461328c565b51610f9b828761328c565b52610fa6818661328c565b5001610ee6565b806000198101116110b057610fc660001982018361306c565b505460ff6001818616149160c81c16151514610fec575b610fe6906137e5565b80610ed3565b94602435811015806110a5575b611012575b61100a610fe6916138f6565b959050610fdd565b9261100a61109c610fe69261102b6000198a018661306c565b5060026040519161103b83612ee7565b60ff815464ffffffffff8116855260018060a01b038160281c166020860152818160c81c161515604086015260d01c16606084015260018101546080840152015460a082015261108b828a61328c565b52611096818961328c565b506138f6565b94915050610ffe565b506044358410610ff9565b634e487b7160e01b87526011600452602487fd5b50346104ea5760203660031901126104ea576020906040906001600160a01b036110ec613042565b168152602483522054604051908152f35b50346104ea57806003193601126104ea576012546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea57611140613042565b81546001600160a01b03919061115990831633146132c3565b166001600160601b0360a01b603254161760325580f35b50346104ea5760203660031901126104ea576020906040906001600160a01b03611198613042565b168152602283522054604051908152f35b50346104ea5760203660031901126104ea5780546111db90336001600160a01b039182161490811561062957506131f3565b60043560045580f35b50346104ea5760403660031901126104ea576020906105ea90611224906001600160a01b03611211613042565b168152602184526040602435912061306c565b50615a27565b50346104ea57806003193601126104ea57600f546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea5760209060ff906040906001600160a01b0361127e613042565b168152602584522054166040519015158152f35b50346104ea5760603660031901126104ea576107946112af613042565b6112b76130ae565b906112c3333214613463565b6112df6112ce6135c3565b6001600160a01b038316111561351b565b600460ff83166112f182821115613554565b14611309575b61130360243582614183565b336144eb565b338452602560205261132160ff604086205416613586565b6112f7565b50346104ea57806003193601126104ea5761136360405161134681612f2b565b60048152630734f53560e41b602082015260405191829182612ff9565b0390f35b50346104ea57806003193601126104ea576020601954604051908152f35b50346104ea5760203660031901126104ea5761139f613042565b81546001600160a01b0391906113b890831633146132c3565b166001600160601b0360a01b601554161760155580f35b50346104ea5760803660031901126104ea576113e9613042565b6001600160401b03919060243583811161150857366023820112156115085780600401359384116115085760248101906024369160c087020101116115085782546001600160a01b0392839161144290831633146132c3565b1690818452602092602184526040852091855b87811061147b578660238787835260228152604435604084205552606435604082205580f35b8061149261148c6001938b866136c0565b866136f1565b6114a860406114a2838c876136c0565b016136e4565b156114b4575b01611455565b836114ca886114c4848d886136c0565b016136d0565b16868952601f88526114e160408a209182546132a0565b9055836114f3886114c4848d886136c0565b16611501601e9182546132a0565b90556114ae565b8280fd5b50346104ea5760203660031901126104ea57611526613042565b81546001600160a01b03919061153f90831633146132c3565b166001600160601b0360a01b601154161760115580f35b50346104ea57806003193601126104ea57546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea57600435906003548210156104ea5760206115a883613151565b90549060031b1c604051908152f35b50346104ea57806003193601126104ea576020601754604051908152f35b50346104ea5760403660031901126104ea576107946115f2613042565b82546001600160a01b039061164d9060243590831633148015611653575b611619906131f3565b61162284613dc6565b91829161162e86613df0565b94861688526024602052806040892055601f60205260408820546132a0565b93613e2e565b5060325483163314611610565b50346104ea57806003193601126104ea576020601c54604051908152f35b50346104ea57806003193601126104ea576014546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea576013546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea576116ea613042565b81546001600160a01b03919061170390831633146132c3565b166001600160601b0360a01b601254161760125580f35b50346104ea5760203660031901126104ea5760043590602e548210156104ea576113636117468361311a565b50546040805164ffffffffff8316815260289290921c6001600160a01b0316602083015290918291820190565b50346104ea57806003193601126104ea576020602854604051908152f35b50346104ea57806003193601126104ea5760206105ea6137f2565b50346104ea5760203660031901126104ea576117c6613042565b6001600160a01b03168152602160205260408120805490919081816117f1575b602083604051908152f35b600019820191821161185957505b611809818461306c565b5060ff815460c81c161561183e575b5080156118325761182b611809916137e5565b90506117ff565b506020915038806117e6565b9161184c6118529293615a27565b906132a0565b9038611818565b634e487b7160e01b81526011600452602490fd5b50346104ea5760803660031901126104ea576004356001600160401b038111610e815761189e9036906004016131ad565b6024356001600160401b0381116107f2576118bd9036906004016131ad565b6044939193356001600160401b03811161056e576118df9036906004016131ad565b6064959195356001600160401b038111611b86576119019036906004016131ad565b92909561191860018060a01b038a541633146132c3565b848103611b4157828103611b0457838103611abf57885b81811061193a578980f35b6119458183896136b0565b356001600160a01b0381168103611abb5786821015611aa7578160051b840135601e1985360301811215611aa35784016001600160401b03813511611aa35760c081350236036020820113611aa3576001600160a01b0382168c52602160205260408c20908c5b8d82358210611a035750505050906001916119c882878d6136b0565b35838060a01b0382168d52602260205260408d20556119e882888c6136b0565b3590838060a01b03168c52602360205260408c20550161192f565b90600191611a1961148c838635602088016136c0565b611a2d60406114a2848735602089016136c0565b15611a3a575b50016119ac565b611a726040848060a01b03611a5860206114c4878a35838c016136c0565b1692858060a01b0389168152601f602052209182546132a0565b9055818060a01b03611a8d60206114c48487358389016136c0565b16611a9b601e9182546132a0565b90558e611a33565b8b80fd5b634e487b7160e01b8b52603260045260248bfd5b8a80fd5b60405162461bcd60e51b815260206004820152601760248201527f4c656e677468206d69736d61746368207669727475616c0000000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601560248201527413195b99dd1a081b5a5cdb585d18da081d1bdd185b605a1b6044820152606490fd5b60405162461bcd60e51b815260206004820152601760248201527f4c656e677468206d69736d61746368207265636f7264730000000000000000006044820152606490fd5b8780fd5b50346104ea5760203660031901126104ea578054611bbc90336001600160a01b039182161490811561062957506131f3565b600435602a5580f35b50346104ea57806003193601126104ea576020602b54604051908152f35b50346104ea57806003193601126104ea576020602754604051908152f35b50346104ea5760203660031901126104ea57805460043590611c3790336001600160a01b039182161490811561062957506131f3565b60648111611c455760305580f35b60405162461bcd60e51b815260206004820152600c60248201526b0526174696f203c3d203130360a41b6044820152606490fd5b50346104ea5760203660031901126104ea57600435906026548210156104ea57611363611746836130e3565b50346104ea57806003193601126104ea5760206105ea6135c3565b50346104ea57602090816003193601126104ea5760043591611ce3333214613463565b33825260218152611cf7836040842061306c565b50546001600160a01b03939084611d0c6133b4565b9160281c16116124835733835260218252611d2a816040852061306c565b509384549464ffffffffff95611d42878216426133a7565b60ff8260d01c16600581101561246f57600a0154116124325760ff8160c81c1661240757829060281c1692611d7984601e546133a7565b601e55611d8884602f546132a0565b9182602f55611d95614441565b884216938482528588830191168152602e5499600160401b8b10156123f357611dc660019b60018101602e5561311a565b9390936123df575183549251600160281b600160c81b0390891660281b166001600160c81b03199093169116600160281b600160c81b03191617179055338752601f865260408720611e198682546133a7565b9055866040518681527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef883392a36001818101889055815460ff60c81b1916600160c81b1790915533875285805260408720549081019081106110b0573387528580526040872055604051918683528583015260408201527f48711929c842404f1d698f9525c36a831e8224d0bac22977e91904b3fe9f656460603392a280600f5416926040516370a0823160e01b9485825230600483015260249483838781855afa92831561220a5788936123b0575b506040519187835230600484015273d98492fdc4b1853051dc251638dda05fd2ea07889385848981885afa9182156123a5578a9261236e575b611f74945060405190611f3582612f46565b6002825260403689840137611f498261326f565b5285611f548261327c565b52604051634401edf760e11b815294859142903090858860048701614925565b03938a817310ed43c718714eb63d5aa57b78b54704e256024e968183895af180156123125761234c575b5086600f541690868a8a6040518095819382523060048301525afa918215612312578b9261231d575b50604051998a523060048b0152868a8a81895afa998a15612312578b9a6122e1575b50611ffe9291611ff8916133a7565b986133a7565b818082116122d0575b50506010546004805460405163195006c760e11b815233928101929092526024820152908990829060449082908a165afa9081156122c557908a918a916122a3575b509089905b612224575b50508798509087929161208461206833613dc6565b61207133613df0565b9061207c84836132a0565b908033613e2e565b809160305480612138575b505050806120df575b50505050600f541690813b156120da57839260405194859384926337470d6f60e21b845260048401525af180156104ed576120d1575080f35b61079490612f18565b505050fd5b60405163a9059cbb60e01b8152336004820152602481019190915291839183916044918391905af180156105795761211a575b808691612098565b8161213092903d10610522576105128183612f61565b503880612112565b60648111156122195750606461214f815b84613355565b0491821561208f57829550612166929193506133a7565b906040519361217485612f46565b6002855260403687870137836121898661326f565b5286600f54166121988661327c565b52813b15612215578991888380936121d6604051998a9687958694635c11d79560e01b8652600486015284015260a0604484015260a4830190614146565b33606483015242608483015203925af192831561220a5788936121fb575b808061208f565b61220490612f18565b386121f4565b6040513d8a823e3d90fd5b8980fd5b61214f606491612149565b815181101561229e57908a8261228f6022898e8c61224387998961328c565b51169061224f82613dc6565b9061225983613df0565b9485948483525260408120908b82541015600014612297575061227d8b82546133a7565b90555b61228982613dc6565b91613e2e565b01909161204e565b9055612280565b612053565b6122bf91503d808c833e6122b78183612f61565b81019061446a565b38612049565b6040513d8b823e3d90fd5b6122d9916133a7565b503881612007565b9099508681813d831161230b575b6122f98183612f61565b81010312611abb575198611ffe611fe9565b503d6122ef565b6040513d8d823e3d90fd5b9091508681813d8311612345575b6123358183612f61565b81010312611abb57519038611fc7565b503d61232b565b612367903d808d833e61235f8183612f61565b8101906148ac565b5038611f9e565b92939091508581813d831161239e575b6123888183612f61565b810103126122155790611f749392915191611f23565b503d61237e565b6040513d8c823e3d90fd5b9092508381813d83116123d8575b6123c88183612f61565b81010312611b8657519138611eea565b503d6123be565b634e487b7160e01b8b5260048b905260248bfd5b634e487b7160e01b8a52604160045260248afd5b60405162461bcd60e51b8152600481018690526003602482015262616c7760e81b6044820152606490fd5b60405162461bcd60e51b8152600481018690526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b6044820152606490fd5b634e487b7160e01b88526032600452602488fd5b60405162461bcd60e51b815260048101839052600b60248201526a11185a5b1e481b1a5b5a5d60aa1b6044820152606490fd5b50346104ea5760203660031901126104ea57600435906001548210156104ea5760206108f4836130be565b50346104ea57806003193601126104ea576020602954604051908152f35b50346104ea5760203660031901126104ea57602061253e61251e613042565b6001600160a01b03166000908152601f6020526040902054603154111590565b6040519015158152f35b50346104ea57806003193601126104ea576020603154604051908152f35b50346104ea57806003193601126104ea576032546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea576020602f54604051908152f35b50346104ea5760203660031901126104ea576125c7613042565b81546001600160a01b0391906125e090831633146132c3565b166001600160601b0360a01b601454161760145580f35b50346104ea5760803660031901126104ea576004356001600160a01b03602435818116808203610d015761262961309e565b92612635333214613463565b338652602160205261265d61264d866040892061306c565b5054918260281c16831015613495565b60058410156126fa5760ff84600a01549160d01c1660058110156126e6576107949594926126986126c495936126a093600a015411156134d7565b610c776135c3565b600460ff83166126b282821115613554565b146126c9575b61130360443582614183565b61495e565b33865260256020526126e160ff604088205416613586565b6126b8565b634e487b7160e01b87526032600452602487fd5b634e487b7160e01b86526032600452602486fd5b50346104ea57806003193601126104ea5760206105ea6133b4565b50346104ea5760203660031901126104ea57612743613042565b81546001600160a01b03919061275c90831633146132c3565b166001600160601b0360a01b601354161760135580f35b50346104ea57602080600319360112610e81576001600160401b03906004358281116107f2576127a7903690600401612f99565b83546127c790336001600160a01b039182161490811561062957506131f3565b6127d46008825114613316565b8051928311610e6d57600160401b8311610e6d576003548360035580841061283f575b506020019060038452835b83811061280d578480f35b82517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b82015591810191600101612802565b837fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b91820191015b81811061287457506127f7565b858155600101612867565b50346104ea5760203660031901126104ea576020906040906001600160a01b036128a7613042565b168152602383522054604051908152f35b50346104ea57806003193601126104ea576020601d54604051908152f35b50346104ea57806003193601126104ea576020602c54604051908152f35b50346104ea57602080600319360112610e81576001600160401b03906004358281116107f257612928903690600401612f99565b835461294890336001600160a01b039182161490811561062957506131f3565b6129556008825114613316565b8051928311610e6d57600160401b8311610e6d57600254836002558084106129ae575b506020019060028452835b83811061298e578480f35b8251600080516020615e7f83398151915282015591810191600101612983565b83600080516020615e7f83398151915291820191015b8181106129d15750612978565b8581556001016129c4565b50346104ea5760403660031901126104ea57806020612a506129fc613042565b83546001600160a01b0390612a1490821633146132c3565b600f5460405163a9059cbb60e01b81526001600160a01b0390931660048401526024803590840152919485939190921691839182906044820190565b03925af180156104ed57610a2f575080f35b50346104ea5760403660031901126104ea576004356001600160401b038111610e815736602382011215610e8157806004013590612a9f82612f82565b90612aad6040519283612f61565b8282526020926024602084019160051b8301019136831161056e576024859101915b838310612b555750505050602435918215158093036107f25783546001600160a01b0390811633148015612b48575b612b0a909493946131f3565b60ff859316925b8451811015612b44578082612b286001938861328c565b511687526025845260408720805460ff19168617905501612b11565b8580f35b5060325481163314612afe565b8190612b6084613058565b8152019101908490612acf565b50346104ea57806003193601126104ea576020602a54604051908152f35b50346104ea5760203660031901126104ea576020906040906001600160a01b03612bb3613042565b168152602183522054604051908152f35b50346104ea57806003193601126104ea57602060405160128152f35b50346104ea5760203660031901126104ea576020906040906001600160a01b03612c08613042565b168152601f83522054604051908152f35b50346104ea57806003193601126104ea576020602d54604051908152f35b50346104ea57806003193601126104ea576020601e54604051908152f35b50346104ea5760403660031901126104ea57610794612c72613042565b8254602435916001600160a01b0391821633148015612ccb575b612c95906131f3565b612c9e81613dc6565b612289612caa83613df0565b948594841688526023602052806040892055602260205260408820546132a0565b5060325482163314612c8c565b50346104ea5760403660031901126104ea57612cf2613042565b6001600160a01b039081168252602160205260408220805460243593908410156104ea575060c092612d239161306c565b5080549060ff60026001830154920154926040519464ffffffffff821686528160281c166020860152818160c81c161515604086015260d01c166060840152608083015260a0820152f35b50346104ea57806003193601126104ea57611363604051612d8e81612f2b565b600a81526905374616b6564204f53560b41b602082015260405191829182612ff9565b50346104ea5760403660031901126104ea576001600160401b0360043581811161150857612de3903690600401612f99565b9060243590811161150857612dfc903690600401612f99565b8254612e1c90336001600160a01b039182161490811561062957506131f3565b600590612e2c6005845114613230565b612e396005825114613230565b835b828110612e46578480f35b80612e536001928661328c565b5181600a0155612e63818461328c565b518185015501612e3b565b50346104ea57612e7d36612ec9565b92612e9e60018060a09594951b0380875416331490811561062957506131f3565b601a55601b55601c55601d5580f35b905034610e815781600319360112610e81576020906004548152f35b60809060031901126105af5760043590602435906044359060643590565b60c081019081106001600160401b03821117612f0257604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b038111612f0257604052565b604081019081106001600160401b03821117612f0257604052565b606081019081106001600160401b03821117612f0257604052565b90601f801991011681019081106001600160401b03821117612f0257604052565b6001600160401b038111612f025760051b60200190565b9080601f830112156105af576020908235612fb381612f82565b93612fc16040519586612f61565b81855260208086019260051b8201019283116105af57602001905b828210612fea575050505090565b81358152908301908301612fdc565b6020808252825181830181905290939260005b82811061302e57505060409293506000838284010152601f8019910116010190565b81810186015184820160400152850161300c565b600435906001600160a01b03821682036105af57565b35906001600160a01b03821682036105af57565b8054821015613088576000526003602060002091020190600090565b634e487b7160e01b600052603260045260246000fd5b6064359060ff821682036105af57565b6044359060ff821682036105af57565b600154811015613088576001600052600080516020615e9f8339815191520190600090565b6026548110156130885760266000527f744a2cf8fd7008e3d53b67916e73460df9fa5214e3ef23dd4259ca09493a35940190600090565b602e5481101561308857602e6000527f37fa166cbdbfbb1561ccd9ea985ec0218b5e68502e230525f544285b2bdf3d7e0190600090565b6003548110156130885760036000527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b0190600090565b600254811015613088576002600052600080516020615e7f8339815191520190600090565b9181601f840112156105af578235916001600160401b0383116105af576020808501948460051b0101116105af57565b60409060031901126105af576004359060243590565b156131fa57565b60405162461bcd60e51b815260206004820152600e60248201526d139bdd08185d5d1a1bdc9a5e995960921b6044820152606490fd5b1561323757565b60405162461bcd60e51b815260206004820152601060248201526f4c656e677468206d757374206265203560801b6044820152606490fd5b8051156130885760200190565b8051600110156130885760400190565b80518210156130885760209160051b010190565b919082018092116132ad57565b634e487b7160e01b600052601160045260246000fd5b156132ca57565b60405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606490fd5b908160209103126105af575180151581036105af5790565b1561331d57565b60405162461bcd60e51b815260206004820152601060248201526f098cadccee8d040daeae6e840c4ca40760831b6044820152606490fd5b818102929181159184041417156132ad57565b908160209103126105af57516001600160701b03811681036105af5790565b8115613391570490565b634e487b7160e01b600052601260045260246000fd5b919082039182116132ad57565b6133bc613905565b600f54604051631a7abd9760e01b815290602090829060049082906001600160a01b03165afa908115613457576127109161340c91600091613428575b506001600160701b03602d549116613355565b049081811061341c575050600090565b613425916133a7565b90565b61344a915060203d602011613450575b6134428183612f61565b810190613368565b386133f9565b503d613438565b6040513d6000823e3d90fd5b1561346a57565b60405162461bcd60e51b8152602060048201526003602482015262454f4160e81b6044820152606490fd5b1561349c57565b60405162461bcd60e51b8152602060048201526013602482015272125b9cdd59999a58da595b9d08185b5bdd5b9d606a1b6044820152606490fd5b156134de57565b60405162461bcd60e51b815260206004820152601560248201527424b739bab33334b1b4b2b73a10323ab930ba34b7b760591b6044820152606490fd5b1561352257565b60405162461bcd60e51b815260206004820152600a60248201526913dd995c88131a5b5a5d60b21b6044820152606490fd5b1561355b57565b60405162461bcd60e51b81526020600482015260036024820152620f0f4d60ea1b6044820152606490fd5b1561358d57565b60405162461bcd60e51b815260206004820152600e60248201526d13db9b1e481dda1a5d195b1a5cdd60921b6044820152606490fd5b6135cb6137f2565b600f54604051631a7abd9760e01b815290602090829060049082906001600160a01b03165afa8015613457576001600160701b0391600091613691575b50169061271061361a60295484613355565b04908181111561366e5750506000905b602a5490818110156136645761363f916133a7565b602b548082111561365d57505b80821015613658575090565b905090565b905061364c565b5050602b5461364c565b613677916133a7565b6028548082101561368a57505b9061362a565b9050613684565b6136aa915060203d602011613450576134428183612f61565b38613608565b91908110156130885760051b0190565b91908110156130885760c0020190565b356001600160a01b03811681036105af5790565b3580151581036105af5790565b8054600160401b811015612f025761370e9160018201815561306c565b9190916137cf57803564ffffffffff81168091036105af57825464ffffffffff1916178255613768613742602083016136d0565b8354600160281b600160c81b03191660289190911b600160281b600160c81b0316178355565b613791613777604083016136e4565b835460ff60c81b191690151560c81b60ff60c81b16178355565b606081013560ff811681036105af57825460ff60d01b191660d09190911b60ff60d01b1617825560029060a090608081013560018501550135910155565b634e487b7160e01b600052600060045260246000fd5b80156132ad576000190190565b602654801561386e57613807602754426133a7565b601e549091819060001981019081116132ad575b613824816130e3565b505464ffffffffff811685111561384157505061342592506133a7565b60281c6001600160a01b0316925080156138635761385e906137e5565b61381b565b5061342592506133a7565b50600090565b6040519061388182612ee7565b8160a06000918281528260208201528260408201528260608201528260808201520152565b906138b082612f82565b6138bd6040519182612f61565b82815280926138ce601f1991612f82565b019060005b8281106138df57505050565b6020906138ea613874565b828285010152016138d3565b60001981146132ad5760010190565b602e54801561386e5761391a602c54426133a7565b9060009060001981019081116132ad575b6139348161311a565b50548364ffffffffff8216106139685750801561395957613954906137e5565b61392b565b5061342591505b602f546133a7565b613425935060281c6001600160a01b031691506139609050565b6000600154918260071015613bf7577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfd548110613c0b575050506008905b60006002908154928360071015613bf7578282527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad5548110613a17575050505060085b60ff811660ff831610600014613658575090565b8360061015613bf7578282527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad4548110613a5657505050506007613a03565b8360051015613bf7578282527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad3548110613a9557505050506006613a03565b60049380851015613be4578383527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad2548210613ad75750505050506005613a03565b8060031015613be4578383527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad1548210613b145750505050613a03565b8084959293941015613bd1578484527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad0548310613b5857505050505060035b613a03565b8060011015613bd1578484527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5acf548310613b955750505050613a03565b9391929315613bbe57508252600080516020615e7f8339815191525411613b5357506001613a03565b634e487b7160e01b845260329052602483fd5b634e487b7160e01b845260328252602484fd5b634e487b7160e01b835260328552602483fd5b634e487b7160e01b82526032600452602482fd5b8260061015613bf7577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfc548110613c47575050506007906139c0565b8260051015613bf7577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfb548110613c83575050506006906139c0565b60049280841015613db3577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfa548210613cc257505050506005906139c0565b8060031015613db3577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf9548210613cfc57505050906139c0565b80600295949293951015613da0577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf8548310613d3f57506003935050505b6139c0565b8060011015613da0577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf7548310613d7c57506002935050506139c0565b15613bbe5750600080516020615e9f8339815191525411613d3a57600191506139c0565b634e487b7160e01b855260328252602485fd5b634e487b7160e01b835260328452602483fd5b60018060a01b031660005260226020526134256040600020546023602052604060002054906132a0565b60018060a01b0316600052601f6020526134256040600020546024602052604060002054906132a0565b51906001600160a01b03821682036105af57565b92613e3e90613e44939592613982565b93613982565b9160ff80600094169116818114613eb05760088103613ffe5750613e696019546137e5565b6019556015546001600160a01b039081169081613fa6575b50505b60088103613f115750613e986019546138f6565b6019556015546001600160a01b039081169182613eb6575b50505050565b823b156107f25790604484928360405195869485936311f9fbc960e21b8552166004840152670de0b6b3a764000060248401525af180156104ed57613efd575b8080613eb0565b613f078291612f18565b6104ea5780613ef6565b60078103613f425750613f256018546138f6565b6018556014546001600160a01b039081169182613eb65750505050565b60068103613f735750613f566017546138f6565b6017556013546001600160a01b039081169182613eb65750505050565b600514613f7e575050565b613f896016546138f6565b6016556012546001600160a01b039081169182613eb65750505050565b813b15610d0157849160448392604051948593849263f3fef3a360e01b845289166004840152670de0b6b3a764000060248401525af180156105bb5790849115613e8157613ff390612f18565b611508578238613e81565b6007810361408a57506140126018546137e5565b6018556014546001600160a01b039081169081614032575b50505b613e84565b813b15610d0157849160448392604051948593849263f3fef3a360e01b845289166004840152670de0b6b3a764000060248401525af180156105bb579084911561402a5761407f90612f18565b61150857823861402a565b600681036140bc575061409e6017546137e5565b6017556013546001600160a01b039081169081614032575050613e84565b60050361402d576140ce6016546137e5565b6016556012546001600160a01b0390811690816140ec575050613e84565b813b15610d0157849160448392604051948593849263f3fef3a360e01b845289166004840152670de0b6b3a764000060248401525af180156105bb57614133575b8061402a565b61413f90939193612f18565b913861412d565b90815180825260208080930193019160005b828110614166575050505090565b83516001600160a01b031685529381019392810192600101614158565b604080516323b872dd60e01b81523360048201523060248201526001600160a01b038381166044830152600094602094909273d98492fdc4b1853051dc251638dda05fd2ea0788919086816064818b875af180156144375761441a575b508480516141ed81612f46565b60028152873691013784519561420287612f46565b60028752853682890137826142168861326f565b5283600f541693846142278961327c565b5286519282846024816370a0823160e01b998a82523060048301525afa9384156143e1578a946143eb575b5060011c60016001609f1b0316977310ed43c718714eb63d5aa57b78b54704e256024e96873b15611abb578a908a6142af8b519485938493635c11d79560e01b85526004850152602484015260a0604484015260a4830190614146565b3060648301524260848301520381838b5af180156143e1576143ce575b50600f54169386519081523060048201528181602481885afa9182156143c4579089939291849261438b575b50509461430c6101049493926060976133a7565b8751988996879562e8e33760e81b875260048701526024860152604485015260648401528160848401528160a48401528160c48401524260e48401525af1908115614382575061435a575050565b606090813d831161437b575b6143708183612f61565b810103126104ea5750565b503d614366565b513d84823e3d90fd5b819594508092503d83116143bd575b6143a48183612f61565b810103126105af5791519091879161430c6101046142f8565b503d61439a565b87513d8b823e3d90fd5b6143da90999199612f18565b97386142cc565b88513d8c823e3d90fd5b9093508281813d8311614413575b6144038183612f61565b8101031261221557519238614252565b503d6143f9565b61443090873d8911610522576105128183612f61565b50386141e0565b86513d8a823e3d90fd5b60405190604082018281106001600160401b03821117612f025760405260006020838281520152565b60209081818403126105af578051906001600160401b0382116105af57019180601f840112156105af57825161449f81612f82565b936144ad6040519586612f61565b818552838086019260051b8201019283116105af578301905b8282106144d4575050505090565b8380916144e084613e1a565b8152019101906144c6565b9192909260018060a01b03908160105416926040938451633bb1db8160e21b8152602081602481888b16958660048301525afa9081156148a157600091614882575b50156148555761453b614441565b9664ffffffffff938442169889815286601e54166020820190815260265491600160401b9283811015612f025780600161457892016026556130e3565b6137cf57905181549251600160281b600160c81b03908b1660281b166001600160c81b0319909316908916600160281b600160c81b0319161791909117905564ffffffffff19846000526021602052888060002091898354966145d9613874565b9e8f52169c8d938460208301528382019560008752606083019560ff8916875261462760a08501968b885261461083601e546132a0565b601e558c600052601f6020526000209182546132a0565b9055815490811015612f02576146429160018201815561306c565b9590956137cf57815186546020840151600160281b600160c81b03908f1660281b169c909116931692909217600160281b600160c81b031916999099178455614714986002936080926146cb9160ff916146b19051895460ff60c81b191690151560c81b60ff60c81b16178955565b51875460ff60d01b1916911660d01b60ff60d01b16178655565b015160018401555191015560105460048054895163195006c760e11b81526001600160a01b038c1692810192909252602482015295600091879190891690829081906044820190565b03915afa94851561484a5760009561482d575b5060005b855181101561478657806147808b8a8a6147476001968c61328c565b511661475281613dc6565b61228961475e83613df0565b9485948460005260226020526000206147788282546132a0565b9055826132a0565b0161472b565b5094509491969250946147b89061479c81613dc6565b906147a681613df0565b91806147b287856133a7565b92613e2e565b8460007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208451868152a36005831015613088577f9cfd25589d1eb8ad71e342a86a8524e83522e3936c0803048c08f6d9ad974f4093608093600a01549180519384524260208501528301526060820152a2565b6148439195503d806000833e6122b78183612f61565b9338614727565b87513d6000823e3d90fd5b845162461bcd60e51b81526020600482015260066024820152650848589a5b9960d21b6044820152606490fd5b61489b915060203d602011610522576105128183612f61565b3861452d565b86513d6000823e3d90fd5b60209081818403126105af578051906001600160401b0382116105af57019180601f840112156105af5782516148e181612f82565b936148ef6040519586612f61565b818552838086019260051b8201019283116105af578301905b828210614916575050505090565b81518152908301908301614908565b919260809361494a92979695978452602084015260a0604084015260a0830190614146565b6001600160a01b0390951660608201520152565b9060003381526021602052614976836040832061306c565b509182549364ffffffffff9061498e828716426133a7565b60ff8760d01c1660058110156126fa57600a0154116159ea5760ff8660c81c166159bf57601e546149cd90602888901c6001600160a01b0316906133a7565b601e55338452601f6020526040842080546149f690602889901c6001600160a01b0316906133a7565b90558360405160018060a01b038860281c1681527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60203392a3614a3985615a27565b6001808701829055865460ff60c81b1916600160c81b17909655338552602080526040852054909581019081106159ab57338552602080526040852055604051918583524216602083015260408201527f48711929c842404f1d698f9525c36a831e8224d0bac22977e91904b3fe9f656460603392a2600f546040516370a0823160e01b815230600482015293906001600160a01b0316602085602481845afa9485156105bb578495615977575b506040516370a0823160e01b81523060048201529060208260248173d98492fdc4b1853051dc251638dda05fd2ea07885afa91821561052957908591829361593e575b50614b93929360405191614b3d83612f46565b600283526040366020850137614b528361326f565b5273d98492fdc4b1853051dc251638dda05fd2ea0788614b718361327c565b52604051634401edf760e11b81529384928392429130918c9060048701614925565b0381837310ed43c718714eb63d5aa57b78b54704e256024e5af180156105bb57615924575b50600f546040516370a0823160e01b81523060048201526001600160a01b039091169190602081602481865afa9081156105295785916158f2575b506040516370a0823160e01b81523060048201529560208760248173d98492fdc4b1853051dc251638dda05fd2ea07885afa9687156105795786976158bc575b5091614c47614c4d92614ca39695946133a7565b966133a7565b849190602888901c6001600160a01b0316811161589a575b506010546004805460405163195006c760e11b81523392810192909252602482015294869186916001600160a01b0390911690829081906044820190565b03915afa93841561052957859461587e575b5081614fa3575b5050825b8251811015614d4c57600190614d3f6001600160a01b03614ce1838761328c565b5116614cec81613dc6565b614cf582613df0565b918291818a526022806020528a8d60408220908a8060a01b039060281c1681541015600014614d45575083905260205260408a2061227d8d898060a01b039060281c1682546133a7565b01614cc0565b5550612280565b50939050919091614d80614d5f33613dc6565b614d6833613df0565b9061207c602885901c6001600160a01b0316836132a0565b602881901c6001600160a01b0316908380614f98575b614e58575b5080614df5575b50600f546001600160a01b031690813b156115085782916024839260405194859384926337470d6f60e21b845260048401525af180156104ed57614de4575050565b614dee8291612f18565b6104ea5750565b60405163a9059cbb60e01b815233600482015260248101919091526020816044818673d98492fdc4b1853051dc251638dda05fd2ea07885af180156107e75715614da257614e519060203d602011610522576105128183612f61565b5038614da2565b6030546064811115614f8d57506064614e7f815b602884901c6001600160a01b0316613355565b049081614e8d575b50614d9b565b909150614ea790829060281c6001600160a01b03166133a7565b9060405190614eb582612f46565b60028252604036602084013773d98492fdc4b1853051dc251638dda05fd2ea0788614edf8361326f565b52600f546001600160a01b0316614ef58361327c565b527310ed43c718714eb63d5aa57b78b54704e256024e3b15610d0157614f459185916040519384928392635c11d79560e01b8452600484015284602484015260a0604484015260a4830190614146565b3360648301524260848301520381837310ed43c718714eb63d5aa57b78b54704e256024e5af180156105bb5790849115614e8757614f8290612f18565b611508578238614e87565b614e7f606491614e6c565b506030541515614d96565b614fca614fc1614fb8601a54601b54906132a0565b601c54906132a0565b601d54906132a0565b906064614fd78385613355565b046003548060001981011161586a576064615008614ffb61500f9360001901613151565b90549060031b1c87613355565b04826132a0565b9161501a83866133a7565b61502481856132a0565b9182615035575b5050505050614cbc565b6040519061504282612f46565b60028252604036602084013773d98492fdc4b1853051dc251638dda05fd2ea078861506c8361326f565b52806150778361327c565b5260405163d06ca61f60e01b8152846004820152604060248201528b81806150a26044820187614146565b03817310ed43c718714eb63d5aa57b78b54704e256024e5afa9081156157ea57906150d4918d91615850575b5061327c565b519081605a810204605a148215171561583c57906020602495949392604051968780926370a0823160e01b82523060048301525afa9485156157ea578c95615808575b507310ed43c718714eb63d5aa57b78b54704e256024e3b15611aa35761515f918c916040519384928392635c11d79560e01b845242916064605a309302048a60048701614925565b0381837310ed43c718714eb63d5aa57b78b54704e256024e5af18015612312576157f5575b50600f546040516370a0823160e01b81523060048201526001600160a01b0390911693602082602481885afa80156157ea578c906157b6575b6151c792506133a7565b91826151d4575b5061502b565b6151e16151e69284613355565b613387565b9182615754575b50906151f8916133a7565b9182615207575b8080806151ce565b6151e16152149284613355565b918061523b575b50615231929161522a916133a7565b9084615b01565b38808080806151ff565b601654151580615740575b1561572f576012546001600160a01b03165b615268826151e1601a5487613355565b600f5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529293929091602091839160449183918f91165af180156123a557615710575b506012546001600160a01b03908116911681146156a2575b5060175415158061568e575b1561567c576013546001600160a01b0316905b6152f5836151e1601b5488613355565b600f5460405163a9059cbb60e01b81526001600160a01b038086166004830152602482018490529294929091602091839116818e816044810103925af180156123125761565d575b506013546001600160a01b03908116911681146155ef575b5090615360916132a0565b6018541515806155db575b156155c5576014546001600160a01b03169161538e905b6151e1601c5487613355565b600f5460405163a9059cbb60e01b81526001600160a01b038581166004830152602482018490529294929091602091839160449183918f91165af180156123a5576155a6575b506014546001600160a01b0390811691168114615538575b50906153f7916132a0565b601954151580615524575b1561550e576015546001600160a01b03169061541f905b846133a7565b600f5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529293929091602091839160449183918e91165af180156122c5576154ef575b506015546001600160a01b0390811691168114615483575b5061521b565b600f546001600160a01b0316813b156154eb5760405163a9fc507b60e01b81526001600160a01b03919091166004820152602481019290925287908290604490829084905af1801561085e579087911561547d576154e090612f18565b61056e57853861547d565b8880fd5b6155079060203d602011610522576105128183612f61565b5038615465565b6011546001600160a01b03169061541f90615419565b506015546001600160a01b03161515615402565b600f546001600160a01b0316813b156122155760405163a9fc507b60e01b81526001600160a01b03919091166004820152602481018490529089908290604490829084905af180156122c557908991615592575b506153ec565b61559b90612f18565b611b8657873861558c565b6155be9060203d602011610522576105128183612f61565b50386153d4565b6011546001600160a01b03169161538e90615382565b506014546001600160a01b0316151561536b565b600f546001600160a01b0316813b15611abb5760405163a9fc507b60e01b81526001600160a01b0391909116600482015260248101849052908a908290604490829084905af180156123a557908a91615649575b50615355565b61565290612f18565b6154eb578838615643565b6156759060203d602011610522576105128183612f61565b503861533d565b6011546001600160a01b0316906152e5565b506013546001600160a01b031615156152d2565b600f546001600160a01b0316813b156122155760405163a9fc507b60e01b81526001600160a01b03919091166004820152602481018390529089908290604490829084905af180156122c5579089916156fc575b506152c6565b61570590612f18565b611b865787386156f6565b6157289060203d602011610522576105128183612f61565b50386152ae565b6011546001600160a01b0316615258565b506012546001600160a01b03161515615246565b60405163a9059cbb60e01b81523360048201526024810184905290602090829060449082908e905af180156123a557906151f8939291615797575b5090916151ed565b6157af9060203d602011610522576105128183612f61565b503861578f565b506020823d6020116157e2575b816157d060209383612f61565b810103126105af576151c791516151bd565b3d91506157c3565b6040513d8e823e3d90fd5b615801909a919a612f18565b9838615184565b9094506020813d602011615834575b8161582460209383612f61565b81010312611aa357519338615117565b3d9150615817565b634e487b7160e01b8c52601160045260248cfd5b61586491503d808f833e61235f8183612f61565b386150ce565b634e487b7160e01b88526011600452602488fd5b6158939194503d8087833e6122b78183612f61565b9238614cb5565b9091506158b590602888901c6001600160a01b0316906133a7565b9038614c65565b9096506020813d6020116158ea575b816158d860209383612f61565b8101031261056e575195614c47614c33565b3d91506158cb565b90506020813d60201161591c575b8161590d60209383612f61565b81010312610d01575138614bf3565b3d9150615900565b615937903d8086833e61235f8183612f61565b5038614bb8565b915091506020813d60201161596f575b8161595b60209383612f61565b81010312610d015751908490614b93614b2a565b3d915061594e565b9094506020813d6020116159a3575b8161599360209383612f61565b810103126107f257519338614ae7565b3d9150615986565b634e487b7160e01b85526011600452602485fd5b60405162461bcd60e51b8152602060048201526003602482015262616c7760e81b6044820152606490fd5b60405162461bcd60e51b8152602060048201526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b6044820152606490fd5b54602881901c6001600160a01b03169064ffffffffff80821642821603918183116132ad5760d01c60ff16916005831015613088578183600a0154168083831610600014615af95750905b81169182615a805750505090565b60050154939290915060018481841615615ae457647fffffffff905b9360011c1694855b615ab5575050613425929350615de8565b80615abf91615de8565b9485828216615ad3575b50811c9485615aa4565b615add9194615de8565b9285615ac9565b50647fffffffff670de0b6b3a7640000615a9c565b905090615a72565b91908115615de357600390600354600019908181019081116132ad57615b39615b2b606492613151565b90549060031b1c8094613355565b0415615d955760008060005b8751811015615d88576001600160a01b0380615b61838b61328c565b5116615b6c81613dc6565b6001600160a01b0382166000908152601f602052604090205460315491939111615d7d576000926001805490898201918213166159ab575b6000811215615d11575b505087858411615bc7575b505050506001905b01615b45565b6151e1615bdc8597615be294959799966133a7565b8c613355565b600f546040805163a9059cbb60e01b81526001600160a01b03969096166004870152602486018390529194602093909291849184916044918391600091165af1908115615d07575090615c3e94939291615ce9575b50506132a0565b9184821015615c505738808087615bb9565b50509394505050505b818110615c64575050565b600f54601154615cbf936020936001600160a01b039283169390921691615c8a916133a7565b60405163a9059cbb60e01b81526001600160a01b03909316600484015260248301529092839190829060009082906044820190565b03925af1801561345757615cd1575b50565b615cce9060203d602011610522576105128183612f61565b81615cff92903d10610522576105128183612f61565b503880615c37565b513d6000823e3d90fd5b615d1a816130be565b9054908c1b1c821015615d2c85613df0565b8c615d3684613188565b9054911b1c111581615d75575b50615d5a57600160ff1b81146132ad578801615ba4565b9050615d67919350613151565b905490891b1c913880615bae565b905038615d43565b505050600190615bc1565b5050939450505050615c59565b5050600f5460115460405163a9059cbb60e01b81526001600160a01b03918216600482015260248101949094529293506020928492506044918391600091165af1801561345757615cd15750565b505050565b90919060001983820983820291828083109203918083039214615e6d57670de0b6b3a76400009081831015615e4f57947faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac1066994950990828211900360ee1b910360121c170290565b6044908660405191635173648d60e01b835260048301526024820152fd5b5050670de0b6b3a76400009004915056fe405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5aceb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6a2646970667358221220e046a944cbe48a8aa84e69d4c2efc8fa3ae2e62107076347c7abd993fcf84bdc64736f6c634300081600330000000000000000000000008b74b65763f3fd7aa8b1b6a533bd0fb7b196448400000000000000000000000047166369d54914e61c1bbcbcf528bae2307212a7
Deployed Bytecode
0x608080604052600436101561001357600080fd5b600090813560e01c9081630418925014612ead5750806304d1a25314612e6e57806306d9023614612db157806306fdde0314612d6e57806308adb4be14612cd8578063119b99f214612c5557806318160ddd14612c3757806326aff6af14612c1957806327e235e314612be0578063313ce56714612bc457806333060d9014612b8b57806338a0eb8214612b6d5780633c271a0514612a6257806341a6e407146129dc5780634211cb3b146128f4578063430b6580146128d657806344b714e7146128b85780634b413c2a1461287f5780634b788ba5146127735780634d090fc8146127295780634f4e72631461270e5780634f7f9782146125f75780634fde3fe6146125ad5780635235934d1461258f578063570ca7351461256657806357bae3f31461254857806359f0c0e7146124ff5780635a9f261d146124e15780635c445412146124b65780635d2aa01614611cc05780635d80ca3214611ca55780635e61da0814611c79578063626ec15f14611c01578063660fa4d814611be357806368623aea14611bc55780636d16671114611b8a5780636df77dda1461186d57806370a08231146117ac57806372fbab3b1461179157806377f72287146117735780637a1fe9571461171a5780637bc20284146116d05780637d5f8fd5146116a75780637fe205511461167e57806388ab07bf146116605780638af11b3e146115d55780638c1f7041146115b75780638d4536061461157d5780638da5cb5b14611556578063906e9dd01461150c578063916633bb146113cf57806391be855c1461138557806395af896d1461136757806395d89b4114611326578063988a931b146112925780639b19251a146112535780639f9854e51461122a578063a154f99d146111e4578063b006aed2146111a9578063b108b4cb14611170578063b3ab15fb14611126578063b628c2ee146110fd578063b774bbff146110c4578063baefdf3614610e85578063bb2ae6bf14610d84578063bdd6e34314610d66578063c63568c714610d3d578063c96679fe14610d05578063c980325a14610b01578063d0cc2a1f14610ac2578063d53c149d14610a87578063d667a7d214610a69578063d673587714610a4b578063daf786af1461099f578063df8b83fb14610984578063dff12e591461095b578063e28903281461093d578063e64af65814610902578063e86ad3a1146108c9578063eb27def6146108a4578063eb5921b014610886578063ecb91401146106c8578063f2fde38b1461065b578063f4fdf73214610637578063fbacfb7a146105f2578063fece707d146105c65763fff6cae9146103de57600080fd5b346104ea57806003193601126104ea576040516370a0823160e01b8152306004820152819073d98492fdc4b1853051dc251638dda05fd2ea07889060208082602481865afa9182156105bb578492610584575b50600f546040516324dead2f60e11b81526001600160a01b0394909183908390600490829089165afa9384156105795786928395610534575b5060405163a9059cbb60e01b81526001600160a01b038616600482015260248101919091529183918391829081604481015b03925af18015610529576104fb575b505016803b156104f85781809160046040518094819363fff6cae960e01b83525af180156104ed576104da5750f35b6104e390612f18565b6104ea5780f35b80fd5b6040513d84823e3d90fd5b50fd5b8161051a92903d10610522575b6105128183612f61565b8101906132fe565b5038806104ab565b503d610508565b6040513d87823e3d90fd5b84809296508194503d8311610572575b61054e8183612f61565b8101031261056e5761049c83916105658894613e1a565b9591509161046a565b8580fd5b503d610544565b6040513d88823e3d90fd5b809450818093503d83116105b4575b61059d8183612f61565b810103126105af578392519038610431565b600080fd5b503d610593565b6040513d86823e3d90fd5b50346104ea5760203660031901126104ea5760206105ea6105e5613042565b613df0565b604051908152f35b50346104ea57610601366131dd565b9061062060018060a01b03808554163314908115610629575b506131f3565b602c55602d5580f35b90506032541633143861061a565b50346104ea5760203660031901126104ea5760206105ea610656613042565b613dc6565b50346104ea5760203660031901126104ea57610675613042565b8154906001600160a01b039061068e33838516146132c3565b1680916001600160601b0360a01b16178255337f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b50346104ea5760803660031901126104ea576106e2613042565b906106eb6130ae565b6064356001600160a01b03818116918290036107f25761070c333214613463565b6107216107176135c3565b828716111561351b565b600460ff841661073382821115613554565b14610869575b61074560243586614183565b6010541690604051633bb1db8160e21b908181523360048201526020908181602481885afa90811561085e578791610841575b501591826107f6575b5050610797575b836107948487336144eb565b80f35b813b156107f2578391604483926040519485938492631ea690cf60e21b845260048401523360248401525af180156107e7576107d4575b80610788565b916107e161079493612f18565b916107ce565b6040513d85823e3d90fd5b8380fd5b9091506040519081528260048201528181602481875afa918215610579578692610824575b50503880610781565b61083a9250803d10610522576105128183612f61565b388061081b565b6108589150823d8411610522576105128183612f61565b38610778565b6040513d89823e3d90fd5b338452602560205261088160ff604086205416613586565b610739565b50346104ea57806003193601126104ea576020601654604051908152f35b50346104ea5760206108be6108b8366131dd565b90613982565b60ff60405191168152f35b50346104ea5760203660031901126104ea57600435906002548210156104ea5760206108f483613188565b90546040519160031b1c8152f35b50346104ea5760203660031901126104ea57805461093490336001600160a01b039182161490811561062957506131f3565b60043560315580f35b50346104ea57806003193601126104ea576020601854604051908152f35b50346104ea57806003193601126104ea576015546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea5760206105ea613905565b50346104ea5760203660031901126104ea578060206109bc613042565b82546001600160a01b0391906109d590831633146132c3565b16806001600160601b0360a01b600f541617600f5560446040518094819363095ea7b360e01b83527310ed43c718714eb63d5aa57b78b54704e256024e600484015260001960248401525af180156104ed57610a2f575080f35b610a479060203d602011610522576105128183612f61565b5080f35b50346104ea57806003193601126104ea576020601b54604051908152f35b50346104ea57806003193601126104ea576020603054604051908152f35b50346104ea5760603660031901126104ea57610aad60018060a01b0382541633146132c3565b60043560165560243560175560443560185580f35b50346104ea57610ad136612ec9565b92610af260018060a09594951b0380875416331490811561062957506131f3565b602755602855602955602b5580f35b50346104ea5760803660031901126104ea57600435602435916001600160401b0383116104ea57366023840112156104ea578260040135610b4181612f82565b93610b4f6040519586612f61565b8185526020916024602087019160051b83010191368311610d0157602401905b828210610cea5750505050610b8261309e565b92610b8e333214613463565b3382526021602052610ba3836040842061306c565b509282805b8351851015610bda57600190610bd2906001600160a01b03610bca888861328c565b5116906132a0565b940193610ba8565b945491946001600160a01b0394509091610bfc602882901c8616831015613495565b6005871015610cd65760ff87600a01549160d01c166005811015610cc257610c519291610c2e91600a015411156134d7565b600460ff8816610c4082821115613554565b14610ca5575b846044359116614183565b805b8251811015610c9b5780610c7e85610c6d6001948761328c565b5116610c776135c3565b101561351b565b610c958786610c8d848861328c565b5116336144eb565b01610c53565b506107948461495e565b3383526025602052610cbd60ff604085205416613586565b610c46565b634e487b7160e01b84526032600452602484fd5b634e487b7160e01b83526032600452602483fd5b838091610cf684613058565b815201910190610b6f565b8480fd5b50346104ea5760203660031901126104ea576020906040906001600160a01b03610d2d613042565b1681528280522054604051908152f35b50346104ea57806003193601126104ea576010546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea576020601a54604051908152f35b50346104ea57602080600319360112610e81576001600160401b036004358181116107f257610db7903690600401612f99565b91610dd560018060a01b0380865416331490811561062957506131f3565b610de26008845114613316565b8251918211610e6d57600160401b8211610e6d5760019260015483600155808410610e3d575b506020019060018552845b838110610e1e578580f35b8251600080516020615e9f833981519152820155918101918401610e13565b8484600080516020615e9f83398151915292830192015b828110610e62575050610e08565b878155018590610e54565b634e487b7160e01b84526041600452602484fd5b5080fd5b50346104ea5760803660031901126104ea57610e9f613042565b610ea761309e565b6001600160a01b03909116825260216020526040822080549190610ecc6044356138a6565b9184918594805b610fad57505050610ee3816138a6565b91845b828110610f83575050506040519160408301936040845282518095526060946020606086019401915b818110610f23578580868660208301520390f35b8251805164ffffffffff1686526020818101516001600160a01b0316818801526040808301511515908801528882015160ff16898801526080808301519088015260a0918201519187019190915260c09095019490920191600101610f0f565b80610f906001928461328c565b51610f9b828761328c565b52610fa6818661328c565b5001610ee6565b806000198101116110b057610fc660001982018361306c565b505460ff6001818616149160c81c16151514610fec575b610fe6906137e5565b80610ed3565b94602435811015806110a5575b611012575b61100a610fe6916138f6565b959050610fdd565b9261100a61109c610fe69261102b6000198a018661306c565b5060026040519161103b83612ee7565b60ff815464ffffffffff8116855260018060a01b038160281c166020860152818160c81c161515604086015260d01c16606084015260018101546080840152015460a082015261108b828a61328c565b52611096818961328c565b506138f6565b94915050610ffe565b506044358410610ff9565b634e487b7160e01b87526011600452602487fd5b50346104ea5760203660031901126104ea576020906040906001600160a01b036110ec613042565b168152602483522054604051908152f35b50346104ea57806003193601126104ea576012546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea57611140613042565b81546001600160a01b03919061115990831633146132c3565b166001600160601b0360a01b603254161760325580f35b50346104ea5760203660031901126104ea576020906040906001600160a01b03611198613042565b168152602283522054604051908152f35b50346104ea5760203660031901126104ea5780546111db90336001600160a01b039182161490811561062957506131f3565b60043560045580f35b50346104ea5760403660031901126104ea576020906105ea90611224906001600160a01b03611211613042565b168152602184526040602435912061306c565b50615a27565b50346104ea57806003193601126104ea57600f546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea5760209060ff906040906001600160a01b0361127e613042565b168152602584522054166040519015158152f35b50346104ea5760603660031901126104ea576107946112af613042565b6112b76130ae565b906112c3333214613463565b6112df6112ce6135c3565b6001600160a01b038316111561351b565b600460ff83166112f182821115613554565b14611309575b61130360243582614183565b336144eb565b338452602560205261132160ff604086205416613586565b6112f7565b50346104ea57806003193601126104ea5761136360405161134681612f2b565b60048152630734f53560e41b602082015260405191829182612ff9565b0390f35b50346104ea57806003193601126104ea576020601954604051908152f35b50346104ea5760203660031901126104ea5761139f613042565b81546001600160a01b0391906113b890831633146132c3565b166001600160601b0360a01b601554161760155580f35b50346104ea5760803660031901126104ea576113e9613042565b6001600160401b03919060243583811161150857366023820112156115085780600401359384116115085760248101906024369160c087020101116115085782546001600160a01b0392839161144290831633146132c3565b1690818452602092602184526040852091855b87811061147b578660238787835260228152604435604084205552606435604082205580f35b8061149261148c6001938b866136c0565b866136f1565b6114a860406114a2838c876136c0565b016136e4565b156114b4575b01611455565b836114ca886114c4848d886136c0565b016136d0565b16868952601f88526114e160408a209182546132a0565b9055836114f3886114c4848d886136c0565b16611501601e9182546132a0565b90556114ae565b8280fd5b50346104ea5760203660031901126104ea57611526613042565b81546001600160a01b03919061153f90831633146132c3565b166001600160601b0360a01b601154161760115580f35b50346104ea57806003193601126104ea57546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea57600435906003548210156104ea5760206115a883613151565b90549060031b1c604051908152f35b50346104ea57806003193601126104ea576020601754604051908152f35b50346104ea5760403660031901126104ea576107946115f2613042565b82546001600160a01b039061164d9060243590831633148015611653575b611619906131f3565b61162284613dc6565b91829161162e86613df0565b94861688526024602052806040892055601f60205260408820546132a0565b93613e2e565b5060325483163314611610565b50346104ea57806003193601126104ea576020601c54604051908152f35b50346104ea57806003193601126104ea576014546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea576013546040516001600160a01b039091168152602090f35b50346104ea5760203660031901126104ea576116ea613042565b81546001600160a01b03919061170390831633146132c3565b166001600160601b0360a01b601254161760125580f35b50346104ea5760203660031901126104ea5760043590602e548210156104ea576113636117468361311a565b50546040805164ffffffffff8316815260289290921c6001600160a01b0316602083015290918291820190565b50346104ea57806003193601126104ea576020602854604051908152f35b50346104ea57806003193601126104ea5760206105ea6137f2565b50346104ea5760203660031901126104ea576117c6613042565b6001600160a01b03168152602160205260408120805490919081816117f1575b602083604051908152f35b600019820191821161185957505b611809818461306c565b5060ff815460c81c161561183e575b5080156118325761182b611809916137e5565b90506117ff565b506020915038806117e6565b9161184c6118529293615a27565b906132a0565b9038611818565b634e487b7160e01b81526011600452602490fd5b50346104ea5760803660031901126104ea576004356001600160401b038111610e815761189e9036906004016131ad565b6024356001600160401b0381116107f2576118bd9036906004016131ad565b6044939193356001600160401b03811161056e576118df9036906004016131ad565b6064959195356001600160401b038111611b86576119019036906004016131ad565b92909561191860018060a01b038a541633146132c3565b848103611b4157828103611b0457838103611abf57885b81811061193a578980f35b6119458183896136b0565b356001600160a01b0381168103611abb5786821015611aa7578160051b840135601e1985360301811215611aa35784016001600160401b03813511611aa35760c081350236036020820113611aa3576001600160a01b0382168c52602160205260408c20908c5b8d82358210611a035750505050906001916119c882878d6136b0565b35838060a01b0382168d52602260205260408d20556119e882888c6136b0565b3590838060a01b03168c52602360205260408c20550161192f565b90600191611a1961148c838635602088016136c0565b611a2d60406114a2848735602089016136c0565b15611a3a575b50016119ac565b611a726040848060a01b03611a5860206114c4878a35838c016136c0565b1692858060a01b0389168152601f602052209182546132a0565b9055818060a01b03611a8d60206114c48487358389016136c0565b16611a9b601e9182546132a0565b90558e611a33565b8b80fd5b634e487b7160e01b8b52603260045260248bfd5b8a80fd5b60405162461bcd60e51b815260206004820152601760248201527f4c656e677468206d69736d61746368207669727475616c0000000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152601560248201527413195b99dd1a081b5a5cdb585d18da081d1bdd185b605a1b6044820152606490fd5b60405162461bcd60e51b815260206004820152601760248201527f4c656e677468206d69736d61746368207265636f7264730000000000000000006044820152606490fd5b8780fd5b50346104ea5760203660031901126104ea578054611bbc90336001600160a01b039182161490811561062957506131f3565b600435602a5580f35b50346104ea57806003193601126104ea576020602b54604051908152f35b50346104ea57806003193601126104ea576020602754604051908152f35b50346104ea5760203660031901126104ea57805460043590611c3790336001600160a01b039182161490811561062957506131f3565b60648111611c455760305580f35b60405162461bcd60e51b815260206004820152600c60248201526b0526174696f203c3d203130360a41b6044820152606490fd5b50346104ea5760203660031901126104ea57600435906026548210156104ea57611363611746836130e3565b50346104ea57806003193601126104ea5760206105ea6135c3565b50346104ea57602090816003193601126104ea5760043591611ce3333214613463565b33825260218152611cf7836040842061306c565b50546001600160a01b03939084611d0c6133b4565b9160281c16116124835733835260218252611d2a816040852061306c565b509384549464ffffffffff95611d42878216426133a7565b60ff8260d01c16600581101561246f57600a0154116124325760ff8160c81c1661240757829060281c1692611d7984601e546133a7565b601e55611d8884602f546132a0565b9182602f55611d95614441565b884216938482528588830191168152602e5499600160401b8b10156123f357611dc660019b60018101602e5561311a565b9390936123df575183549251600160281b600160c81b0390891660281b166001600160c81b03199093169116600160281b600160c81b03191617179055338752601f865260408720611e198682546133a7565b9055866040518681527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef883392a36001818101889055815460ff60c81b1916600160c81b1790915533875285805260408720549081019081106110b0573387528580526040872055604051918683528583015260408201527f48711929c842404f1d698f9525c36a831e8224d0bac22977e91904b3fe9f656460603392a280600f5416926040516370a0823160e01b9485825230600483015260249483838781855afa92831561220a5788936123b0575b506040519187835230600484015273d98492fdc4b1853051dc251638dda05fd2ea07889385848981885afa9182156123a5578a9261236e575b611f74945060405190611f3582612f46565b6002825260403689840137611f498261326f565b5285611f548261327c565b52604051634401edf760e11b815294859142903090858860048701614925565b03938a817310ed43c718714eb63d5aa57b78b54704e256024e968183895af180156123125761234c575b5086600f541690868a8a6040518095819382523060048301525afa918215612312578b9261231d575b50604051998a523060048b0152868a8a81895afa998a15612312578b9a6122e1575b50611ffe9291611ff8916133a7565b986133a7565b818082116122d0575b50506010546004805460405163195006c760e11b815233928101929092526024820152908990829060449082908a165afa9081156122c557908a918a916122a3575b509089905b612224575b50508798509087929161208461206833613dc6565b61207133613df0565b9061207c84836132a0565b908033613e2e565b809160305480612138575b505050806120df575b50505050600f541690813b156120da57839260405194859384926337470d6f60e21b845260048401525af180156104ed576120d1575080f35b61079490612f18565b505050fd5b60405163a9059cbb60e01b8152336004820152602481019190915291839183916044918391905af180156105795761211a575b808691612098565b8161213092903d10610522576105128183612f61565b503880612112565b60648111156122195750606461214f815b84613355565b0491821561208f57829550612166929193506133a7565b906040519361217485612f46565b6002855260403687870137836121898661326f565b5286600f54166121988661327c565b52813b15612215578991888380936121d6604051998a9687958694635c11d79560e01b8652600486015284015260a0604484015260a4830190614146565b33606483015242608483015203925af192831561220a5788936121fb575b808061208f565b61220490612f18565b386121f4565b6040513d8a823e3d90fd5b8980fd5b61214f606491612149565b815181101561229e57908a8261228f6022898e8c61224387998961328c565b51169061224f82613dc6565b9061225983613df0565b9485948483525260408120908b82541015600014612297575061227d8b82546133a7565b90555b61228982613dc6565b91613e2e565b01909161204e565b9055612280565b612053565b6122bf91503d808c833e6122b78183612f61565b81019061446a565b38612049565b6040513d8b823e3d90fd5b6122d9916133a7565b503881612007565b9099508681813d831161230b575b6122f98183612f61565b81010312611abb575198611ffe611fe9565b503d6122ef565b6040513d8d823e3d90fd5b9091508681813d8311612345575b6123358183612f61565b81010312611abb57519038611fc7565b503d61232b565b612367903d808d833e61235f8183612f61565b8101906148ac565b5038611f9e565b92939091508581813d831161239e575b6123888183612f61565b810103126122155790611f749392915191611f23565b503d61237e565b6040513d8c823e3d90fd5b9092508381813d83116123d8575b6123c88183612f61565b81010312611b8657519138611eea565b503d6123be565b634e487b7160e01b8b5260048b905260248bfd5b634e487b7160e01b8a52604160045260248afd5b60405162461bcd60e51b8152600481018690526003602482015262616c7760e81b6044820152606490fd5b60405162461bcd60e51b8152600481018690526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b6044820152606490fd5b634e487b7160e01b88526032600452602488fd5b60405162461bcd60e51b815260048101839052600b60248201526a11185a5b1e481b1a5b5a5d60aa1b6044820152606490fd5b50346104ea5760203660031901126104ea57600435906001548210156104ea5760206108f4836130be565b50346104ea57806003193601126104ea576020602954604051908152f35b50346104ea5760203660031901126104ea57602061253e61251e613042565b6001600160a01b03166000908152601f6020526040902054603154111590565b6040519015158152f35b50346104ea57806003193601126104ea576020603154604051908152f35b50346104ea57806003193601126104ea576032546040516001600160a01b039091168152602090f35b50346104ea57806003193601126104ea576020602f54604051908152f35b50346104ea5760203660031901126104ea576125c7613042565b81546001600160a01b0391906125e090831633146132c3565b166001600160601b0360a01b601454161760145580f35b50346104ea5760803660031901126104ea576004356001600160a01b03602435818116808203610d015761262961309e565b92612635333214613463565b338652602160205261265d61264d866040892061306c565b5054918260281c16831015613495565b60058410156126fa5760ff84600a01549160d01c1660058110156126e6576107949594926126986126c495936126a093600a015411156134d7565b610c776135c3565b600460ff83166126b282821115613554565b146126c9575b61130360443582614183565b61495e565b33865260256020526126e160ff604088205416613586565b6126b8565b634e487b7160e01b87526032600452602487fd5b634e487b7160e01b86526032600452602486fd5b50346104ea57806003193601126104ea5760206105ea6133b4565b50346104ea5760203660031901126104ea57612743613042565b81546001600160a01b03919061275c90831633146132c3565b166001600160601b0360a01b601354161760135580f35b50346104ea57602080600319360112610e81576001600160401b03906004358281116107f2576127a7903690600401612f99565b83546127c790336001600160a01b039182161490811561062957506131f3565b6127d46008825114613316565b8051928311610e6d57600160401b8311610e6d576003548360035580841061283f575b506020019060038452835b83811061280d578480f35b82517fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b82015591810191600101612802565b837fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b91820191015b81811061287457506127f7565b858155600101612867565b50346104ea5760203660031901126104ea576020906040906001600160a01b036128a7613042565b168152602383522054604051908152f35b50346104ea57806003193601126104ea576020601d54604051908152f35b50346104ea57806003193601126104ea576020602c54604051908152f35b50346104ea57602080600319360112610e81576001600160401b03906004358281116107f257612928903690600401612f99565b835461294890336001600160a01b039182161490811561062957506131f3565b6129556008825114613316565b8051928311610e6d57600160401b8311610e6d57600254836002558084106129ae575b506020019060028452835b83811061298e578480f35b8251600080516020615e7f83398151915282015591810191600101612983565b83600080516020615e7f83398151915291820191015b8181106129d15750612978565b8581556001016129c4565b50346104ea5760403660031901126104ea57806020612a506129fc613042565b83546001600160a01b0390612a1490821633146132c3565b600f5460405163a9059cbb60e01b81526001600160a01b0390931660048401526024803590840152919485939190921691839182906044820190565b03925af180156104ed57610a2f575080f35b50346104ea5760403660031901126104ea576004356001600160401b038111610e815736602382011215610e8157806004013590612a9f82612f82565b90612aad6040519283612f61565b8282526020926024602084019160051b8301019136831161056e576024859101915b838310612b555750505050602435918215158093036107f25783546001600160a01b0390811633148015612b48575b612b0a909493946131f3565b60ff859316925b8451811015612b44578082612b286001938861328c565b511687526025845260408720805460ff19168617905501612b11565b8580f35b5060325481163314612afe565b8190612b6084613058565b8152019101908490612acf565b50346104ea57806003193601126104ea576020602a54604051908152f35b50346104ea5760203660031901126104ea576020906040906001600160a01b03612bb3613042565b168152602183522054604051908152f35b50346104ea57806003193601126104ea57602060405160128152f35b50346104ea5760203660031901126104ea576020906040906001600160a01b03612c08613042565b168152601f83522054604051908152f35b50346104ea57806003193601126104ea576020602d54604051908152f35b50346104ea57806003193601126104ea576020601e54604051908152f35b50346104ea5760403660031901126104ea57610794612c72613042565b8254602435916001600160a01b0391821633148015612ccb575b612c95906131f3565b612c9e81613dc6565b612289612caa83613df0565b948594841688526023602052806040892055602260205260408820546132a0565b5060325482163314612c8c565b50346104ea5760403660031901126104ea57612cf2613042565b6001600160a01b039081168252602160205260408220805460243593908410156104ea575060c092612d239161306c565b5080549060ff60026001830154920154926040519464ffffffffff821686528160281c166020860152818160c81c161515604086015260d01c166060840152608083015260a0820152f35b50346104ea57806003193601126104ea57611363604051612d8e81612f2b565b600a81526905374616b6564204f53560b41b602082015260405191829182612ff9565b50346104ea5760403660031901126104ea576001600160401b0360043581811161150857612de3903690600401612f99565b9060243590811161150857612dfc903690600401612f99565b8254612e1c90336001600160a01b039182161490811561062957506131f3565b600590612e2c6005845114613230565b612e396005825114613230565b835b828110612e46578480f35b80612e536001928661328c565b5181600a0155612e63818461328c565b518185015501612e3b565b50346104ea57612e7d36612ec9565b92612e9e60018060a09594951b0380875416331490811561062957506131f3565b601a55601b55601c55601d5580f35b905034610e815781600319360112610e81576020906004548152f35b60809060031901126105af5760043590602435906044359060643590565b60c081019081106001600160401b03821117612f0257604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b038111612f0257604052565b604081019081106001600160401b03821117612f0257604052565b606081019081106001600160401b03821117612f0257604052565b90601f801991011681019081106001600160401b03821117612f0257604052565b6001600160401b038111612f025760051b60200190565b9080601f830112156105af576020908235612fb381612f82565b93612fc16040519586612f61565b81855260208086019260051b8201019283116105af57602001905b828210612fea575050505090565b81358152908301908301612fdc565b6020808252825181830181905290939260005b82811061302e57505060409293506000838284010152601f8019910116010190565b81810186015184820160400152850161300c565b600435906001600160a01b03821682036105af57565b35906001600160a01b03821682036105af57565b8054821015613088576000526003602060002091020190600090565b634e487b7160e01b600052603260045260246000fd5b6064359060ff821682036105af57565b6044359060ff821682036105af57565b600154811015613088576001600052600080516020615e9f8339815191520190600090565b6026548110156130885760266000527f744a2cf8fd7008e3d53b67916e73460df9fa5214e3ef23dd4259ca09493a35940190600090565b602e5481101561308857602e6000527f37fa166cbdbfbb1561ccd9ea985ec0218b5e68502e230525f544285b2bdf3d7e0190600090565b6003548110156130885760036000527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b0190600090565b600254811015613088576002600052600080516020615e7f8339815191520190600090565b9181601f840112156105af578235916001600160401b0383116105af576020808501948460051b0101116105af57565b60409060031901126105af576004359060243590565b156131fa57565b60405162461bcd60e51b815260206004820152600e60248201526d139bdd08185d5d1a1bdc9a5e995960921b6044820152606490fd5b1561323757565b60405162461bcd60e51b815260206004820152601060248201526f4c656e677468206d757374206265203560801b6044820152606490fd5b8051156130885760200190565b8051600110156130885760400190565b80518210156130885760209160051b010190565b919082018092116132ad57565b634e487b7160e01b600052601160045260246000fd5b156132ca57565b60405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606490fd5b908160209103126105af575180151581036105af5790565b1561331d57565b60405162461bcd60e51b815260206004820152601060248201526f098cadccee8d040daeae6e840c4ca40760831b6044820152606490fd5b818102929181159184041417156132ad57565b908160209103126105af57516001600160701b03811681036105af5790565b8115613391570490565b634e487b7160e01b600052601260045260246000fd5b919082039182116132ad57565b6133bc613905565b600f54604051631a7abd9760e01b815290602090829060049082906001600160a01b03165afa908115613457576127109161340c91600091613428575b506001600160701b03602d549116613355565b049081811061341c575050600090565b613425916133a7565b90565b61344a915060203d602011613450575b6134428183612f61565b810190613368565b386133f9565b503d613438565b6040513d6000823e3d90fd5b1561346a57565b60405162461bcd60e51b8152602060048201526003602482015262454f4160e81b6044820152606490fd5b1561349c57565b60405162461bcd60e51b8152602060048201526013602482015272125b9cdd59999a58da595b9d08185b5bdd5b9d606a1b6044820152606490fd5b156134de57565b60405162461bcd60e51b815260206004820152601560248201527424b739bab33334b1b4b2b73a10323ab930ba34b7b760591b6044820152606490fd5b1561352257565b60405162461bcd60e51b815260206004820152600a60248201526913dd995c88131a5b5a5d60b21b6044820152606490fd5b1561355b57565b60405162461bcd60e51b81526020600482015260036024820152620f0f4d60ea1b6044820152606490fd5b1561358d57565b60405162461bcd60e51b815260206004820152600e60248201526d13db9b1e481dda1a5d195b1a5cdd60921b6044820152606490fd5b6135cb6137f2565b600f54604051631a7abd9760e01b815290602090829060049082906001600160a01b03165afa8015613457576001600160701b0391600091613691575b50169061271061361a60295484613355565b04908181111561366e5750506000905b602a5490818110156136645761363f916133a7565b602b548082111561365d57505b80821015613658575090565b905090565b905061364c565b5050602b5461364c565b613677916133a7565b6028548082101561368a57505b9061362a565b9050613684565b6136aa915060203d602011613450576134428183612f61565b38613608565b91908110156130885760051b0190565b91908110156130885760c0020190565b356001600160a01b03811681036105af5790565b3580151581036105af5790565b8054600160401b811015612f025761370e9160018201815561306c565b9190916137cf57803564ffffffffff81168091036105af57825464ffffffffff1916178255613768613742602083016136d0565b8354600160281b600160c81b03191660289190911b600160281b600160c81b0316178355565b613791613777604083016136e4565b835460ff60c81b191690151560c81b60ff60c81b16178355565b606081013560ff811681036105af57825460ff60d01b191660d09190911b60ff60d01b1617825560029060a090608081013560018501550135910155565b634e487b7160e01b600052600060045260246000fd5b80156132ad576000190190565b602654801561386e57613807602754426133a7565b601e549091819060001981019081116132ad575b613824816130e3565b505464ffffffffff811685111561384157505061342592506133a7565b60281c6001600160a01b0316925080156138635761385e906137e5565b61381b565b5061342592506133a7565b50600090565b6040519061388182612ee7565b8160a06000918281528260208201528260408201528260608201528260808201520152565b906138b082612f82565b6138bd6040519182612f61565b82815280926138ce601f1991612f82565b019060005b8281106138df57505050565b6020906138ea613874565b828285010152016138d3565b60001981146132ad5760010190565b602e54801561386e5761391a602c54426133a7565b9060009060001981019081116132ad575b6139348161311a565b50548364ffffffffff8216106139685750801561395957613954906137e5565b61392b565b5061342591505b602f546133a7565b613425935060281c6001600160a01b031691506139609050565b6000600154918260071015613bf7577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfd548110613c0b575050506008905b60006002908154928360071015613bf7578282527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad5548110613a17575050505060085b60ff811660ff831610600014613658575090565b8360061015613bf7578282527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad4548110613a5657505050506007613a03565b8360051015613bf7578282527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad3548110613a9557505050506006613a03565b60049380851015613be4578383527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad2548210613ad75750505050506005613a03565b8060031015613be4578383527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad1548210613b145750505050613a03565b8084959293941015613bd1578484527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ad0548310613b5857505050505060035b613a03565b8060011015613bd1578484527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5acf548310613b955750505050613a03565b9391929315613bbe57508252600080516020615e7f8339815191525411613b5357506001613a03565b634e487b7160e01b845260329052602483fd5b634e487b7160e01b845260328252602484fd5b634e487b7160e01b835260328552602483fd5b634e487b7160e01b82526032600452602482fd5b8260061015613bf7577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfc548110613c47575050506007906139c0565b8260051015613bf7577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfb548110613c83575050506006906139c0565b60049280841015613db3577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cfa548210613cc257505050506005906139c0565b8060031015613db3577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf9548210613cfc57505050906139c0565b80600295949293951015613da0577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf8548310613d3f57506003935050505b6139c0565b8060011015613da0577fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf7548310613d7c57506002935050506139c0565b15613bbe5750600080516020615e9f8339815191525411613d3a57600191506139c0565b634e487b7160e01b855260328252602485fd5b634e487b7160e01b835260328452602483fd5b60018060a01b031660005260226020526134256040600020546023602052604060002054906132a0565b60018060a01b0316600052601f6020526134256040600020546024602052604060002054906132a0565b51906001600160a01b03821682036105af57565b92613e3e90613e44939592613982565b93613982565b9160ff80600094169116818114613eb05760088103613ffe5750613e696019546137e5565b6019556015546001600160a01b039081169081613fa6575b50505b60088103613f115750613e986019546138f6565b6019556015546001600160a01b039081169182613eb6575b50505050565b823b156107f25790604484928360405195869485936311f9fbc960e21b8552166004840152670de0b6b3a764000060248401525af180156104ed57613efd575b8080613eb0565b613f078291612f18565b6104ea5780613ef6565b60078103613f425750613f256018546138f6565b6018556014546001600160a01b039081169182613eb65750505050565b60068103613f735750613f566017546138f6565b6017556013546001600160a01b039081169182613eb65750505050565b600514613f7e575050565b613f896016546138f6565b6016556012546001600160a01b039081169182613eb65750505050565b813b15610d0157849160448392604051948593849263f3fef3a360e01b845289166004840152670de0b6b3a764000060248401525af180156105bb5790849115613e8157613ff390612f18565b611508578238613e81565b6007810361408a57506140126018546137e5565b6018556014546001600160a01b039081169081614032575b50505b613e84565b813b15610d0157849160448392604051948593849263f3fef3a360e01b845289166004840152670de0b6b3a764000060248401525af180156105bb579084911561402a5761407f90612f18565b61150857823861402a565b600681036140bc575061409e6017546137e5565b6017556013546001600160a01b039081169081614032575050613e84565b60050361402d576140ce6016546137e5565b6016556012546001600160a01b0390811690816140ec575050613e84565b813b15610d0157849160448392604051948593849263f3fef3a360e01b845289166004840152670de0b6b3a764000060248401525af180156105bb57614133575b8061402a565b61413f90939193612f18565b913861412d565b90815180825260208080930193019160005b828110614166575050505090565b83516001600160a01b031685529381019392810192600101614158565b604080516323b872dd60e01b81523360048201523060248201526001600160a01b038381166044830152600094602094909273d98492fdc4b1853051dc251638dda05fd2ea0788919086816064818b875af180156144375761441a575b508480516141ed81612f46565b60028152873691013784519561420287612f46565b60028752853682890137826142168861326f565b5283600f541693846142278961327c565b5286519282846024816370a0823160e01b998a82523060048301525afa9384156143e1578a946143eb575b5060011c60016001609f1b0316977310ed43c718714eb63d5aa57b78b54704e256024e96873b15611abb578a908a6142af8b519485938493635c11d79560e01b85526004850152602484015260a0604484015260a4830190614146565b3060648301524260848301520381838b5af180156143e1576143ce575b50600f54169386519081523060048201528181602481885afa9182156143c4579089939291849261438b575b50509461430c6101049493926060976133a7565b8751988996879562e8e33760e81b875260048701526024860152604485015260648401528160848401528160a48401528160c48401524260e48401525af1908115614382575061435a575050565b606090813d831161437b575b6143708183612f61565b810103126104ea5750565b503d614366565b513d84823e3d90fd5b819594508092503d83116143bd575b6143a48183612f61565b810103126105af5791519091879161430c6101046142f8565b503d61439a565b87513d8b823e3d90fd5b6143da90999199612f18565b97386142cc565b88513d8c823e3d90fd5b9093508281813d8311614413575b6144038183612f61565b8101031261221557519238614252565b503d6143f9565b61443090873d8911610522576105128183612f61565b50386141e0565b86513d8a823e3d90fd5b60405190604082018281106001600160401b03821117612f025760405260006020838281520152565b60209081818403126105af578051906001600160401b0382116105af57019180601f840112156105af57825161449f81612f82565b936144ad6040519586612f61565b818552838086019260051b8201019283116105af578301905b8282106144d4575050505090565b8380916144e084613e1a565b8152019101906144c6565b9192909260018060a01b03908160105416926040938451633bb1db8160e21b8152602081602481888b16958660048301525afa9081156148a157600091614882575b50156148555761453b614441565b9664ffffffffff938442169889815286601e54166020820190815260265491600160401b9283811015612f025780600161457892016026556130e3565b6137cf57905181549251600160281b600160c81b03908b1660281b166001600160c81b0319909316908916600160281b600160c81b0319161791909117905564ffffffffff19846000526021602052888060002091898354966145d9613874565b9e8f52169c8d938460208301528382019560008752606083019560ff8916875261462760a08501968b885261461083601e546132a0565b601e558c600052601f6020526000209182546132a0565b9055815490811015612f02576146429160018201815561306c565b9590956137cf57815186546020840151600160281b600160c81b03908f1660281b169c909116931692909217600160281b600160c81b031916999099178455614714986002936080926146cb9160ff916146b19051895460ff60c81b191690151560c81b60ff60c81b16178955565b51875460ff60d01b1916911660d01b60ff60d01b16178655565b015160018401555191015560105460048054895163195006c760e11b81526001600160a01b038c1692810192909252602482015295600091879190891690829081906044820190565b03915afa94851561484a5760009561482d575b5060005b855181101561478657806147808b8a8a6147476001968c61328c565b511661475281613dc6565b61228961475e83613df0565b9485948460005260226020526000206147788282546132a0565b9055826132a0565b0161472b565b5094509491969250946147b89061479c81613dc6565b906147a681613df0565b91806147b287856133a7565b92613e2e565b8460007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208451868152a36005831015613088577f9cfd25589d1eb8ad71e342a86a8524e83522e3936c0803048c08f6d9ad974f4093608093600a01549180519384524260208501528301526060820152a2565b6148439195503d806000833e6122b78183612f61565b9338614727565b87513d6000823e3d90fd5b845162461bcd60e51b81526020600482015260066024820152650848589a5b9960d21b6044820152606490fd5b61489b915060203d602011610522576105128183612f61565b3861452d565b86513d6000823e3d90fd5b60209081818403126105af578051906001600160401b0382116105af57019180601f840112156105af5782516148e181612f82565b936148ef6040519586612f61565b818552838086019260051b8201019283116105af578301905b828210614916575050505090565b81518152908301908301614908565b919260809361494a92979695978452602084015260a0604084015260a0830190614146565b6001600160a01b0390951660608201520152565b9060003381526021602052614976836040832061306c565b509182549364ffffffffff9061498e828716426133a7565b60ff8760d01c1660058110156126fa57600a0154116159ea5760ff8660c81c166159bf57601e546149cd90602888901c6001600160a01b0316906133a7565b601e55338452601f6020526040842080546149f690602889901c6001600160a01b0316906133a7565b90558360405160018060a01b038860281c1681527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60203392a3614a3985615a27565b6001808701829055865460ff60c81b1916600160c81b17909655338552602080526040852054909581019081106159ab57338552602080526040852055604051918583524216602083015260408201527f48711929c842404f1d698f9525c36a831e8224d0bac22977e91904b3fe9f656460603392a2600f546040516370a0823160e01b815230600482015293906001600160a01b0316602085602481845afa9485156105bb578495615977575b506040516370a0823160e01b81523060048201529060208260248173d98492fdc4b1853051dc251638dda05fd2ea07885afa91821561052957908591829361593e575b50614b93929360405191614b3d83612f46565b600283526040366020850137614b528361326f565b5273d98492fdc4b1853051dc251638dda05fd2ea0788614b718361327c565b52604051634401edf760e11b81529384928392429130918c9060048701614925565b0381837310ed43c718714eb63d5aa57b78b54704e256024e5af180156105bb57615924575b50600f546040516370a0823160e01b81523060048201526001600160a01b039091169190602081602481865afa9081156105295785916158f2575b506040516370a0823160e01b81523060048201529560208760248173d98492fdc4b1853051dc251638dda05fd2ea07885afa9687156105795786976158bc575b5091614c47614c4d92614ca39695946133a7565b966133a7565b849190602888901c6001600160a01b0316811161589a575b506010546004805460405163195006c760e11b81523392810192909252602482015294869186916001600160a01b0390911690829081906044820190565b03915afa93841561052957859461587e575b5081614fa3575b5050825b8251811015614d4c57600190614d3f6001600160a01b03614ce1838761328c565b5116614cec81613dc6565b614cf582613df0565b918291818a526022806020528a8d60408220908a8060a01b039060281c1681541015600014614d45575083905260205260408a2061227d8d898060a01b039060281c1682546133a7565b01614cc0565b5550612280565b50939050919091614d80614d5f33613dc6565b614d6833613df0565b9061207c602885901c6001600160a01b0316836132a0565b602881901c6001600160a01b0316908380614f98575b614e58575b5080614df5575b50600f546001600160a01b031690813b156115085782916024839260405194859384926337470d6f60e21b845260048401525af180156104ed57614de4575050565b614dee8291612f18565b6104ea5750565b60405163a9059cbb60e01b815233600482015260248101919091526020816044818673d98492fdc4b1853051dc251638dda05fd2ea07885af180156107e75715614da257614e519060203d602011610522576105128183612f61565b5038614da2565b6030546064811115614f8d57506064614e7f815b602884901c6001600160a01b0316613355565b049081614e8d575b50614d9b565b909150614ea790829060281c6001600160a01b03166133a7565b9060405190614eb582612f46565b60028252604036602084013773d98492fdc4b1853051dc251638dda05fd2ea0788614edf8361326f565b52600f546001600160a01b0316614ef58361327c565b527310ed43c718714eb63d5aa57b78b54704e256024e3b15610d0157614f459185916040519384928392635c11d79560e01b8452600484015284602484015260a0604484015260a4830190614146565b3360648301524260848301520381837310ed43c718714eb63d5aa57b78b54704e256024e5af180156105bb5790849115614e8757614f8290612f18565b611508578238614e87565b614e7f606491614e6c565b506030541515614d96565b614fca614fc1614fb8601a54601b54906132a0565b601c54906132a0565b601d54906132a0565b906064614fd78385613355565b046003548060001981011161586a576064615008614ffb61500f9360001901613151565b90549060031b1c87613355565b04826132a0565b9161501a83866133a7565b61502481856132a0565b9182615035575b5050505050614cbc565b6040519061504282612f46565b60028252604036602084013773d98492fdc4b1853051dc251638dda05fd2ea078861506c8361326f565b52806150778361327c565b5260405163d06ca61f60e01b8152846004820152604060248201528b81806150a26044820187614146565b03817310ed43c718714eb63d5aa57b78b54704e256024e5afa9081156157ea57906150d4918d91615850575b5061327c565b519081605a810204605a148215171561583c57906020602495949392604051968780926370a0823160e01b82523060048301525afa9485156157ea578c95615808575b507310ed43c718714eb63d5aa57b78b54704e256024e3b15611aa35761515f918c916040519384928392635c11d79560e01b845242916064605a309302048a60048701614925565b0381837310ed43c718714eb63d5aa57b78b54704e256024e5af18015612312576157f5575b50600f546040516370a0823160e01b81523060048201526001600160a01b0390911693602082602481885afa80156157ea578c906157b6575b6151c792506133a7565b91826151d4575b5061502b565b6151e16151e69284613355565b613387565b9182615754575b50906151f8916133a7565b9182615207575b8080806151ce565b6151e16152149284613355565b918061523b575b50615231929161522a916133a7565b9084615b01565b38808080806151ff565b601654151580615740575b1561572f576012546001600160a01b03165b615268826151e1601a5487613355565b600f5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529293929091602091839160449183918f91165af180156123a557615710575b506012546001600160a01b03908116911681146156a2575b5060175415158061568e575b1561567c576013546001600160a01b0316905b6152f5836151e1601b5488613355565b600f5460405163a9059cbb60e01b81526001600160a01b038086166004830152602482018490529294929091602091839116818e816044810103925af180156123125761565d575b506013546001600160a01b03908116911681146155ef575b5090615360916132a0565b6018541515806155db575b156155c5576014546001600160a01b03169161538e905b6151e1601c5487613355565b600f5460405163a9059cbb60e01b81526001600160a01b038581166004830152602482018490529294929091602091839160449183918f91165af180156123a5576155a6575b506014546001600160a01b0390811691168114615538575b50906153f7916132a0565b601954151580615524575b1561550e576015546001600160a01b03169061541f905b846133a7565b600f5460405163a9059cbb60e01b81526001600160a01b038481166004830152602482018490529293929091602091839160449183918e91165af180156122c5576154ef575b506015546001600160a01b0390811691168114615483575b5061521b565b600f546001600160a01b0316813b156154eb5760405163a9fc507b60e01b81526001600160a01b03919091166004820152602481019290925287908290604490829084905af1801561085e579087911561547d576154e090612f18565b61056e57853861547d565b8880fd5b6155079060203d602011610522576105128183612f61565b5038615465565b6011546001600160a01b03169061541f90615419565b506015546001600160a01b03161515615402565b600f546001600160a01b0316813b156122155760405163a9fc507b60e01b81526001600160a01b03919091166004820152602481018490529089908290604490829084905af180156122c557908991615592575b506153ec565b61559b90612f18565b611b8657873861558c565b6155be9060203d602011610522576105128183612f61565b50386153d4565b6011546001600160a01b03169161538e90615382565b506014546001600160a01b0316151561536b565b600f546001600160a01b0316813b15611abb5760405163a9fc507b60e01b81526001600160a01b0391909116600482015260248101849052908a908290604490829084905af180156123a557908a91615649575b50615355565b61565290612f18565b6154eb578838615643565b6156759060203d602011610522576105128183612f61565b503861533d565b6011546001600160a01b0316906152e5565b506013546001600160a01b031615156152d2565b600f546001600160a01b0316813b156122155760405163a9fc507b60e01b81526001600160a01b03919091166004820152602481018390529089908290604490829084905af180156122c5579089916156fc575b506152c6565b61570590612f18565b611b865787386156f6565b6157289060203d602011610522576105128183612f61565b50386152ae565b6011546001600160a01b0316615258565b506012546001600160a01b03161515615246565b60405163a9059cbb60e01b81523360048201526024810184905290602090829060449082908e905af180156123a557906151f8939291615797575b5090916151ed565b6157af9060203d602011610522576105128183612f61565b503861578f565b506020823d6020116157e2575b816157d060209383612f61565b810103126105af576151c791516151bd565b3d91506157c3565b6040513d8e823e3d90fd5b615801909a919a612f18565b9838615184565b9094506020813d602011615834575b8161582460209383612f61565b81010312611aa357519338615117565b3d9150615817565b634e487b7160e01b8c52601160045260248cfd5b61586491503d808f833e61235f8183612f61565b386150ce565b634e487b7160e01b88526011600452602488fd5b6158939194503d8087833e6122b78183612f61565b9238614cb5565b9091506158b590602888901c6001600160a01b0316906133a7565b9038614c65565b9096506020813d6020116158ea575b816158d860209383612f61565b8101031261056e575195614c47614c33565b3d91506158cb565b90506020813d60201161591c575b8161590d60209383612f61565b81010312610d01575138614bf3565b3d9150615900565b615937903d8086833e61235f8183612f61565b5038614bb8565b915091506020813d60201161596f575b8161595b60209383612f61565b81010312610d015751908490614b93614b2a565b3d915061594e565b9094506020813d6020116159a3575b8161599360209383612f61565b810103126107f257519338614ae7565b3d9150615986565b634e487b7160e01b85526011600452602485fd5b60405162461bcd60e51b8152602060048201526003602482015262616c7760e81b6044820152606490fd5b60405162461bcd60e51b8152602060048201526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b6044820152606490fd5b54602881901c6001600160a01b03169064ffffffffff80821642821603918183116132ad5760d01c60ff16916005831015613088578183600a0154168083831610600014615af95750905b81169182615a805750505090565b60050154939290915060018481841615615ae457647fffffffff905b9360011c1694855b615ab5575050613425929350615de8565b80615abf91615de8565b9485828216615ad3575b50811c9485615aa4565b615add9194615de8565b9285615ac9565b50647fffffffff670de0b6b3a7640000615a9c565b905090615a72565b91908115615de357600390600354600019908181019081116132ad57615b39615b2b606492613151565b90549060031b1c8094613355565b0415615d955760008060005b8751811015615d88576001600160a01b0380615b61838b61328c565b5116615b6c81613dc6565b6001600160a01b0382166000908152601f602052604090205460315491939111615d7d576000926001805490898201918213166159ab575b6000811215615d11575b505087858411615bc7575b505050506001905b01615b45565b6151e1615bdc8597615be294959799966133a7565b8c613355565b600f546040805163a9059cbb60e01b81526001600160a01b03969096166004870152602486018390529194602093909291849184916044918391600091165af1908115615d07575090615c3e94939291615ce9575b50506132a0565b9184821015615c505738808087615bb9565b50509394505050505b818110615c64575050565b600f54601154615cbf936020936001600160a01b039283169390921691615c8a916133a7565b60405163a9059cbb60e01b81526001600160a01b03909316600484015260248301529092839190829060009082906044820190565b03925af1801561345757615cd1575b50565b615cce9060203d602011610522576105128183612f61565b81615cff92903d10610522576105128183612f61565b503880615c37565b513d6000823e3d90fd5b615d1a816130be565b9054908c1b1c821015615d2c85613df0565b8c615d3684613188565b9054911b1c111581615d75575b50615d5a57600160ff1b81146132ad578801615ba4565b9050615d67919350613151565b905490891b1c913880615bae565b905038615d43565b505050600190615bc1565b5050939450505050615c59565b5050600f5460115460405163a9059cbb60e01b81526001600160a01b03918216600482015260248101949094529293506020928492506044918391600091165af1801561345757615cd15750565b505050565b90919060001983820983820291828083109203918083039214615e6d57670de0b6b3a76400009081831015615e4f57947faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac1066994950990828211900360ee1b910360121c170290565b6044908660405191635173648d60e01b835260048301526024820152fd5b5050670de0b6b3a76400009004915056fe405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5aceb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6a2646970667358221220e046a944cbe48a8aa84e69d4c2efc8fa3ae2e62107076347c7abd993fcf84bdc64736f6c63430008160033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000008b74b65763f3fd7aa8b1b6a533bd0fb7b196448400000000000000000000000047166369d54914e61c1bbcbcf528bae2307212a7
-----Decoded View---------------
Arg [0] : REFERRAL_ (address): 0x8b74B65763f3fd7Aa8B1B6a533BD0Fb7b1964484
Arg [1] : marketingAddress_ (address): 0x47166369d54914e61C1BbCBCf528bae2307212A7
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000008b74b65763f3fd7aa8b1b6a533bd0fb7b1964484
Arg [1] : 00000000000000000000000047166369d54914e61c1bbcbcf528bae2307212a7
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.
Add Token to MetaMask (Web3)