BNB Price: $612.41 (-1.22%)
 

Overview

BNB Balance

BNB Smart Chain LogoBNB Smart Chain LogoBNB Smart Chain Logo0 BNB

BNB Value

$0.00

Token Holdings

More Info

Private Name Tags

TokenTracker

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Stake815860742026-02-16 16:31:0023 mins ago1771259460IN
0xB7dab22F...d401676D1
0 BNB0.000047810.06565
Unstake815857112026-02-16 16:28:1626 mins ago1771259296IN
0xB7dab22F...d401676D1
0 BNB0.000045460.06565
Stake815852722026-02-16 16:24:5929 mins ago1771259099IN
0xB7dab22F...d401676D1
0 BNB0.000059650.06565
Unstake815844012026-02-16 16:18:2736 mins ago1771258707IN
0xB7dab22F...d401676D1
0 BNB0.000063950.0663065
Unstake815829442026-02-16 16:07:3146 mins ago1771258051IN
0xB7dab22F...d401676D1
0 BNB0.000062920.06565
Stake815826902026-02-16 16:05:3748 mins ago1771257937IN
0xB7dab22F...d401676D1
0 BNB0.000057350.06565
Unstake815825852026-02-16 16:04:4949 mins ago1771257889IN
0xB7dab22F...d401676D1
0 BNB0.000064270.0663065
Stake815824162026-02-16 16:03:3350 mins ago1771257813IN
0xB7dab22F...d401676D1
0 BNB0.000060960.06849346
Unstake815823282026-02-16 16:02:5451 mins ago1771257774IN
0xB7dab22F...d401676D1
0 BNB0.000065010.06565
Stake815818772026-02-16 15:59:3154 mins ago1771257571IN
0xB7dab22F...d401676D1
0 BNB0.000063610.0663065
Stake815817572026-02-16 15:58:3755 mins ago1771257517IN
0xB7dab22F...d401676D1
0 BNB0.00005950.06565
Unstake815816632026-02-16 15:57:5456 mins ago1771257474IN
0xB7dab22F...d401676D1
0 BNB0.000066380.06565
Unstake815815972026-02-16 15:57:2557 mins ago1771257445IN
0xB7dab22F...d401676D1
0 BNB0.000066620.07086412
Stake815815442026-02-16 15:57:0157 mins ago1771257421IN
0xB7dab22F...d401676D1
0 BNB0.000059540.06565
Unstake815814452026-02-16 15:56:1658 mins ago1771257376IN
0xB7dab22F...d401676D1
0 BNB0.000102120.101
Unstake815811682026-02-16 15:54:121 hr ago1771257252IN
0xB7dab22F...d401676D1
0 BNB0.000060180.06565
Stake815810112026-02-16 15:53:011 hr ago1771257181IN
0xB7dab22F...d401676D1
0 BNB0.000060170.0663065
Unstake815808532026-02-16 15:51:501 hr ago1771257110IN
0xB7dab22F...d401676D1
0 BNB0.000066230.06565
Stake815806242026-02-16 15:50:071 hr ago1771257007IN
0xB7dab22F...d401676D1
0 BNB0.000090790.101
Unstake815805422026-02-16 15:49:301 hr ago1771256970IN
0xB7dab22F...d401676D1
0 BNB0.000070760.07102989
Stake815803752026-02-16 15:48:151 hr ago1771256895IN
0xB7dab22F...d401676D1
0 BNB0.000058450.06565
Unstake815802862026-02-16 15:47:351 hr ago1771256855IN
0xB7dab22F...d401676D1
0 BNB0.000065870.06696956
Stake815800912026-02-16 15:46:071 hr ago1771256767IN
0xB7dab22F...d401676D1
0 BNB0.000061790.06565
Stake815800522026-02-16 15:45:491 hr ago1771256749IN
0xB7dab22F...d401676D1
0 BNB0.000056340.0663065
Unstake815799892026-02-16 15:45:211 hr ago1771256721IN
0xB7dab22F...d401676D1
0 BNB0.000063420.06565
View all transactions

Parent Transaction Hash Block From To
View All Internal Transactions
Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Staking

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 41 : Staking.sol
// SPDX-License-Identifier: UNLICENSED
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 {IBY} from "./interface/IBY.sol";
import {IReferral} from "./interface/IReferral.sol";
import {ISharePool} from "./interface/ISharePool.sol";
import {Owned} from "solmate/src/auth/Owned.sol";
import {_USDT_ADDR, _ROUTER_ADDR, _BYB_ADDR, _DEV_ADDR, _MARKETING_ADDR, _PROFIT_ADDR, _ROOT_REFERRER} from "./Const.sol";

contract Staking is Owned {

    bool public isStarted; // Whether staking is enabled
    uint8 public maxLevels = 30; // Maximum referral levels
    uint32 public totalNodeCount; // Total number of nodes
    uint32 public activeNodeCount; // Number of currently active nodes

    uint256[3] stakingDays = [1 days, 15 days, 30 days]; // Staking periods
    uint256[3] rates = [
        1000000034670200000,
        1000000069236900000,
        1000000138062200000
    ]; // Staking interest rates
    uint256[6] TEAM_LEVEL = [
        0,
        10000 ether,
        50000 ether,
        100000 ether,
        500000 ether,
        1000000 ether
    ]; // Team performance levels

    uint256[6] public FREE_NODES = [
        0, // S0
        0, // S1
        70, // S2
        70, // S3
        70, // S4
        70 // S5
    ]; // Free node quota

    // User => Level => isAllocated
    mapping(address => mapping(uint256 => bool)) private freeNodeAllocated; // User node allocation mapping

    mapping(address => uint32[6]) public levelCounts; // Count of direct referrals at each level

    struct UserInfo {
        bool isPreacher; // Whether user is a preacher (staked 100U or more)
        uint32 freeNodeCount; // User's node count
        uint32 initNodeCount; // User's genesis node count
        uint32 preacherCount; // Count of direct referrals who are preachers (staked 100U or more)
        uint256 teamKPI; // User's team performance
        uint256 unstakingCount; // Count of user's unstaked records
    }
    mapping(address => UserInfo) public userInfo; // User information mapping

    struct Record {
        uint40 stakingTime; // Staking timestamp
        uint160 amount; // Staking amount (USDT)
        bool status; // Staking status, true if unstaked, false if active
        uint8 stakingType; // Staking type (0: 1 day, 1: 15 days, 2: 30 days)
    }
    mapping(address => Record[]) public stakingRecords; // User staking records mapping

    IUniswapV2Router02 constant ROUTER = IUniswapV2Router02(_ROUTER_ADDR);
    IERC20 constant USDT = IERC20(_USDT_ADDR);
    IERC20 constant BYB = IERC20(_BYB_ADDR);
    IBY public BY;
    IReferral public REFERRAL;
    ISharePool public SHARE_POOL;

    address marketingAddress;

    // Token attributes
    uint256 public totalSupply;
    uint8 public constant decimals = 18;
    string public constant name = "BYS";
    string public constant symbol = "BYS";
    mapping(address => uint256) public balances;

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Staked(
        address indexed user,
        uint256 amount,
        uint256 timestamp,
        uint256 stakingIndex,
        uint256 stakingTime
    );

    event Unstaked(
        address indexed user,
        uint256 reward,
        uint40 timestamp,
        uint256 stakingIndex
    );

    modifier onlyEOA() {
        require(tx.origin == msg.sender, "Not EOA");
        _;
    }

    constructor(
        address _referralAddress
    ) Owned(msg.sender) {
        REFERRAL = IReferral(_referralAddress);
        marketingAddress = _MARKETING_ADDR;
        USDT.approve(address(ROUTER), type(uint256).max);
    }

    function updateScore(address _user) private {
        UserInfo storage info = userInfo[_user];
        if((info.freeNodeCount + info.initNodeCount) == 0 || info.preacherCount < 10){
            return;
        }
        uint256 newScore = (info.freeNodeCount + info.initNodeCount) * (info.teamKPI + balances[_user]) / 1e18;
        SHARE_POOL.updateScore(_user, newScore);
    }

    function clearScore(address _user) private {
        SHARE_POOL.updateScore(_user, 0);
    }

    // Initialize genesis nodes, a total of 220, each can only be initialized once, and receive 500 BY tokens
    function initNodes(address[] calldata addresses) public onlyOwner {
        for (uint256 i; i < addresses.length; ++i) {
            require(userInfo[addresses[i]].initNodeCount == 0, "Already initialized");
            BY.transfer(addresses[i], 500 ether);
            userInfo[addresses[i]].initNodeCount = 1;
            totalNodeCount +=1;
        }
    }

    function start() external onlyOwner {
        isStarted = true;
    }

    function stop() external onlyOwner {
        isStarted = false;
    }

    function setMaxLevels(uint8 _maxLevels) external onlyOwner {
        maxLevels = _maxLevels;
    }

    function setByAddress(address _byAddress) external onlyOwner {
        BY = IBY(_byAddress);
        BY.approve(address(ROUTER), type(uint256).max);
    }

    function setSharePoolAddress(address _sharePoolAddress) external onlyOwner {
        SHARE_POOL = ISharePool(_sharePoolAddress);
    }

    function setReferralAddress(address _referralAddress) external onlyOwner {
        REFERRAL = IReferral(_referralAddress);
    }

    function setMarketingAddress(address _account) external onlyOwner {
        marketingAddress = _account;
    }

    // Dynamically calculate the user's maximum staking amount based on the USDT reserve in BY's liquidity pool
    function maxStakingAmount()
        public
        view
        returns (uint256 _maxStakingAmount)
    {
        uint112 reverseu = BY.getReserveUSDT();
        if (reverseu < 1000000 ether) {
            _maxStakingAmount = 1000 ether;
        } else if (reverseu < 3000000 ether) {
            _maxStakingAmount = 3000 ether;
        } else if (reverseu < 10000000 ether) {
            _maxStakingAmount = 5000 ether;
        } else if (reverseu < 20000000 ether) {
            _maxStakingAmount = 10000 ether;
        } else {
            _maxStakingAmount = 1000000000 ether;
        }
    }

    function stakeWithInviter(
        uint256 _amount,
        uint256 amountOutMin,
        uint8 _stakingType,
        address parent
    ) external onlyEOA {
        if (
            !REFERRAL.isBindReferral(msg.sender) &&
            REFERRAL.isBindReferral(parent)
        ) {
            REFERRAL.bindReferral(parent, msg.sender);
        }
        stake(_amount, amountOutMin, _stakingType);
    }

    function stake(
        uint256 _amount,
        uint256 amountOutMin,
        uint8 _stakingType
    ) public {
        require(isStarted, "Staking: not started");
        require(REFERRAL.isBindReferral(msg.sender), "No referrer bound");
        uint256 maxAmount = maxStakingAmount();
        require(
            balances[msg.sender] + _amount <= maxAmount,
            "Staking amount cannot exceed max"
        );
        require(_amount <= 1000 ether, "Staking amount cannot exceed 1000");
        require(_stakingType <= 2, "Incorrect staking type");

        USDT.transferFrom(msg.sender, address(this), _amount);

        uint256 slippage = _stakingType == 2 ? (_amount * 5) / 100 : 0; // For 30-day staking type, 5% slippage

        // 95% add liquidity
        swapAndAddLiquidity(_amount - slippage, amountOutMin);

        mint(msg.sender, _amount, _stakingType);
        updateScore(msg.sender);
        if(slippage > 0){
            // 1% buy and burn
            buyAndBurn(slippage / 5, 0);
            // 1% node rewards
            uint256 amountShare = slippage / 5;
            if (SHARE_POOL.totalScore() > 0) {
                USDT.transfer(address(SHARE_POOL), amountShare);
                SHARE_POOL.addRewards(amountShare); // Update reward pool
            } else {
                USDT.transfer(_DEV_ADDR, amountShare);
            }
            // 3% to dev lab
            USDT.transfer(_DEV_ADDR, slippage * 3 / 5);
        }
    }

    function buyAndBurn(uint256 _amount, uint256 amountOutMin) private {
        address[] memory path = new address[](2);
        path = new address[](2);
        path[0] = address(USDT);
        path[1] = address(BY);
        ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
            _amount,
            amountOutMin,
            path,
            address(0xdead),
            block.timestamp
        );
    }

    function swapAndAddLiquidity(
        uint256 _amount,
        uint256 amountOutMin
    ) private {
        address[] memory path = new address[](2);
        path = new address[](2);
        path[0] = address(USDT);
        path[1] = address(BY);
        uint256 balb = BY.balanceOf(address(this));
        ROUTER.swapExactTokensForTokensSupportingFeeOnTransferTokens(
            _amount / 2,
            amountOutMin,
            path,
            address(this),
            block.timestamp
        );
        uint256 bala = BY.balanceOf(address(this));
        ROUTER.addLiquidity(
            address(USDT),
            address(BY),
            _amount / 2,
            bala - balb,
            0, // slippage is unavoidable
            0, // slippage is unavoidable
            address(0),
            block.timestamp
        );
    }

    function mint(address sender, uint256 _amount, uint8 _stakingType) private {
        Record memory order;
        order.stakingTime = uint40(block.timestamp);
        order.amount = uint160(_amount);
        order.status = false;
        order.stakingType = _stakingType;

        totalSupply += _amount;
        balances[sender] += _amount;
        setPreacher(sender); // Update preacher qualification, must be called before team performance update
        Record[] storage cord = stakingRecords[sender];
        uint256 stakingIndex = cord.length;
        cord.push(order);

        address[] memory referrals = REFERRAL.getUplines(sender, maxLevels);
        for (uint8 i = 0; i < referrals.length; i++) {
            address upline = referrals[i];
            uint256 preTeamValue = userInfo[upline].teamKPI;
            userInfo[upline].teamKPI = preTeamValue + _amount;
            uint256 newTeamValue = userInfo[upline].teamKPI;
            updateScore(upline);
            if(i >= referrals.length -1){
                // Already at the last level
                break;
            }
            address nextUpline = referrals[i + 1];
            for(uint256 j = 5; j >=2; j--){
                if(newTeamValue >= TEAM_LEVEL[j] && preTeamValue < TEAM_LEVEL[j]){
                    levelCounts[nextUpline][j] +=1;
                    addFreeNode(nextUpline, j);
                    break;
                }
            }
        }
        emit Transfer(address(0), sender, _amount);
        emit Staked(
            sender,
            _amount,
            block.timestamp,
            stakingIndex,
            stakingDays[_stakingType]
        );
    }

    function addFreeNode(address _user, uint256 _level) internal {
        // All free nodes have been distributed, or level is less than 2, do not process
        if(FREE_NODES[_level] == 0 || _level < 2){
            return;
        }
        // Check if free node has already been claimed for this level
        if(freeNodeAllocated[_user][_level]){
            return;
        }
        uint256 count = levelCounts[_user][_level];
        if(count == _level){
            FREE_NODES[_level] -=1;
            userInfo[_user].freeNodeCount += 1;
            totalNodeCount +=1;
            freeNodeAllocated[_user][_level] = true;
            if(userInfo[_user].preacherCount >=10){
                activeNodeCount += 1;
            }
        }
    }

    function subFreeNode(address _user, uint256 _level) internal {
        // Never claimed free node, or level is less than 2, do not process
        if(FREE_NODES[_level] == 70 || _level < 2){
            return;
        }
        // Has not claimed free node for this level, return directly
        if(!freeNodeAllocated[_user][_level]){
            return;
        }
        uint256 count = levelCounts[_user][_level];
        if(count == _level -1){
            FREE_NODES[_level] +=1;
            userInfo[_user].freeNodeCount = userInfo[_user].freeNodeCount > 0 ? userInfo[_user].freeNodeCount - 1 : 0;
            totalNodeCount = totalNodeCount > 0 ? totalNodeCount - 1 : 0;
            if(userInfo[_user].freeNodeCount == 0){
                clearScore(_user);
            }
            if(userInfo[_user].preacherCount >= 10){
                activeNodeCount = activeNodeCount > 0 ? activeNodeCount - 1 : 0;
            }
        }
    }

    function balanceOf(
        address account
    ) external view returns (uint256 balance) {
        Record[] storage cord = stakingRecords[account];
        if (cord.length > 0) {
            for (uint256 i = cord.length - 1; i >= 0; i--) {
                Record storage stakingRecord = cord[i];
                if (stakingRecord.status == false) {
                    balance += caclItem(stakingRecord);
                }
                if (i == 0) break;
            }
        }
    }

    struct RtRecord {
        uint32 index;
        uint40 stakingTime;
        uint160 amount;
        bool status;
        uint8 stakingType;
        uint40 countdown;
        uint256 reward;
    }

    function getRecords(
        address user,
        uint32 num,
        uint32 offset
    ) external view returns (RtRecord[] memory records) {
        Record[] storage cord = stakingRecords[user];
        uint256 length = cord.length;

        uint256 returnCount;
        if (num == 0 || offset + num > length) {
            if (offset >= length) {
                returnCount = 0;
            } else {
                returnCount = length - offset;
            }
        } else {
            returnCount = num;
        }

        records = new RtRecord[](returnCount);
        for (uint32 i = 0; i < returnCount; i++) {
            Record storage stakingRecord = cord[offset + i];

            uint40 countdown = 0;
            if (stakingRecord.status == false) {
                uint40 stake_time = stakingRecord.stakingTime;
                uint40 timeGas = uint40(stakingDays[stakingRecord.stakingType]);
                if ((timeGas + stake_time) > block.timestamp) {
                    countdown = timeGas + stake_time - uint40(block.timestamp);
                }
            }

            records[i] = RtRecord({
                index: offset + i,
                stakingTime: stakingRecord.stakingTime,
                amount: stakingRecord.amount,
                status: stakingRecord.status,
                stakingType: stakingRecord.stakingType,
                reward: caclItem(stakingRecord),
                countdown: countdown
            });
        }
    }

    function caclItem(
        Record storage stakingRecord
    ) private view returns (uint256 reward) {
        UD60x18 stakingAmount = ud(stakingRecord.amount);
        uint40 stake_time = stakingRecord.stakingTime;
        uint40 stake_period = (uint40(block.timestamp) - stake_time);
        stake_period = Math.min(stake_period, 30 days);
        if (stake_period == 0) reward = UD60x18.unwrap(stakingAmount);
        else
            reward = UD60x18.unwrap(
                stakingAmount.mul(
                    ud(rates[stakingRecord.stakingType]).powu(stake_period)
                )
            );
    }

    function rewardOfSlot(
        address user,
        uint8 index
    ) public view returns (uint256 reward) {
        Record storage stakingRecord = stakingRecords[user][index];
        return caclItem(stakingRecord);
    }

    function stakeCount(address user) external view returns (uint256 count) {
        count = stakingRecords[user].length;
    }

    // Process swap and distribute slippage fees
    function _processSwap(
        uint256 reward,
        uint256 stakingAmount,
        uint8 stakingType
    ) private returns (uint256 usdtAmountSwaped) {
        uint256 slippage = stakingType == 2 ? (stakingAmount * 5) / 100 : 0; // 30 days, 5% slippage
        uint256 usdtBalance1 = USDT.balanceOf(address(this));
        
        address[] memory path = new address[](2);
        path[0] = address(BY);
        path[1] = address(USDT);
        
        // 5% slippage swapped from BY to USDT, not deducted from user rewards
        ROUTER.swapTokensForExactTokens(
            reward + slippage,
            BY.balanceOf(address(this)),
            path,
            address(this),
            block.timestamp
        );

        if(slippage > 0){
            // === 1% buy and burn
            buyAndBurn(slippage / 5, 0);
            // === 1% node rewards
            uint256 amountShare = slippage / 5;
            if (SHARE_POOL.totalScore() > 0) {
                USDT.transfer(address(SHARE_POOL), amountShare);
                SHARE_POOL.addRewards(amountShare);
            } else {
                USDT.transfer(_DEV_ADDR, amountShare);
            }
            // === 3% to marketing wallet
            USDT.transfer(_MARKETING_ADDR, slippage * 3 / 5);
        }
        usdtAmountSwaped = USDT.balanceOf(address(this)) - usdtBalance1;
    }

    // Process referral reward distribution
    function _distributeRewards(
        uint256 stakingAmount,
        uint256 usdtAmountSwaped
    ) private returns (uint256 userAmount) {
        uint256 interset;
        if (usdtAmountSwaped > stakingAmount) {
            interset = usdtAmountSwaped - stakingAmount;
        }
        
        address[] memory referrals = REFERRAL.getUplines(msg.sender, maxLevels);
        uint256 teamFee = teamReward(referrals, interset, stakingAmount);
        uint256 directFee = directReferralReward(msg.sender, interset); // 5% of profit as direct referral reward
        
        userAmount = usdtAmountSwaped - directFee - teamFee;
    }

    function unstake(uint256 index) external onlyEOA {
        (uint256 reward, uint256 stakingAmount, uint8 stakingType) = _unstake(index);

        setPreacher(msg.sender); // Update preacher qualification, must be called before team performance update

        uint256 usdtSwapped = _processSwap(reward, stakingAmount, stakingType);
        uint256 userAmount = _distributeRewards(stakingAmount, usdtSwapped);

        // Update reward weight score and claim node rewards
        updateScore(msg.sender);
        SHARE_POOL.harvest(msg.sender);

        // Maintain 200,000 BY contract balance for swapping to USDT during unstaking
        if(BY.balanceOf(address(this)) < 200000 ether){
            BY.recycle(200000 ether - BY.balanceOf(address(this)));
        }
        
        // BYB airdrop (only valid for 30-day staking records)
        if (stakingType == 2) {
            uint256 bybAmount = usdtSwapped * 10;
            if (BYB.balanceOf(address(this)) >= bybAmount) {
                BYB.transfer(msg.sender, bybAmount);
            }
        }

        USDT.transfer(msg.sender, userAmount); // Transfer user's principal and rewards to their wallet
    }

    function _unstake(uint256 index) private returns (uint256 reward, uint256 amount, uint8 stakingType) {
        address sender = msg.sender;
        Record storage stakingRecord = stakingRecords[sender][index];

        uint256 stakingTime = stakingRecord.stakingTime;
        stakingType = stakingRecord.stakingType;
        require(
            block.timestamp - stakingTime >= stakingDays[stakingType],
            "The time is not right"
        );
        require(stakingRecord.status == false, "unstaked already");

        amount = stakingRecord.amount;
        totalSupply -= amount;
        balances[sender] -= amount;
        emit Transfer(sender, address(0), amount);

        reward = caclItem(stakingRecord);
        stakingRecord.status = true;

        userInfo[sender].unstakingCount = userInfo[sender].unstakingCount + 1;

        emit Unstaked(sender, reward, uint40(block.timestamp), index);
    }

    function getTeamKPI(address _user) public view returns (uint256) {
        return userInfo[_user].teamKPI;
    }

    function setPreacher(address _user) internal {
        if (userInfo[_user].isPreacher) {
            if (balances[_user] < 100e18) {
                userInfo[_user].isPreacher = false;
                address ref = REFERRAL.getReferral(_user);
                if (ref != address(0)) {
                    userInfo[ref].preacherCount -= 1;
                    if(userInfo[ref].preacherCount == 9){
                        clearScore(ref);
                        activeNodeCount -= (userInfo[ref].freeNodeCount + userInfo[ref].initNodeCount);
                    }
                }
            }
        } else {
            if (balances[_user] >= 100e18) {
                userInfo[_user].isPreacher = true;
                address ref = REFERRAL.getReferral(_user);
                if (ref != address(0)) {
                    userInfo[ref].preacherCount += 1;
                    if(userInfo[ref].preacherCount == 10){
                        activeNodeCount += (userInfo[ref].freeNodeCount + userInfo[ref].initNodeCount);
                    }
                }
            }
        }
    }

    function directReferralReward(
        address _user,
        uint256 _interset
    ) private returns (uint256 fee) {
        fee = (_interset * 5) / 100;
        address up = REFERRAL.getReferral(_user);
        if (up != address(0) && userInfo[up].isPreacher) {
            USDT.transfer(up, fee);
        } else {
            // No direct referrer, or direct referrer is not a preacher, reward goes to marketing wallet
            USDT.transfer(marketingAddress, fee);
        }
    }

    function teamReward(
        address[] memory referrals,
        uint256 _interset,
        uint256 _stakingAmount
    ) private returns (uint256 fee) {
        address upline;
        uint256 teamKpi;
        uint256 maxTeamRate = 20;
        uint256 spendRate = 0;
        fee = (_interset * maxTeamRate) / 100;
        for (uint256 i = 0; i < referrals.length; i++) {
            upline = referrals[i];
            uint256 preTeamValue = userInfo[upline].teamKPI;
            uint256 newTeamValue = preTeamValue > _stakingAmount ? preTeamValue - _stakingAmount : 0;
            userInfo[upline].teamKPI = newTeamValue;
            if (!userInfo[upline].isPreacher) {
                continue;
            }
            teamKpi = getTeamKPI(upline);
            if (
                teamKpi >= TEAM_LEVEL[5] &&
                maxTeamRate > spendRate
            ) {
                USDT.transfer(
                    upline,
                    (_interset * (maxTeamRate - spendRate)) / 100
                );
                spendRate = 20;
            }else if (
                teamKpi >= TEAM_LEVEL[4] &&
                teamKpi < TEAM_LEVEL[5] &&
                spendRate < 16
            ) {
                USDT.transfer(upline, (_interset * (16 - spendRate)) / 100);
                spendRate = 16;
            }else if (
                teamKpi >= TEAM_LEVEL[3] &&
                teamKpi < TEAM_LEVEL[4] &&
                spendRate < 12
            ) {
                USDT.transfer(upline, (_interset * (12 - spendRate)) / 100);
                spendRate = 12;
            }else if (
                teamKpi >= TEAM_LEVEL[2] &&
                teamKpi < TEAM_LEVEL[3] &&
                spendRate < 8
            ) {
                USDT.transfer(upline, (_interset * (8 - spendRate)) / 100);
                spendRate = 8;
            }

            if (
                teamKpi >= TEAM_LEVEL[1] &&
                teamKpi < TEAM_LEVEL[2] &&
                spendRate < 4
            ) {
                USDT.transfer(upline, (_interset * (4 - spendRate)) / 100);
                spendRate = 4;
            }
            if(newTeamValue == 0){
                // Team performance is 0, clear node reward weight score, no reward eligibility
                clearScore(upline);
            }else{
                // Team performance changed, update node reward weight score
                updateScore(upline);
            }
            if(i >= referrals.length -1){
                    // Already at the last level
                    break;
            }
            address nextUpline = referrals[i + 1];
            for(uint256 j = 5; j >=2; j--){
                if(newTeamValue < TEAM_LEVEL[j] && preTeamValue >= TEAM_LEVEL[j]){
                    levelCounts[nextUpline][j] -=1;
                    subFreeNode(nextUpline, j);
                    break;
                }
            }
        }
        if (maxTeamRate > spendRate) {
            // Remaining undistributed team rewards to marketing wallet
            USDT.transfer(
                marketingAddress,
                fee - ((_interset * spendRate) / 100)
            );
        }
    }

    // Synchronize UniswapV2Pair reserves,
    // Transfer all USDT in the contract to the liquidity pool contract,
    // Then call the sync method
    // No permission required, anyone can call
    function sync() external {
        uint256 usdtBalance = IERC20(USDT).balanceOf(address(this));
        address pair = BY.uniswapV2Pair();
        IERC20(USDT).transfer(pair, usdtBalance);
        IUniswapV2Pair(pair).sync();
    }

    function emergencyWithdrawBY(
        address to,
        uint256 _amount
    ) external onlyOwner {
        BY.transfer(to, _amount);
    }

    function getUserInfo(address _user)
        external
        view
        returns (
            uint32 directCount, // My direct referral count
            uint32 teamCount, // My total team size
            bool isBindReferral, // Whether I have bound a referrer
            uint256 myKPI, // My total staked amount
            uint256 teamKPI, // My team performance
            uint256 balance, // My total staking rewards (current assets)
            uint256 _maxStakingAmount, // My current maximum staking amount
            address referrer // My referrer
        )
    {
        (, directCount, teamCount, isBindReferral) = REFERRAL.getInfo(_user);
        myKPI = balances[_user];
        balance = this.balanceOf(_user);
        _maxStakingAmount = maxStakingAmount() > myKPI ? maxStakingAmount() - myKPI : 0;
        UserInfo storage info = userInfo[_user];
        teamKPI = info.teamKPI;
        referrer = REFERRAL.getReferral(_user);
    }

    function getNodeInfo(address _user)
        external
        view
        returns (
            uint256 _totalRewards, // Total rewards distributed across the network
            uint32 _totalNodeCount, // Current total number of nodes
            uint32 _totalActiveNodes, // Current number of active nodes across the network   
            uint32 directPreacherCount, // My current qualified member count 
            uint32 userNodeCount, // My node count     
            uint256 userRewardAcc, // My accumulated rewards
            uint256 userRewardPending // My pending reward amount
        )
    {
        (_totalRewards, , userRewardAcc, userRewardPending) = SHARE_POOL.getInfo(_user);
        _totalActiveNodes = activeNodeCount;
        _totalNodeCount = totalNodeCount;
        UserInfo storage info = userInfo[_user];
        directPreacherCount = info.preacherCount;
        userNodeCount = info.freeNodeCount + info.initNodeCount;
    }

    struct Downline {
        address user;
        uint256 teamKPI;
        uint256 personKPI;
    }

    function getDownlines(
        address _address,
        uint32 _num,
        uint32 _offset
    ) external view returns (Downline[] memory) {
        address[] memory downlines = REFERRAL.getDownlines(
            _address,
            _num,
            _offset
        );
        Downline[] memory RtDownlines = new Downline[](downlines.length);
        for (uint256 i = 0; i < downlines.length; i++) {
            RtDownlines[i] = Downline({
                user: downlines[i],
                teamKPI: getTeamKPI(downlines[i]),
                personKPI: balances[downlines[i]]
            });
        }
        return RtDownlines;
    }

    function hasBound(address _user) external view returns (bool) {
        return REFERRAL.isBindReferral(_user);
    }
}

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);
}

File 3 of 41 : Common.sol
// 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;
        }
    }
}

File 4 of 41 : Casting.sol
// 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);
}

File 5 of 41 : Constants.sol
// 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;

File 6 of 41 : Errors.sol
// 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);

File 7 of 41 : ValueType.sol
// 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;

File 8 of 41 : Casting.sol
// 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);
}

File 9 of 41 : Constants.sol
// 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;

File 10 of 41 : Errors.sol
// 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);

File 11 of 41 : ValueType.sol
// 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;

File 12 of 41 : Casting.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, 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);
}

File 13 of 41 : Constants.sol
// 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);

File 14 of 41 : Errors.sol
// 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);

File 15 of 41 : Helpers.sol
// 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());
}

File 16 of 41 : Math.sol
// 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));
    }
}

File 17 of 41 : ValueType.sol
// 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;

File 18 of 41 : Casting.sol
// 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);
}

File 19 of 41 : Constants.sol
// 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);

File 20 of 41 : Errors.sol
// 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);

File 21 of 41 : ValueType.sol
// 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;

File 22 of 41 : Casting.sol
// 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);
}

File 23 of 41 : Constants.sol
// 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;

File 24 of 41 : Errors.sol
// 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);

File 25 of 41 : ValueType.sol
// 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;

File 26 of 41 : UD60x18.sol
// 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";

File 27 of 41 : Casting.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);
}

File 28 of 41 : Constants.sol
// 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);

File 29 of 41 : Conversions.sol
// 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);
    }
}

File 30 of 41 : Errors.sol
// 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);

File 31 of 41 : Helpers.sol
// 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());
}

File 32 of 41 : Math.sol
// 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));
    }
}

File 33 of 41 : ValueType.sol
// 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;
}

File 37 of 41 : Const.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

address constant _USDT_ADDR = 0x55d398326f99059fF775485246999027B3197955;
address constant _ROUTER_ADDR = 0x10ED43C718714eb63d5aA57B78B54704E256024E;
address constant _BYB_ADDR = 0xd1c5840E565f7350A893cd036367f639CB66B75f;

address constant _DEV_ADDR = 0x1ae539Ba18B0c9469ED03F08F3A2ea6FC5615dB8;
address constant _MARKETING_ADDR = 0x2986D00364d109E0139D1bC7623d905ca5E56f8B;
address constant _PROFIT_ADDR = 0x02C1Af1edDb172aEc7b9E82e3dEfCE30c07c72c5;
address constant _ROOT_REFERRER = 0x2fa1B0fE92286915a78fF073515DEBE50aB9C05d;

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

interface IBY {
    event Approval(address indexed owner, address indexed spender, uint256 amount);
    event ExcludedFromFee(address account);
    event IncludedToFee(address account);
    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 excludeFromFee(address account) external;
    function excludeMultipleAccountsFromFee(address[] memory accounts) external;
    function inSwapAndLiquify() external view returns (bool);
    function includeInFee(address account) external;
    function isExcludedFromFee(address account) external view returns (bool);
    function name() external view returns (string memory);
    function owner() external view returns (address);
    function symbol() external view returns (string memory);
    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 getReserveUSDT() external view returns (uint112);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

interface IReferral{    
    function getReferral(address _address)external view returns(address);

    function isBindReferral(address _address) external view returns(bool);

    function bindReferral(address _referral,address _user) external;

    function getUplines(address _address,uint256 _num) external view returns(address[] memory);

    function getDirectCount(address _address) external view returns(uint256);

    function getTeamCount(address _address) external view returns(uint256);

    function getDownlines(address _address, uint256 _num, uint256 _offset) external view returns (address[] memory);

    function getInfo(address _user) external view returns (
        address referral,
        uint32 directCount,
        uint32 teamCount,
        bool hasBound
    );
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

interface ISharePool {
    function updateScore(address _user, uint256 _newScore) external;
    function harvest(address _user) external;
    function addRewards(uint256 amount) external;
    function getInfo(address _user) external view returns (
        uint256 _totalRewards,
        uint256 _totalClaimedRewards,
        uint256 userRewardAcc,
        uint256 userRewardPending
    );
    function totalScore() external view returns (uint256);
}

// 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);
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_referralAddress","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":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakingIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakingTime","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"},{"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":"stakingIndex","type":"uint256"}],"name":"Unstaked","type":"event"},{"inputs":[],"name":"BY","outputs":[{"internalType":"contract IBY","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"FREE_NODES","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REFERRAL","outputs":[{"internalType":"contract IReferral","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SHARE_POOL","outputs":[{"internalType":"contract ISharePool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"activeNodeCount","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"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":[],"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":"emergencyWithdrawBY","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint32","name":"_num","type":"uint32"},{"internalType":"uint32","name":"_offset","type":"uint32"}],"name":"getDownlines","outputs":[{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"teamKPI","type":"uint256"},{"internalType":"uint256","name":"personKPI","type":"uint256"}],"internalType":"struct Staking.Downline[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"getNodeInfo","outputs":[{"internalType":"uint256","name":"_totalRewards","type":"uint256"},{"internalType":"uint32","name":"_totalNodeCount","type":"uint32"},{"internalType":"uint32","name":"_totalActiveNodes","type":"uint32"},{"internalType":"uint32","name":"directPreacherCount","type":"uint32"},{"internalType":"uint32","name":"userNodeCount","type":"uint32"},{"internalType":"uint256","name":"userRewardAcc","type":"uint256"},{"internalType":"uint256","name":"userRewardPending","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint32","name":"num","type":"uint32"},{"internalType":"uint32","name":"offset","type":"uint32"}],"name":"getRecords","outputs":[{"components":[{"internalType":"uint32","name":"index","type":"uint32"},{"internalType":"uint40","name":"stakingTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"bool","name":"status","type":"bool"},{"internalType":"uint8","name":"stakingType","type":"uint8"},{"internalType":"uint40","name":"countdown","type":"uint40"},{"internalType":"uint256","name":"reward","type":"uint256"}],"internalType":"struct Staking.RtRecord[]","name":"records","type":"tuple[]"}],"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"}],"name":"getUserInfo","outputs":[{"internalType":"uint32","name":"directCount","type":"uint32"},{"internalType":"uint32","name":"teamCount","type":"uint32"},{"internalType":"bool","name":"isBindReferral","type":"bool"},{"internalType":"uint256","name":"myKPI","type":"uint256"},{"internalType":"uint256","name":"teamKPI","type":"uint256"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"_maxStakingAmount","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"hasBound","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"addresses","type":"address[]"}],"name":"initNodes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isStarted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"levelCounts","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxLevels","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxStakingAmount","outputs":[{"internalType":"uint256","name":"_maxStakingAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint8","name":"index","type":"uint8"}],"name":"rewardOfSlot","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_byAddress","type":"address"}],"name":"setByAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"setMarketingAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"_maxLevels","type":"uint8"}],"name":"setMaxLevels","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_referralAddress","type":"address"}],"name":"setReferralAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_sharePoolAddress","type":"address"}],"name":"setSharePoolAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint8","name":"_stakingType","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":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint8","name":"_stakingType","type":"uint8"},{"internalType":"address","name":"parent","type":"address"}],"name":"stakeWithInviter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"stakingRecords","outputs":[{"internalType":"uint40","name":"stakingTime","type":"uint40"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"bool","name":"status","type":"bool"},{"internalType":"uint8","name":"stakingType","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"start","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stop","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":[],"name":"totalNodeCount","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","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":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"bool","name":"isPreacher","type":"bool"},{"internalType":"uint32","name":"freeNodeCount","type":"uint32"},{"internalType":"uint32","name":"initNodeCount","type":"uint32"},{"internalType":"uint32","name":"preacherCount","type":"uint32"},{"internalType":"uint256","name":"teamKPI","type":"uint256"},{"internalType":"uint256","name":"unstakingCount","type":"uint256"}],"stateMutability":"view","type":"function"}]

6000805460ff60a81b1916600f60a91b17905560e06040526201518060809081526213c68060a05262278d0060c0526200003e90600190600362000281565b5060408051606081018252670de0b6bbb9e544c08152670de0b6c3c63b40a06020820152670de0b6d3cc89fcc09181019190915262000082906004906003620002cb565b506040805160c0810182526000815269021e19e0c9bab24000006020820152690a968163f0a57b4000009181019190915269152d02c7e14af680000060608201526969e10de76676d0800000608082015269d3c21bcecceda100000060a0820152620000f390600790600662000307565b506040805160c081018252600080825260208201526046918101829052606081018290526080810182905260a08101919091526200013690600d90600662000343565b503480156200014457600080fd5b506040516200551938038062005519833981016040819052620001679162000390565b600080546001600160a01b031916339081178255604051909182917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a350601880546001600160a01b0383166001600160a01b031991821617909155601a8054909116732986d00364d109e0139d1bc7623d905ca5e56f8b17905560405163095ea7b360e01b81527310ed43c718714eb63d5aa57b78b54704e256024e600482015260001960248201527355d398326f99059ff775485246999027b31979559063095ea7b3906044016020604051808303816000875af115801562000253573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002799190620003c2565b5050620003e6565b8260038101928215620002b9579160200282015b82811115620002b9578251829062ffffff1690559160200191906001019062000295565b50620002c792915062000379565b5090565b8260038101928215620002b9579160200282015b82811115620002b957825182906001600160401b0316905591602001919060010190620002df565b8260068101928215620002b9579160200282015b82811115620002b957825182906001600160501b03169055916020019190600101906200031b565b8260068101928215620002b9579160200282015b82811115620002b9578251829060ff1690559160200191906001019062000357565b5b80821115620002c757600081556001016200037a565b600060208284031215620003a357600080fd5b81516001600160a01b0381168114620003bb57600080fd5b9392505050565b600060208284031215620003d557600080fd5b81518015158114620003bb57600080fd5b61512380620003f66000396000f3fe608060405234801561001057600080fd5b50600436106102535760003560e01c80636f38e410116101465780639f18635e116100c3578063c999fea311610087578063c999fea3146106d0578063cc097076146106e7578063d04072b4146106fa578063f2fde38b1461070d578063f56d60b414610720578063fff6cae91461073357600080fd5b80639f18635e14610663578063a2f921c614610676578063b3caba5a146106a2578063be9a6555146106b5578063c63568c7146106bd57600080fd5b80638282b0151161010a5780638282b0151461060a5780638da5cb5b1461061d578063906e9dd01461063057806395d89b41146102a657806399fe39011461064357600080fd5b80636f38e4101461058e57806370a08231146105a2578063748e6856146105b557806375340815146105c857806381471bd0146105df57600080fd5b806333060d90116101d4578063544736e611610198578063544736e61461048c578063582115fb146104a05780636386c1c7146104f657806365ecbf661461055b57806367b524c81461057b57600080fd5b806333060d90146103e957806336255e071461041257806340b708c0146104255780634d5d08061461043857806353a273411461044057600080fd5b80631959a0021161021b5780631959a002146102e85780631d65168e1461037957806327e235e31461039c5780632e17de78146103bc578063313ce567146103cf57600080fd5b8063020b565d14610258578063069a8f2d1461028557806306fdde03146102a657806307da68f5146102d557806318160ddd146102df575b600080fd5b61026b61026636600461485b565b61073b565b60405163ffffffff90911681526020015b60405180910390f35b61029861029336600461489d565b61077a565b60405190815260200161027c565b6102c86040518060400160405280600381526020016242595360e81b81525081565b60405161027c91906148d2565b6102dd6107c9565b005b610298601b5481565b61033d6102f6366004614920565b60156020526000908152604090208054600182015460029092015460ff82169263ffffffff6101008404811693600160281b8104821693600160481b909104909116919086565b60408051961515875263ffffffff95861660208801529385169386019390935292166060840152608083019190915260a082015260c00161027c565b61038c610387366004614920565b61080b565b604051901515815260200161027c565b6102986103aa366004614920565b601c6020526000908152604090205481565b6102dd6103ca36600461493d565b61087a565b6103d7601281565b60405160ff909116815260200161027c565b6102986103f7366004614920565b6001600160a01b031660009081526016602052604090205490565b6102dd610420366004614956565b610c3e565b6102dd61043336600461485b565b610dd5565b610298610e79565b61045361044e36600461485b565b610fb9565b6040805164ffffffffff90951685526001600160a01b0390931660208501529015159183019190915260ff16606082015260800161027c565b60005461038c90600160a01b900460ff1681565b6104b36104ae366004614920565b611014565b6040805197885263ffffffff9687166020890152948616948701949094529184166060860152909216608084015260a083019190915260c082015260e00161027c565b610509610504366004614920565b611109565b6040805163ffffffff998a168152989097166020890152941515958701959095526060860192909252608085015260a084015260c08301919091526001600160a01b031660e08201526101000161027c565b61056e6105693660046149b0565b6112d3565b60405161027c91906149fb565b6102dd610589366004614920565b611544565b6000546103d790600160a81b900460ff1681565b6102986105b0366004614920565b611590565b6102dd6105c3366004614aa8565b611637565b60005461026b90600160d01b900463ffffffff1681565b6019546105f2906001600160a01b031681565b6040516001600160a01b03909116815260200161027c565b6102dd610618366004614add565b611baa565b6000546105f2906001600160a01b031681565b6102dd61063e366004614920565b611dc8565b6106566106513660046149b0565b611e14565b60405161027c9190614b52565b61029861067136600461493d565b612019565b610298610684366004614920565b6001600160a01b031660009081526015602052604090206001015490565b6102dd6106b0366004614920565b612030565b6102dd61207c565b6018546105f2906001600160a01b031681565b60005461026b90600160b01b900463ffffffff1681565b6017546105f2906001600160a01b031681565b6102dd610708366004614920565b6120bb565b6102dd61071b366004614920565b612183565b6102dd61072e366004614ba7565b6121f8565b6102dd612242565b6014602052816000526040600020816006811061075757600080fd5b60089182820401919006600402915091509054906101000a900463ffffffff1681565b6001600160a01b0382166000908152601660205260408120805482919060ff85169081106107aa576107aa614bc2565b9060005260206000200190506107bf816123fe565b9150505b92915050565b6000546001600160a01b031633146107fc5760405162461bcd60e51b81526004016107f390614bd8565b60405180910390fd5b6000805460ff60a01b19169055565b601854604051633bb1db8160e21b81526001600160a01b038381166004830152600092169063eec76e0490602401602060405180830381865afa158015610856573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107c39190614c0e565b3233146108b35760405162461bcd60e51b81526020600482015260076024820152664e6f7420454f4160c81b60448201526064016107f3565b60008060006108c18461249f565b9250925092506108d0336126f0565b60006108dd848484612a6d565b905060006108eb8483612fe1565b90506108f6336130a7565b60195460405163072e008f60e11b81523360048201526001600160a01b0390911690630e5c011e90602401600060405180830381600087803b15801561093b57600080fd5b505af115801561094f573d6000803e3d6000fd5b50506017546040516370a0823160e01b8152306004820152692a5a058fc295ed00000093506001600160a01b0390911691506370a0823190602401602060405180830381865afa1580156109a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109cb9190614c29565b1015610aaa576017546040516370a0823160e01b81523060048201526001600160a01b039091169063dd1c35bc9082906370a0823190602401602060405180830381865afa158015610a21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a459190614c29565b610a5990692a5a058fc295ed000000614c58565b6040518263ffffffff1660e01b8152600401610a7791815260200190565b600060405180830381600087803b158015610a9157600080fd5b505af1158015610aa5573d6000803e3d6000fd5b505050505b8260ff16600203610bbf576000610ac283600a614c6b565b6040516370a0823160e01b8152306004820152909150819073d1c5840e565f7350a893cd036367f639cb66b75f906370a0823190602401602060405180830381865afa158015610b16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3a9190614c29565b10610bbd5760405163a9059cbb60e01b815273d1c5840e565f7350a893cd036367f639cb66b75f9063a9059cbb90610b789033908590600401614c82565b6020604051808303816000875af1158015610b97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bbb9190614c0e565b505b505b60405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb90610bf29033908590600401614c82565b6020604051808303816000875af1158015610c11573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c359190614c0e565b50505050505050565b323314610c775760405162461bcd60e51b81526020600482015260076024820152664e6f7420454f4160c81b60448201526064016107f3565b601854604051633bb1db8160e21b81523360048201526001600160a01b039091169063eec76e0490602401602060405180830381865afa158015610cbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce39190614c0e565b158015610d595750601854604051633bb1db8160e21b81526001600160a01b0383811660048301529091169063eec76e0490602401602060405180830381865afa158015610d35573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d599190614c0e565b15610dc457601854604051631ea690cf60e21b81526001600160a01b03838116600483015233602483015290911690637a9a433c90604401600060405180830381600087803b158015610dab57600080fd5b505af1158015610dbf573d6000803e3d6000fd5b505050505b610dcf848484611637565b50505050565b6000546001600160a01b03163314610dff5760405162461bcd60e51b81526004016107f390614bd8565b60175460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610e319085908590600401614c82565b6020604051808303816000875af1158015610e50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e749190614c0e565b505050565b600080601760009054906101000a90046001600160a01b03166001600160a01b0316631542609b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ecf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef39190614c9b565b905069d3c21bcecceda1000000816001600160701b03161015610f2057683635c9adc5dea0000091505090565b6a027b46536c66c8e3000000816001600160701b03161015610f4c5768a2a15d09519be0000091505090565b6a084595161401484a000000816001600160701b03161015610f795769010f0cf064dd5920000091505090565b6a108b2a2c28029094000000816001600160701b03161015610fa65769021e19e0c9bab240000091505090565b6b033b2e3c9fd0803ce800000091505090565b60166020528160005260406000208181548110610fd557600080fd5b60009182526020909120015464ffffffffff811692506001600160a01b03600160281b820416915060ff600160c81b8204811691600160d01b90041684565b60195460405160016222a30f60e01b031981526001600160a01b038381166004830152600092839283928392839283928392169063ffdd5cf190602401608060405180830381865afa15801561106e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110929190614cc4565b600080546001600160a01b038e168252601560205260409091208054959c5063ffffffff600160b01b830481169c50600160d01b90920482169a50600160481b86048216995092965090945090926110fb9250600160281b810482169161010090910416614cfa565b935050919395979092949650565b60185460405160016222a30f60e01b031981526001600160a01b038381166004830152600092839283928392839283928392839291169063ffdd5cf190602401608060405180830381865afa158015611166573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118a9190614d17565b6001600160a01b038d166000818152601c6020526040908190205490516370a0823160e01b81526004810192909252939c50919a5098509096503091506370a0823190602401602060405180830381865afa1580156111ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112119190614c29565b92508461121c610e79565b1161122857600061123b565b84611231610e79565b61123b9190614c58565b6001600160a01b038a81166000818152601560205260409081902060018101546018549251633b0f0f2f60e01b81526004810194909452985093955090911690633b0f0f2f90602401602060405180830381865afa1580156112a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c59190614d73565b915050919395975091939597565b6001600160a01b0383166000908152601660205260408120805460609263ffffffff861615806113115750816113098787614cfa565b63ffffffff16115b1561134257818563ffffffff161061132b5750600061134b565b61133b63ffffffff861683614c58565b905061134b565b5063ffffffff85165b8067ffffffffffffffff81111561136457611364614d90565b6040519080825280602002602001820160405280156113cb57816020015b6040805160e08101825260008082526020808301829052928201819052606082018190526080820181905260a0820181905260c082015282526000199092019101816113825790505b50935060005b818163ffffffff161015611539576000846113ec8389614cfa565b63ffffffff168154811061140257611402614bc2565b600091825260208220018054909250600160c81b900460ff161515810361148557815464ffffffffff811690600090600190600160d01b900460ff166003811061144e5761144e614bc2565b015490504261145d8383614da6565b64ffffffffff16111561148257426114758383614da6565b61147f9190614dc4565b92505b50505b6040518060e00160405280848a61149c9190614cfa565b63ffffffff168152835464ffffffffff80821660208401526001600160a01b03600160281b830416604084015260ff600160c81b8304811615156060850152600160d01b9092049091166080830152831660a082015260c0016114fe846123fe565b815250878463ffffffff168151811061151957611519614bc2565b60200260200101819052505050808061153190614de2565b9150506113d1565b505050509392505050565b6000546001600160a01b0316331461156e5760405162461bcd60e51b81526004016107f390614bd8565b601980546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526016602052604081208054156116315780546000906115c090600190614c58565b90505b60008282815481106115d7576115d7614bc2565b600091825260208220018054909250600160c81b900460ff161515900361160e57611601816123fe565b61160b9085614e05565b93505b8160000361161c575061162f565b508061162781614e18565b9150506115c3565b505b50919050565b600054600160a01b900460ff166116875760405162461bcd60e51b815260206004820152601460248201527314dd185ada5b99ce881b9bdd081cdd185c9d195960621b60448201526064016107f3565b601854604051633bb1db8160e21b81523360048201526001600160a01b039091169063eec76e0490602401602060405180830381865afa1580156116cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f39190614c0e565b6117335760405162461bcd60e51b8152602060048201526011602482015270139bc81c9959995c9c995c88189bdd5b99607a1b60448201526064016107f3565b600061173d610e79565b336000908152601c6020526040902054909150819061175d908690614e05565b11156117ab5760405162461bcd60e51b815260206004820181905260248201527f5374616b696e6720616d6f756e742063616e6e6f7420657863656564206d617860448201526064016107f3565b683635c9adc5dea0000084111561180e5760405162461bcd60e51b815260206004820152602160248201527f5374616b696e6720616d6f756e742063616e6e6f7420657863656564203130306044820152600360fc1b60648201526084016107f3565b60028260ff16111561185b5760405162461bcd60e51b8152602060048201526016602482015275496e636f7272656374207374616b696e67207479706560501b60448201526064016107f3565b6040516323b872dd60e01b8152336004820152306024820152604481018590526000805160206150ce833981519152906323b872dd906064016020604051808303816000875af11580156118b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d79190614c0e565b5060008260ff166002146118ec576000611903565b60646118f9866005614c6b565b6119039190614e2f565b90506119186119128287614c58565b856131d5565b6119233386856134c6565b61192c336130a7565b8015611ba357611947611940600583614e2f565b60006138d2565b6000611954600583614e2f565b90506000601960009054906101000a90046001600160a01b03166001600160a01b031663c006719f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119cf9190614c29565b1115611aba5760195460405163a9059cbb60e01b81526000805160206150ce8339815191529163a9059cbb91611a13916001600160a01b0316908590600401614c82565b6020604051808303816000875af1158015611a32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a569190614c0e565b5060195460405163beceed3960e01b8152600481018390526001600160a01b039091169063beceed3990602401600060405180830381600087803b158015611a9d57600080fd5b505af1158015611ab1573d6000803e3d6000fd5b50505050611b46565b60405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb90611b0190731ae539ba18b0c9469ed03f08f3a2ea6fc5615db8908590600401614c82565b6020604051808303816000875af1158015611b20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b449190614c0e565b505b6000805160206150ce83398151915263a9059cbb731ae539ba18b0c9469ed03f08f3a2ea6fc5615db86005611b7c866003614c6b565b611b869190614e2f565b6040518363ffffffff1660e01b8152600401610bf2929190614c82565b5050505050565b6000546001600160a01b03163314611bd45760405162461bcd60e51b81526004016107f390614bd8565b60005b81811015610e745760156000848484818110611bf557611bf5614bc2565b9050602002016020810190611c0a9190614920565b6001600160a01b03168152602081019190915260400160002054600160281b900463ffffffff1615611c745760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60448201526064016107f3565b6017546001600160a01b031663a9059cbb848484818110611c9757611c97614bc2565b9050602002016020810190611cac9190614920565b681b1ae4d6e2ef5000006040518363ffffffff1660e01b8152600401611cd3929190614c82565b6020604051808303816000875af1158015611cf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d169190614c0e565b50600160156000858585818110611d2f57611d2f614bc2565b9050602002016020810190611d449190614920565b6001600160a01b0316815260208101919091526040016000908120805468ffffffff00000000001916600160281b63ffffffff948516021790558054600192601691611d99918591600160b01b900416614cfa565b92506101000a81548163ffffffff021916908363ffffffff16021790555080611dc190614e51565b9050611bd7565b6000546001600160a01b03163314611df25760405162461bcd60e51b81526004016107f390614bd8565b601a80546001600160a01b0319166001600160a01b0392909216919091179055565b601854604051631d98022360e01b81526001600160a01b03858116600483015263ffffffff808616602484015284166044830152606092600092911690631d98022390606401600060405180830381865afa158015611e77573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611e9f9190810190614ebf565b90506000815167ffffffffffffffff811115611ebd57611ebd614d90565b604051908082528060200260200182016040528015611f1b57816020015b611f08604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b815260200190600190039081611edb5790505b50905060005b825181101561200f576040518060600160405280848381518110611f4757611f47614bc2565b60200260200101516001600160a01b03168152602001611f98858481518110611f7257611f72614bc2565b60200260200101516001600160a01b031660009081526015602052604090206001015490565b8152602001601c6000868581518110611fb357611fb3614bc2565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054815250828281518110611ff157611ff1614bc2565b6020026020010181905250808061200790614e51565b915050611f21565b5095945050505050565b600d816006811061202957600080fd5b0154905081565b6000546001600160a01b0316331461205a5760405162461bcd60e51b81526004016107f390614bd8565b601880546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146120a65760405162461bcd60e51b81526004016107f390614bd8565b6000805460ff60a01b1916600160a01b179055565b6000546001600160a01b031633146120e55760405162461bcd60e51b81526004016107f390614bd8565b601780546001600160a01b0319166001600160a01b03831690811790915560405163095ea7b360e01b815263095ea7b39061213c907310ed43c718714eb63d5aa57b78b54704e256024e9060001990600401614c82565b6020604051808303816000875af115801561215b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061217f9190614c0e565b5050565b6000546001600160a01b031633146121ad5760405162461bcd60e51b81526004016107f390614bd8565b600080546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b6000546001600160a01b031633146122225760405162461bcd60e51b81526004016107f390614bd8565b6000805460ff909216600160a81b0260ff60a81b19909216919091179055565b6040516370a0823160e01b81523060048201526000906000805160206150ce833981519152906370a0823190602401602060405180830381865afa15801561228e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b29190614c29565b90506000601760009054906101000a90046001600160a01b03166001600160a01b03166349bd5a5e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612309573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061232d9190614d73565b60405163a9059cbb60e01b81529091506000805160206150ce8339815191529063a9059cbb906123639084908690600401614c82565b6020604051808303816000875af1158015612382573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a69190614c0e565b50806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156123e257600080fd5b505af11580156123f6573d6000803e3d6000fd5b505050505050565b80546000906001600160a01b03600160281b8204169064ffffffffff16826124268242614dc4565b90506124358162278d006139bf565b90508064ffffffffff1660000361244e57829350612497565b84546124949061248d9064ffffffffff84169061248790600490600160d01b900460ff166003811061248257612482614bc2565b015490565b906139e5565b8490613a47565b93505b505050919050565b33600081815260166020526040812080549192839283928391879081106124c8576124c8614bc2565b6000918252602090912001805460ff600160d01b820416945090915064ffffffffff16600184600381106124fe576124fe614bc2565b015461250a8242614c58565b10156125505760405162461bcd60e51b8152602060048201526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b60448201526064016107f3565b8154600160c81b900460ff161561259c5760405162461bcd60e51b815260206004820152601060248201526f756e7374616b656420616c726561647960801b60448201526064016107f3565b8154601b8054600160281b9092046001600160a01b0316965086916000906125c5908490614c58565b90915550506001600160a01b0383166000908152601c6020526040812080548792906125f2908490614c58565b90915550506040518581526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3612641826123fe565b825460ff60c81b1916600160c81b1783556001600160a01b03841660009081526015602052604090206002015490965061267c906001614e05565b6001600160a01b03841660008181526015602090815260409182902060020193909355805189815264ffffffffff4216938101939093528201899052907f569d6dbbe8a026a1e17ebab5d7c373f2b81a8a4d7f3fef0d2a5ed744d231a8b89060600160405180910390a25050509193909250565b6001600160a01b03811660009081526015602052604090205460ff16156128d4576001600160a01b0381166000908152601c602052604090205468056bc75e2d6310000011156128d1576001600160a01b03818116600081815260156020526040808220805460ff191690556018549051633b0f0f2f60e01b8152600481019390935290921690633b0f0f2f90602401602060405180830381865afa15801561279d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127c19190614d73565b90506001600160a01b0381161561217f576001600160a01b038116600090815260156020526040902080546001919060099061280b908490600160481b900463ffffffff16614f53565b82546101009290920a63ffffffff8181021990931691831602179091556001600160a01b038316600090815260156020526040902054600160481b900416600903905061217f5761285b81613a59565b6001600160a01b0381166000908152601560205260409020546128929063ffffffff600160281b8204811691610100900416614cfa565b60008054601a906128b1908490600160d01b900463ffffffff16614f53565b92506101000a81548163ffffffff021916908363ffffffff160217905550505b50565b6001600160a01b0381166000908152601c602052604090205468056bc75e2d63100000116128d1576001600160a01b03818116600081815260156020526040808220805460ff191660011790556018549051633b0f0f2f60e01b8152600481019390935290921690633b0f0f2f90602401602060405180830381865afa158015612962573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129869190614d73565b90506001600160a01b0381161561217f576001600160a01b03811660009081526015602052604090208054600191906009906129d0908490600160481b900463ffffffff16614cfa565b82546101009290920a63ffffffff8181021990931691831602179091556001600160a01b038316600090815260156020526040902054600160481b900416600a03905061217f576001600160a01b038116600090815260156020526040902054612a4e9063ffffffff600160281b8204811691610100900416614cfa565b60008054601a906128b1908490600160d01b900463ffffffff16614cfa565b6000808260ff16600214612a82576000612a99565b6064612a8f856005614c6b565b612a999190614e2f565b6040516370a0823160e01b81523060048201529091506000906000805160206150ce833981519152906370a0823190602401602060405180830381865afa158015612ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b0c9190614c29565b6040805160028082526060820183529293506000929091602083019080368337505060175482519293506001600160a01b031691839150600090612b5257612b52614bc2565b60200260200101906001600160a01b031690816001600160a01b0316815250506000805160206150ce83398151915281600181518110612b9457612b94614bc2565b6001600160a01b03909216602092830291909101909101527310ed43c718714eb63d5aa57b78b54704e256024e638803dbee612bd0858a614e05565b6017546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015612c18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c3c9190614c29565b8430426040518663ffffffff1660e01b8152600401612c5f959493929190614f70565b6000604051808303816000875af1158015612c7e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ca69190810190614fe1565b508215612f5d57612cbb611940600585614e2f565b6000612cc8600585614e2f565b90506000601960009054906101000a90046001600160a01b03166001600160a01b031663c006719f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d439190614c29565b1115612e2e5760195460405163a9059cbb60e01b81526000805160206150ce8339815191529163a9059cbb91612d87916001600160a01b0316908590600401614c82565b6020604051808303816000875af1158015612da6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dca9190614c0e565b5060195460405163beceed3960e01b8152600481018390526001600160a01b039091169063beceed3990602401600060405180830381600087803b158015612e1157600080fd5b505af1158015612e25573d6000803e3d6000fd5b50505050612eba565b60405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb90612e7590731ae539ba18b0c9469ed03f08f3a2ea6fc5615db8908590600401614c82565b6020604051808303816000875af1158015612e94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eb89190614c0e565b505b6000805160206150ce83398151915263a9059cbb732986d00364d109e0139d1bc7623d905ca5e56f8b6005612ef0886003614c6b565b612efa9190614e2f565b6040518363ffffffff1660e01b8152600401612f17929190614c82565b6020604051808303816000875af1158015612f36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f5a9190614c0e565b50505b6040516370a0823160e01b815230600482015282906000805160206150ce833981519152906370a0823190602401602060405180830381865afa158015612fa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fcc9190614c29565b612fd69190614c58565b979650505050505050565b60008083831115612ff957612ff68484614c58565b90505b60185460008054604051631c8a1fb760e21b8152336004820152600160a81b90910460ff16602482015290916001600160a01b0316906372287edc90604401600060405180830381865afa158015613055573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261307d9190810190614ebf565b9050600061308c828488613aba565b9050600061309a3385614157565b905081612fcc8288614c58565b6001600160a01b038116600090815260156020526040902080546130df9063ffffffff600160281b8204811691610100900416614cfa565b63ffffffff16158061310057508054600a600160481b90910463ffffffff16105b15613109575050565b6001600160a01b0382166000908152601c60205260408120546001830154670de0b6b3a76400009161313a91614e05565b835461315a9063ffffffff600160281b8204811691610100900416614cfa565b63ffffffff1661316a9190614c6b565b6131749190614e2f565b6019546040516319765dc960e21b81529192506001600160a01b0316906365d97724906131a79086908590600401614c82565b600060405180830381600087803b1580156131c157600080fd5b505af1158015610c35573d6000803e3d6000fd5b60408051600280825260608201835260009260208301908036833750506040805160028082526060820183529394509291506020830190803683370190505090506000805160206150ce8339815191528160008151811061323857613238614bc2565b6001600160a01b03928316602091820292909201015260175482519116908290600190811061326957613269614bc2565b6001600160a01b0392831660209182029290920101526017546040516370a0823160e01b815230600482015260009291909116906370a0823190602401602060405180830381865afa1580156132c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132e79190614c29565b90507310ed43c718714eb63d5aa57b78b54704e256024e635c11d79561330e600287614e2f565b858530426040518663ffffffff1660e01b8152600401613332959493929190614f70565b600060405180830381600087803b15801561334c57600080fd5b505af1158015613360573d6000803e3d6000fd5b50506017546040516370a0823160e01b8152306004820152600093506001600160a01b0390911691506370a0823190602401602060405180830381865afa1580156133af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d39190614c29565b6017549091507310ed43c718714eb63d5aa57b78b54704e256024e9063e8e33700906000805160206150ce833981519152906001600160a01b031661341960028a614e2f565b6134238787614c58565b6040516001600160e01b031960e087901b1681526001600160a01b0394851660048201529390921660248401526044830152606482015260006084820181905260a4820181905260c48201524260e4820152610104016060604051808303816000875af1158015613498573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134bc9190615067565b5050505050505050565b6040805160808101825260009181018290524264ffffffffff1681526001600160a01b038416602082015260ff83166060820152601b80549192859261350d908490614e05565b90915550506001600160a01b0384166000908152601c60205260408120805485929061353a908490614e05565b909155506135499050846126f0565b6001600160a01b038481166000818152601660209081526040808320805460018101825581855283852088519082018054958a01518a86015160608c015164ffffffffff9094166001600160c81b031990981697909717600160281b918b16919091021761ffff60c81b1916600160c81b9615159690960260ff60d01b191695909517600160d01b60ff928316021790945560185485549351631c8a1fb760e21b81526004810197909752600160a81b90930490931660248601529491939116906372287edc90604401600060405180830381865afa158015613630573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136589190810190614ebf565b905060005b81518160ff16101561381e576000828260ff168151811061368057613680614bc2565b6020908102919091018101516001600160a01b038116600090815260159092526040909120600101549091506136b68982614e05565b6001600160a01b03831660009081526015602052604090206001018190556136dd836130a7565b600185516136eb9190614c58565b8460ff16106136fc5750505061381e565b60008561370a866001615095565b60ff168151811061371d5761371d614bc2565b602002602001015190506000600590505b60028110613806576007816006811061374957613749614bc2565b0154831015801561376d57506007816006811061376857613768614bc2565b015484105b156137f4576001600160a01b0382166000908152601460205260409020600190826006811061379e5761379e614bc2565b600891828204019190066004028282829054906101000a900463ffffffff166137c79190614cfa565b92506101000a81548163ffffffff021916908363ffffffff1602179055506137ef8282614321565b613806565b806137fe81614e18565b91505061372e565b50505050508080613816906150ae565b91505061365d565b506040518681526001600160a01b038816906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3866001600160a01b03167f9cfd25589d1eb8ad71e342a86a8524e83522e3936c0803048c08f6d9ad974f4087428560018a60ff16600381106138a4576138a4614bc2565b015460408051948552602085019390935291830152606082015260800160405180910390a250505050505050565b60408051600280825260608201835260009260208301908036833750506040805160028082526060820183529394509291506020830190803683370190505090506000805160206150ce8339815191528160008151811061393557613935614bc2565b6001600160a01b03928316602091820292909201015260175482519116908290600190811061396657613966614bc2565b6001600160a01b0390921660209283029190910190910152604051635c11d79560e01b81527310ed43c718714eb63d5aa57b78b54704e256024e90635c11d795906131a79086908690869061dead904290600401614f70565b60008164ffffffffff168364ffffffffff16106139dc57816139de565b825b9392505050565b60008281600184166139ff57670de0b6b3a7640000613a01565b815b9050600184901c93505b8315613a3f57613a1b828361451c565b91506001841615613a3357613a30818361451c565b90505b600184901c9350613a0b565b949350505050565b60006139de613a56848461451c565b90565b6019546040516319765dc960e21b81526001600160a01b03909116906365d9772490613a8c908490600090600401614c82565b600060405180830381600087803b158015613aa657600080fd5b505af1158015611ba3573d6000803e3d6000fd5b600080806014816064613acd8389614c6b565b613ad79190614e2f565b945060005b88518110156140a057888181518110613af757613af7614bc2565b6020908102919091018101516001600160a01b03811660009081526015909252604082206001015490965090888211613b31576000613b3b565b613b3b8983614c58565b6001600160a01b0388166000908152601560205260409020600181018290555490915060ff16613b6c57505061408e565b6001600160a01b038716600090815260156020526040902060010154600c549096508610801590613b9c57508385115b15613c40576000805160206150ce83398151915263a9059cbb886064613bc2888a614c58565b613bcc908f614c6b565b613bd69190614e2f565b6040518363ffffffff1660e01b8152600401613bf3929190614c82565b6020604051808303816000875af1158015613c12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c369190614c0e565b5060149350613e88565b600b548610801590613c535750600c5486105b8015613c5f5750601084105b15613d04576000805160206150ce83398151915263a9059cbb886064613c86886010614c58565b613c90908f614c6b565b613c9a9190614e2f565b6040518363ffffffff1660e01b8152600401613cb7929190614c82565b6020604051808303816000875af1158015613cd6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cfa9190614c0e565b5060109350613e88565b600a548610801590613d175750600b5486105b8015613d235750600c84105b15613dc8576000805160206150ce83398151915263a9059cbb886064613d4a88600c614c58565b613d54908f614c6b565b613d5e9190614e2f565b6040518363ffffffff1660e01b8152600401613d7b929190614c82565b6020604051808303816000875af1158015613d9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dbe9190614c0e565b50600c9350613e88565b6009548610801590613ddb5750600a5486105b8015613de75750600884105b15613e88576000805160206150ce83398151915263a9059cbb886064613e0e886008614c58565b613e18908f614c6b565b613e229190614e2f565b6040518363ffffffff1660e01b8152600401613e3f929190614c82565b6020604051808303816000875af1158015613e5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e829190614c0e565b50600893505b6008548610801590613e9b575060095486105b8015613ea75750600484105b15613f48576000805160206150ce83398151915263a9059cbb886064613ece886004614c58565b613ed8908f614c6b565b613ee29190614e2f565b6040518363ffffffff1660e01b8152600401613eff929190614c82565b6020604051808303816000875af1158015613f1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f429190614c0e565b50600493505b80600003613f5e57613f5987613a59565b613f67565b613f67876130a7565b60018b51613f759190614c58565b8310613f825750506140a0565b60008b613f90856001614e05565b81518110613fa057613fa0614bc2565b602002602001015190506000600590505b600281106140895760078160068110613fcc57613fcc614bc2565b015483108015613ff0575060078160068110613fea57613fea614bc2565b01548410155b15614077576001600160a01b0382166000908152601460205260409020600190826006811061402157614021614bc2565b600891828204019190066004028282829054906101000a900463ffffffff1661404a9190614f53565b92506101000a81548163ffffffff021916908363ffffffff16021790555061407282826145d2565b614089565b8061408181614e18565b915050613fb1565b505050505b8061409881614e51565b915050613adc565b508082111561153957601a546000805160206150ce8339815191529063a9059cbb906001600160a01b031660646140d7858c614c6b565b6140e19190614e2f565b6140eb9089614c58565b6040518363ffffffff1660e01b8152600401614108929190614c82565b6020604051808303816000875af1158015614127573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061414b9190614c0e565b50505050509392505050565b60006064614166836005614c6b565b6141709190614e2f565b601854604051633b0f0f2f60e01b81526001600160a01b03868116600483015292935060009290911690633b0f0f2f90602401602060405180830381865afa1580156141c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141e49190614d73565b90506001600160a01b0381161580159061421657506001600160a01b03811660009081526015602052604090205460ff165b156142975760405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb9061424e9084908690600401614c82565b6020604051808303816000875af115801561426d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142919190614c0e565b5061431a565b601a5460405163a9059cbb60e01b81526000805160206150ce8339815191529163a9059cbb916142d5916001600160a01b0316908690600401614c82565b6020604051808303816000875af11580156142f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143189190614c0e565b505b5092915050565b600d816006811061433457614334614bc2565b015415806143425750600281105b1561434b575050565b6001600160a01b038216600090815260136020908152604080832084845290915290205460ff161561437b575050565b6001600160a01b038216600090815260146020526040812082600681106143a4576143a4614bc2565b600891828204019190066004029054906101000a900463ffffffff1663ffffffff169050818103610e74576001600d83600681106143e4576143e4614bc2565b0160008282546143f49190614c58565b90915550506001600160a01b0383166000908152601560205260409020805460019190829061442f908290610100900463ffffffff16614cfa565b92506101000a81548163ffffffff021916908363ffffffff1602179055506001600060168282829054906101000a900463ffffffff1661446f9190614cfa565b82546101009290920a63ffffffff8181021990931691831602179091556001600160a01b03851660008181526013602090815260408083208884528252808320805460ff19166001179055928252601590522054600a600160481b909104909116109050610e745760016000601a8282829054906101000a900463ffffffff166144f99190614cfa565b92506101000a81548163ffffffff021916908363ffffffff160217905550505050565b60008080600019848609848602925082811083820303915050806000036145505750670de0b6b3a7640000900490506107c3565b670de0b6b3a7640000811061458257604051635173648d60e01b815260048101869052602481018590526044016107f3565b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b600d81600681106145e5576145e5614bc2565b0154604614806145f55750600281105b156145fe575050565b6001600160a01b038216600090815260136020908152604080832084845290915290205460ff1661462d575050565b6001600160a01b0382166000908152601460205260408120826006811061465657614656614bc2565b60088104919091015460079091166004026101000a900463ffffffff169050614680600183614c58565b8103610e74576001600d836006811061469b5761469b614bc2565b0160008282546146ab9190614e05565b90915550506001600160a01b038316600090815260156020526040902054610100900463ffffffff166146df57600061470f565b6001600160a01b03831660009081526015602052604090205461470f90600190610100900463ffffffff16614f53565b6001600160a01b0384166000908152601560205260408120805464ffffffff00191661010063ffffffff9485160217905554600160b01b900416614754576000614770565b60005461477090600190600160b01b900463ffffffff16614f53565b6000805463ffffffff60b01b1916600160b01b63ffffffff938416021781556001600160a01b038516815260156020526040812054610100900490911690036147bc576147bc83613a59565b6001600160a01b038316600090815260156020526040902054600a600160481b90910463ffffffff1610610e7457600054600160d01b900463ffffffff16614805576000614821565b60005461482190600190600160d01b900463ffffffff16614f53565b6000601a6101000a81548163ffffffff021916908363ffffffff160217905550505050565b6001600160a01b03811681146128d157600080fd5b6000806040838503121561486e57600080fd5b823561487981614846565b946020939093013593505050565b803560ff8116811461489857600080fd5b919050565b600080604083850312156148b057600080fd5b82356148bb81614846565b91506148c960208401614887565b90509250929050565b600060208083528351808285015260005b818110156148ff578581018301518582016040015282016148e3565b506000604082860101526040601f19601f8301168501019250505092915050565b60006020828403121561493257600080fd5b81356139de81614846565b60006020828403121561494f57600080fd5b5035919050565b6000806000806080858703121561496c57600080fd5b843593506020850135925061498360408601614887565b9150606085013561499381614846565b939692955090935050565b63ffffffff811681146128d157600080fd5b6000806000606084860312156149c557600080fd5b83356149d081614846565b925060208401356149e08161499e565b915060408401356149f08161499e565b809150509250925092565b602080825282518282018190526000919060409081850190868401855b82811015614a9b578151805163ffffffff1685528681015164ffffffffff1687860152858101516001600160a01b03168686015260608082015115159086015260808082015160ff169086015260a080820151614a7d8288018264ffffffffff169052565b505060c0908101519085015260e09093019290850190600101614a18565b5091979650505050505050565b600080600060608486031215614abd57600080fd5b8335925060208401359150614ad460408501614887565b90509250925092565b60008060208385031215614af057600080fd5b823567ffffffffffffffff80821115614b0857600080fd5b818501915085601f830112614b1c57600080fd5b813581811115614b2b57600080fd5b8660208260051b8501011115614b4057600080fd5b60209290920196919550909350505050565b602080825282518282018190526000919060409081850190868401855b82811015614a9b57815180516001600160a01b0316855286810151878601528501518585015260609093019290850190600101614b6f565b600060208284031215614bb957600080fd5b6139de82614887565b634e487b7160e01b600052603260045260246000fd5b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b8051801515811461489857600080fd5b600060208284031215614c2057600080fd5b6139de82614bfe565b600060208284031215614c3b57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b818103818111156107c3576107c3614c42565b80820281158282048414176107c3576107c3614c42565b6001600160a01b03929092168252602082015260400190565b600060208284031215614cad57600080fd5b81516001600160701b03811681146139de57600080fd5b60008060008060808587031215614cda57600080fd5b505082516020840151604085015160609095015191969095509092509050565b63ffffffff81811683821601908082111561431a5761431a614c42565b60008060008060808587031215614d2d57600080fd5b8451614d3881614846565b6020860151909450614d498161499e565b6040860151909350614d5a8161499e565b9150614d6860608601614bfe565b905092959194509250565b600060208284031215614d8557600080fd5b81516139de81614846565b634e487b7160e01b600052604160045260246000fd5b64ffffffffff81811683821601908082111561431a5761431a614c42565b64ffffffffff82811682821603908082111561431a5761431a614c42565b600063ffffffff808316818103614dfb57614dfb614c42565b6001019392505050565b808201808211156107c3576107c3614c42565b600081614e2757614e27614c42565b506000190190565b600082614e4c57634e487b7160e01b600052601260045260246000fd5b500490565b600060018201614e6357614e63614c42565b5060010190565b604051601f8201601f1916810167ffffffffffffffff81118282101715614e9357614e93614d90565b604052919050565b600067ffffffffffffffff821115614eb557614eb5614d90565b5060051b60200190565b60006020808385031215614ed257600080fd5b825167ffffffffffffffff811115614ee957600080fd5b8301601f81018513614efa57600080fd5b8051614f0d614f0882614e9b565b614e6a565b81815260059190911b82018301908381019087831115614f2c57600080fd5b928401925b82841015612fd6578351614f4481614846565b82529284019290840190614f31565b63ffffffff82811682821603908082111561431a5761431a614c42565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b81811015614fc05784516001600160a01b031683529383019391830191600101614f9b565b50506001600160a01b03969096166060850152505050608001529392505050565b60006020808385031215614ff457600080fd5b825167ffffffffffffffff81111561500b57600080fd5b8301601f8101851361501c57600080fd5b805161502a614f0882614e9b565b81815260059190911b8201830190838101908783111561504957600080fd5b928401925b82841015612fd65783518252928401929084019061504e565b60008060006060848603121561507c57600080fd5b8351925060208401519150604084015190509250925092565b60ff81811683821601908111156107c3576107c3614c42565b600060ff821660ff81036150c4576150c4614c42565b6001019291505056fe00000000000000000000000055d398326f99059ff775485246999027b3197955a26469706673582212209d38504355dd319b952c136a6530a23ccf4b3848957f54e110b1026b53ef735564736f6c6343000814003300000000000000000000000080472ca15f2b6a3ba29e18952e180d859c20e611

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102535760003560e01c80636f38e410116101465780639f18635e116100c3578063c999fea311610087578063c999fea3146106d0578063cc097076146106e7578063d04072b4146106fa578063f2fde38b1461070d578063f56d60b414610720578063fff6cae91461073357600080fd5b80639f18635e14610663578063a2f921c614610676578063b3caba5a146106a2578063be9a6555146106b5578063c63568c7146106bd57600080fd5b80638282b0151161010a5780638282b0151461060a5780638da5cb5b1461061d578063906e9dd01461063057806395d89b41146102a657806399fe39011461064357600080fd5b80636f38e4101461058e57806370a08231146105a2578063748e6856146105b557806375340815146105c857806381471bd0146105df57600080fd5b806333060d90116101d4578063544736e611610198578063544736e61461048c578063582115fb146104a05780636386c1c7146104f657806365ecbf661461055b57806367b524c81461057b57600080fd5b806333060d90146103e957806336255e071461041257806340b708c0146104255780634d5d08061461043857806353a273411461044057600080fd5b80631959a0021161021b5780631959a002146102e85780631d65168e1461037957806327e235e31461039c5780632e17de78146103bc578063313ce567146103cf57600080fd5b8063020b565d14610258578063069a8f2d1461028557806306fdde03146102a657806307da68f5146102d557806318160ddd146102df575b600080fd5b61026b61026636600461485b565b61073b565b60405163ffffffff90911681526020015b60405180910390f35b61029861029336600461489d565b61077a565b60405190815260200161027c565b6102c86040518060400160405280600381526020016242595360e81b81525081565b60405161027c91906148d2565b6102dd6107c9565b005b610298601b5481565b61033d6102f6366004614920565b60156020526000908152604090208054600182015460029092015460ff82169263ffffffff6101008404811693600160281b8104821693600160481b909104909116919086565b60408051961515875263ffffffff95861660208801529385169386019390935292166060840152608083019190915260a082015260c00161027c565b61038c610387366004614920565b61080b565b604051901515815260200161027c565b6102986103aa366004614920565b601c6020526000908152604090205481565b6102dd6103ca36600461493d565b61087a565b6103d7601281565b60405160ff909116815260200161027c565b6102986103f7366004614920565b6001600160a01b031660009081526016602052604090205490565b6102dd610420366004614956565b610c3e565b6102dd61043336600461485b565b610dd5565b610298610e79565b61045361044e36600461485b565b610fb9565b6040805164ffffffffff90951685526001600160a01b0390931660208501529015159183019190915260ff16606082015260800161027c565b60005461038c90600160a01b900460ff1681565b6104b36104ae366004614920565b611014565b6040805197885263ffffffff9687166020890152948616948701949094529184166060860152909216608084015260a083019190915260c082015260e00161027c565b610509610504366004614920565b611109565b6040805163ffffffff998a168152989097166020890152941515958701959095526060860192909252608085015260a084015260c08301919091526001600160a01b031660e08201526101000161027c565b61056e6105693660046149b0565b6112d3565b60405161027c91906149fb565b6102dd610589366004614920565b611544565b6000546103d790600160a81b900460ff1681565b6102986105b0366004614920565b611590565b6102dd6105c3366004614aa8565b611637565b60005461026b90600160d01b900463ffffffff1681565b6019546105f2906001600160a01b031681565b6040516001600160a01b03909116815260200161027c565b6102dd610618366004614add565b611baa565b6000546105f2906001600160a01b031681565b6102dd61063e366004614920565b611dc8565b6106566106513660046149b0565b611e14565b60405161027c9190614b52565b61029861067136600461493d565b612019565b610298610684366004614920565b6001600160a01b031660009081526015602052604090206001015490565b6102dd6106b0366004614920565b612030565b6102dd61207c565b6018546105f2906001600160a01b031681565b60005461026b90600160b01b900463ffffffff1681565b6017546105f2906001600160a01b031681565b6102dd610708366004614920565b6120bb565b6102dd61071b366004614920565b612183565b6102dd61072e366004614ba7565b6121f8565b6102dd612242565b6014602052816000526040600020816006811061075757600080fd5b60089182820401919006600402915091509054906101000a900463ffffffff1681565b6001600160a01b0382166000908152601660205260408120805482919060ff85169081106107aa576107aa614bc2565b9060005260206000200190506107bf816123fe565b9150505b92915050565b6000546001600160a01b031633146107fc5760405162461bcd60e51b81526004016107f390614bd8565b60405180910390fd5b6000805460ff60a01b19169055565b601854604051633bb1db8160e21b81526001600160a01b038381166004830152600092169063eec76e0490602401602060405180830381865afa158015610856573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107c39190614c0e565b3233146108b35760405162461bcd60e51b81526020600482015260076024820152664e6f7420454f4160c81b60448201526064016107f3565b60008060006108c18461249f565b9250925092506108d0336126f0565b60006108dd848484612a6d565b905060006108eb8483612fe1565b90506108f6336130a7565b60195460405163072e008f60e11b81523360048201526001600160a01b0390911690630e5c011e90602401600060405180830381600087803b15801561093b57600080fd5b505af115801561094f573d6000803e3d6000fd5b50506017546040516370a0823160e01b8152306004820152692a5a058fc295ed00000093506001600160a01b0390911691506370a0823190602401602060405180830381865afa1580156109a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109cb9190614c29565b1015610aaa576017546040516370a0823160e01b81523060048201526001600160a01b039091169063dd1c35bc9082906370a0823190602401602060405180830381865afa158015610a21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a459190614c29565b610a5990692a5a058fc295ed000000614c58565b6040518263ffffffff1660e01b8152600401610a7791815260200190565b600060405180830381600087803b158015610a9157600080fd5b505af1158015610aa5573d6000803e3d6000fd5b505050505b8260ff16600203610bbf576000610ac283600a614c6b565b6040516370a0823160e01b8152306004820152909150819073d1c5840e565f7350a893cd036367f639cb66b75f906370a0823190602401602060405180830381865afa158015610b16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3a9190614c29565b10610bbd5760405163a9059cbb60e01b815273d1c5840e565f7350a893cd036367f639cb66b75f9063a9059cbb90610b789033908590600401614c82565b6020604051808303816000875af1158015610b97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bbb9190614c0e565b505b505b60405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb90610bf29033908590600401614c82565b6020604051808303816000875af1158015610c11573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c359190614c0e565b50505050505050565b323314610c775760405162461bcd60e51b81526020600482015260076024820152664e6f7420454f4160c81b60448201526064016107f3565b601854604051633bb1db8160e21b81523360048201526001600160a01b039091169063eec76e0490602401602060405180830381865afa158015610cbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce39190614c0e565b158015610d595750601854604051633bb1db8160e21b81526001600160a01b0383811660048301529091169063eec76e0490602401602060405180830381865afa158015610d35573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d599190614c0e565b15610dc457601854604051631ea690cf60e21b81526001600160a01b03838116600483015233602483015290911690637a9a433c90604401600060405180830381600087803b158015610dab57600080fd5b505af1158015610dbf573d6000803e3d6000fd5b505050505b610dcf848484611637565b50505050565b6000546001600160a01b03163314610dff5760405162461bcd60e51b81526004016107f390614bd8565b60175460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90610e319085908590600401614c82565b6020604051808303816000875af1158015610e50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e749190614c0e565b505050565b600080601760009054906101000a90046001600160a01b03166001600160a01b0316631542609b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ecf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef39190614c9b565b905069d3c21bcecceda1000000816001600160701b03161015610f2057683635c9adc5dea0000091505090565b6a027b46536c66c8e3000000816001600160701b03161015610f4c5768a2a15d09519be0000091505090565b6a084595161401484a000000816001600160701b03161015610f795769010f0cf064dd5920000091505090565b6a108b2a2c28029094000000816001600160701b03161015610fa65769021e19e0c9bab240000091505090565b6b033b2e3c9fd0803ce800000091505090565b60166020528160005260406000208181548110610fd557600080fd5b60009182526020909120015464ffffffffff811692506001600160a01b03600160281b820416915060ff600160c81b8204811691600160d01b90041684565b60195460405160016222a30f60e01b031981526001600160a01b038381166004830152600092839283928392839283928392169063ffdd5cf190602401608060405180830381865afa15801561106e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110929190614cc4565b600080546001600160a01b038e168252601560205260409091208054959c5063ffffffff600160b01b830481169c50600160d01b90920482169a50600160481b86048216995092965090945090926110fb9250600160281b810482169161010090910416614cfa565b935050919395979092949650565b60185460405160016222a30f60e01b031981526001600160a01b038381166004830152600092839283928392839283928392839291169063ffdd5cf190602401608060405180830381865afa158015611166573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118a9190614d17565b6001600160a01b038d166000818152601c6020526040908190205490516370a0823160e01b81526004810192909252939c50919a5098509096503091506370a0823190602401602060405180830381865afa1580156111ed573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112119190614c29565b92508461121c610e79565b1161122857600061123b565b84611231610e79565b61123b9190614c58565b6001600160a01b038a81166000818152601560205260409081902060018101546018549251633b0f0f2f60e01b81526004810194909452985093955090911690633b0f0f2f90602401602060405180830381865afa1580156112a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c59190614d73565b915050919395975091939597565b6001600160a01b0383166000908152601660205260408120805460609263ffffffff861615806113115750816113098787614cfa565b63ffffffff16115b1561134257818563ffffffff161061132b5750600061134b565b61133b63ffffffff861683614c58565b905061134b565b5063ffffffff85165b8067ffffffffffffffff81111561136457611364614d90565b6040519080825280602002602001820160405280156113cb57816020015b6040805160e08101825260008082526020808301829052928201819052606082018190526080820181905260a0820181905260c082015282526000199092019101816113825790505b50935060005b818163ffffffff161015611539576000846113ec8389614cfa565b63ffffffff168154811061140257611402614bc2565b600091825260208220018054909250600160c81b900460ff161515810361148557815464ffffffffff811690600090600190600160d01b900460ff166003811061144e5761144e614bc2565b015490504261145d8383614da6565b64ffffffffff16111561148257426114758383614da6565b61147f9190614dc4565b92505b50505b6040518060e00160405280848a61149c9190614cfa565b63ffffffff168152835464ffffffffff80821660208401526001600160a01b03600160281b830416604084015260ff600160c81b8304811615156060850152600160d01b9092049091166080830152831660a082015260c0016114fe846123fe565b815250878463ffffffff168151811061151957611519614bc2565b60200260200101819052505050808061153190614de2565b9150506113d1565b505050509392505050565b6000546001600160a01b0316331461156e5760405162461bcd60e51b81526004016107f390614bd8565b601980546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b03811660009081526016602052604081208054156116315780546000906115c090600190614c58565b90505b60008282815481106115d7576115d7614bc2565b600091825260208220018054909250600160c81b900460ff161515900361160e57611601816123fe565b61160b9085614e05565b93505b8160000361161c575061162f565b508061162781614e18565b9150506115c3565b505b50919050565b600054600160a01b900460ff166116875760405162461bcd60e51b815260206004820152601460248201527314dd185ada5b99ce881b9bdd081cdd185c9d195960621b60448201526064016107f3565b601854604051633bb1db8160e21b81523360048201526001600160a01b039091169063eec76e0490602401602060405180830381865afa1580156116cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116f39190614c0e565b6117335760405162461bcd60e51b8152602060048201526011602482015270139bc81c9959995c9c995c88189bdd5b99607a1b60448201526064016107f3565b600061173d610e79565b336000908152601c6020526040902054909150819061175d908690614e05565b11156117ab5760405162461bcd60e51b815260206004820181905260248201527f5374616b696e6720616d6f756e742063616e6e6f7420657863656564206d617860448201526064016107f3565b683635c9adc5dea0000084111561180e5760405162461bcd60e51b815260206004820152602160248201527f5374616b696e6720616d6f756e742063616e6e6f7420657863656564203130306044820152600360fc1b60648201526084016107f3565b60028260ff16111561185b5760405162461bcd60e51b8152602060048201526016602482015275496e636f7272656374207374616b696e67207479706560501b60448201526064016107f3565b6040516323b872dd60e01b8152336004820152306024820152604481018590526000805160206150ce833981519152906323b872dd906064016020604051808303816000875af11580156118b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d79190614c0e565b5060008260ff166002146118ec576000611903565b60646118f9866005614c6b565b6119039190614e2f565b90506119186119128287614c58565b856131d5565b6119233386856134c6565b61192c336130a7565b8015611ba357611947611940600583614e2f565b60006138d2565b6000611954600583614e2f565b90506000601960009054906101000a90046001600160a01b03166001600160a01b031663c006719f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119cf9190614c29565b1115611aba5760195460405163a9059cbb60e01b81526000805160206150ce8339815191529163a9059cbb91611a13916001600160a01b0316908590600401614c82565b6020604051808303816000875af1158015611a32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a569190614c0e565b5060195460405163beceed3960e01b8152600481018390526001600160a01b039091169063beceed3990602401600060405180830381600087803b158015611a9d57600080fd5b505af1158015611ab1573d6000803e3d6000fd5b50505050611b46565b60405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb90611b0190731ae539ba18b0c9469ed03f08f3a2ea6fc5615db8908590600401614c82565b6020604051808303816000875af1158015611b20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b449190614c0e565b505b6000805160206150ce83398151915263a9059cbb731ae539ba18b0c9469ed03f08f3a2ea6fc5615db86005611b7c866003614c6b565b611b869190614e2f565b6040518363ffffffff1660e01b8152600401610bf2929190614c82565b5050505050565b6000546001600160a01b03163314611bd45760405162461bcd60e51b81526004016107f390614bd8565b60005b81811015610e745760156000848484818110611bf557611bf5614bc2565b9050602002016020810190611c0a9190614920565b6001600160a01b03168152602081019190915260400160002054600160281b900463ffffffff1615611c745760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60448201526064016107f3565b6017546001600160a01b031663a9059cbb848484818110611c9757611c97614bc2565b9050602002016020810190611cac9190614920565b681b1ae4d6e2ef5000006040518363ffffffff1660e01b8152600401611cd3929190614c82565b6020604051808303816000875af1158015611cf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d169190614c0e565b50600160156000858585818110611d2f57611d2f614bc2565b9050602002016020810190611d449190614920565b6001600160a01b0316815260208101919091526040016000908120805468ffffffff00000000001916600160281b63ffffffff948516021790558054600192601691611d99918591600160b01b900416614cfa565b92506101000a81548163ffffffff021916908363ffffffff16021790555080611dc190614e51565b9050611bd7565b6000546001600160a01b03163314611df25760405162461bcd60e51b81526004016107f390614bd8565b601a80546001600160a01b0319166001600160a01b0392909216919091179055565b601854604051631d98022360e01b81526001600160a01b03858116600483015263ffffffff808616602484015284166044830152606092600092911690631d98022390606401600060405180830381865afa158015611e77573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611e9f9190810190614ebf565b90506000815167ffffffffffffffff811115611ebd57611ebd614d90565b604051908082528060200260200182016040528015611f1b57816020015b611f08604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b815260200190600190039081611edb5790505b50905060005b825181101561200f576040518060600160405280848381518110611f4757611f47614bc2565b60200260200101516001600160a01b03168152602001611f98858481518110611f7257611f72614bc2565b60200260200101516001600160a01b031660009081526015602052604090206001015490565b8152602001601c6000868581518110611fb357611fb3614bc2565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054815250828281518110611ff157611ff1614bc2565b6020026020010181905250808061200790614e51565b915050611f21565b5095945050505050565b600d816006811061202957600080fd5b0154905081565b6000546001600160a01b0316331461205a5760405162461bcd60e51b81526004016107f390614bd8565b601880546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031633146120a65760405162461bcd60e51b81526004016107f390614bd8565b6000805460ff60a01b1916600160a01b179055565b6000546001600160a01b031633146120e55760405162461bcd60e51b81526004016107f390614bd8565b601780546001600160a01b0319166001600160a01b03831690811790915560405163095ea7b360e01b815263095ea7b39061213c907310ed43c718714eb63d5aa57b78b54704e256024e9060001990600401614c82565b6020604051808303816000875af115801561215b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061217f9190614c0e565b5050565b6000546001600160a01b031633146121ad5760405162461bcd60e51b81526004016107f390614bd8565b600080546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b6000546001600160a01b031633146122225760405162461bcd60e51b81526004016107f390614bd8565b6000805460ff909216600160a81b0260ff60a81b19909216919091179055565b6040516370a0823160e01b81523060048201526000906000805160206150ce833981519152906370a0823190602401602060405180830381865afa15801561228e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b29190614c29565b90506000601760009054906101000a90046001600160a01b03166001600160a01b03166349bd5a5e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612309573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061232d9190614d73565b60405163a9059cbb60e01b81529091506000805160206150ce8339815191529063a9059cbb906123639084908690600401614c82565b6020604051808303816000875af1158015612382573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a69190614c0e565b50806001600160a01b031663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156123e257600080fd5b505af11580156123f6573d6000803e3d6000fd5b505050505050565b80546000906001600160a01b03600160281b8204169064ffffffffff16826124268242614dc4565b90506124358162278d006139bf565b90508064ffffffffff1660000361244e57829350612497565b84546124949061248d9064ffffffffff84169061248790600490600160d01b900460ff166003811061248257612482614bc2565b015490565b906139e5565b8490613a47565b93505b505050919050565b33600081815260166020526040812080549192839283928391879081106124c8576124c8614bc2565b6000918252602090912001805460ff600160d01b820416945090915064ffffffffff16600184600381106124fe576124fe614bc2565b015461250a8242614c58565b10156125505760405162461bcd60e51b8152602060048201526015602482015274151a19481d1a5b59481a5cc81b9bdd081c9a59da1d605a1b60448201526064016107f3565b8154600160c81b900460ff161561259c5760405162461bcd60e51b815260206004820152601060248201526f756e7374616b656420616c726561647960801b60448201526064016107f3565b8154601b8054600160281b9092046001600160a01b0316965086916000906125c5908490614c58565b90915550506001600160a01b0383166000908152601c6020526040812080548792906125f2908490614c58565b90915550506040518581526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3612641826123fe565b825460ff60c81b1916600160c81b1783556001600160a01b03841660009081526015602052604090206002015490965061267c906001614e05565b6001600160a01b03841660008181526015602090815260409182902060020193909355805189815264ffffffffff4216938101939093528201899052907f569d6dbbe8a026a1e17ebab5d7c373f2b81a8a4d7f3fef0d2a5ed744d231a8b89060600160405180910390a25050509193909250565b6001600160a01b03811660009081526015602052604090205460ff16156128d4576001600160a01b0381166000908152601c602052604090205468056bc75e2d6310000011156128d1576001600160a01b03818116600081815260156020526040808220805460ff191690556018549051633b0f0f2f60e01b8152600481019390935290921690633b0f0f2f90602401602060405180830381865afa15801561279d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127c19190614d73565b90506001600160a01b0381161561217f576001600160a01b038116600090815260156020526040902080546001919060099061280b908490600160481b900463ffffffff16614f53565b82546101009290920a63ffffffff8181021990931691831602179091556001600160a01b038316600090815260156020526040902054600160481b900416600903905061217f5761285b81613a59565b6001600160a01b0381166000908152601560205260409020546128929063ffffffff600160281b8204811691610100900416614cfa565b60008054601a906128b1908490600160d01b900463ffffffff16614f53565b92506101000a81548163ffffffff021916908363ffffffff160217905550505b50565b6001600160a01b0381166000908152601c602052604090205468056bc75e2d63100000116128d1576001600160a01b03818116600081815260156020526040808220805460ff191660011790556018549051633b0f0f2f60e01b8152600481019390935290921690633b0f0f2f90602401602060405180830381865afa158015612962573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129869190614d73565b90506001600160a01b0381161561217f576001600160a01b03811660009081526015602052604090208054600191906009906129d0908490600160481b900463ffffffff16614cfa565b82546101009290920a63ffffffff8181021990931691831602179091556001600160a01b038316600090815260156020526040902054600160481b900416600a03905061217f576001600160a01b038116600090815260156020526040902054612a4e9063ffffffff600160281b8204811691610100900416614cfa565b60008054601a906128b1908490600160d01b900463ffffffff16614cfa565b6000808260ff16600214612a82576000612a99565b6064612a8f856005614c6b565b612a999190614e2f565b6040516370a0823160e01b81523060048201529091506000906000805160206150ce833981519152906370a0823190602401602060405180830381865afa158015612ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b0c9190614c29565b6040805160028082526060820183529293506000929091602083019080368337505060175482519293506001600160a01b031691839150600090612b5257612b52614bc2565b60200260200101906001600160a01b031690816001600160a01b0316815250506000805160206150ce83398151915281600181518110612b9457612b94614bc2565b6001600160a01b03909216602092830291909101909101527310ed43c718714eb63d5aa57b78b54704e256024e638803dbee612bd0858a614e05565b6017546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015612c18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c3c9190614c29565b8430426040518663ffffffff1660e01b8152600401612c5f959493929190614f70565b6000604051808303816000875af1158015612c7e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ca69190810190614fe1565b508215612f5d57612cbb611940600585614e2f565b6000612cc8600585614e2f565b90506000601960009054906101000a90046001600160a01b03166001600160a01b031663c006719f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612d1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d439190614c29565b1115612e2e5760195460405163a9059cbb60e01b81526000805160206150ce8339815191529163a9059cbb91612d87916001600160a01b0316908590600401614c82565b6020604051808303816000875af1158015612da6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dca9190614c0e565b5060195460405163beceed3960e01b8152600481018390526001600160a01b039091169063beceed3990602401600060405180830381600087803b158015612e1157600080fd5b505af1158015612e25573d6000803e3d6000fd5b50505050612eba565b60405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb90612e7590731ae539ba18b0c9469ed03f08f3a2ea6fc5615db8908590600401614c82565b6020604051808303816000875af1158015612e94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eb89190614c0e565b505b6000805160206150ce83398151915263a9059cbb732986d00364d109e0139d1bc7623d905ca5e56f8b6005612ef0886003614c6b565b612efa9190614e2f565b6040518363ffffffff1660e01b8152600401612f17929190614c82565b6020604051808303816000875af1158015612f36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f5a9190614c0e565b50505b6040516370a0823160e01b815230600482015282906000805160206150ce833981519152906370a0823190602401602060405180830381865afa158015612fa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fcc9190614c29565b612fd69190614c58565b979650505050505050565b60008083831115612ff957612ff68484614c58565b90505b60185460008054604051631c8a1fb760e21b8152336004820152600160a81b90910460ff16602482015290916001600160a01b0316906372287edc90604401600060405180830381865afa158015613055573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261307d9190810190614ebf565b9050600061308c828488613aba565b9050600061309a3385614157565b905081612fcc8288614c58565b6001600160a01b038116600090815260156020526040902080546130df9063ffffffff600160281b8204811691610100900416614cfa565b63ffffffff16158061310057508054600a600160481b90910463ffffffff16105b15613109575050565b6001600160a01b0382166000908152601c60205260408120546001830154670de0b6b3a76400009161313a91614e05565b835461315a9063ffffffff600160281b8204811691610100900416614cfa565b63ffffffff1661316a9190614c6b565b6131749190614e2f565b6019546040516319765dc960e21b81529192506001600160a01b0316906365d97724906131a79086908590600401614c82565b600060405180830381600087803b1580156131c157600080fd5b505af1158015610c35573d6000803e3d6000fd5b60408051600280825260608201835260009260208301908036833750506040805160028082526060820183529394509291506020830190803683370190505090506000805160206150ce8339815191528160008151811061323857613238614bc2565b6001600160a01b03928316602091820292909201015260175482519116908290600190811061326957613269614bc2565b6001600160a01b0392831660209182029290920101526017546040516370a0823160e01b815230600482015260009291909116906370a0823190602401602060405180830381865afa1580156132c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132e79190614c29565b90507310ed43c718714eb63d5aa57b78b54704e256024e635c11d79561330e600287614e2f565b858530426040518663ffffffff1660e01b8152600401613332959493929190614f70565b600060405180830381600087803b15801561334c57600080fd5b505af1158015613360573d6000803e3d6000fd5b50506017546040516370a0823160e01b8152306004820152600093506001600160a01b0390911691506370a0823190602401602060405180830381865afa1580156133af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d39190614c29565b6017549091507310ed43c718714eb63d5aa57b78b54704e256024e9063e8e33700906000805160206150ce833981519152906001600160a01b031661341960028a614e2f565b6134238787614c58565b6040516001600160e01b031960e087901b1681526001600160a01b0394851660048201529390921660248401526044830152606482015260006084820181905260a4820181905260c48201524260e4820152610104016060604051808303816000875af1158015613498573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134bc9190615067565b5050505050505050565b6040805160808101825260009181018290524264ffffffffff1681526001600160a01b038416602082015260ff83166060820152601b80549192859261350d908490614e05565b90915550506001600160a01b0384166000908152601c60205260408120805485929061353a908490614e05565b909155506135499050846126f0565b6001600160a01b038481166000818152601660209081526040808320805460018101825581855283852088519082018054958a01518a86015160608c015164ffffffffff9094166001600160c81b031990981697909717600160281b918b16919091021761ffff60c81b1916600160c81b9615159690960260ff60d01b191695909517600160d01b60ff928316021790945560185485549351631c8a1fb760e21b81526004810197909752600160a81b90930490931660248601529491939116906372287edc90604401600060405180830381865afa158015613630573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526136589190810190614ebf565b905060005b81518160ff16101561381e576000828260ff168151811061368057613680614bc2565b6020908102919091018101516001600160a01b038116600090815260159092526040909120600101549091506136b68982614e05565b6001600160a01b03831660009081526015602052604090206001018190556136dd836130a7565b600185516136eb9190614c58565b8460ff16106136fc5750505061381e565b60008561370a866001615095565b60ff168151811061371d5761371d614bc2565b602002602001015190506000600590505b60028110613806576007816006811061374957613749614bc2565b0154831015801561376d57506007816006811061376857613768614bc2565b015484105b156137f4576001600160a01b0382166000908152601460205260409020600190826006811061379e5761379e614bc2565b600891828204019190066004028282829054906101000a900463ffffffff166137c79190614cfa565b92506101000a81548163ffffffff021916908363ffffffff1602179055506137ef8282614321565b613806565b806137fe81614e18565b91505061372e565b50505050508080613816906150ae565b91505061365d565b506040518681526001600160a01b038816906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3866001600160a01b03167f9cfd25589d1eb8ad71e342a86a8524e83522e3936c0803048c08f6d9ad974f4087428560018a60ff16600381106138a4576138a4614bc2565b015460408051948552602085019390935291830152606082015260800160405180910390a250505050505050565b60408051600280825260608201835260009260208301908036833750506040805160028082526060820183529394509291506020830190803683370190505090506000805160206150ce8339815191528160008151811061393557613935614bc2565b6001600160a01b03928316602091820292909201015260175482519116908290600190811061396657613966614bc2565b6001600160a01b0390921660209283029190910190910152604051635c11d79560e01b81527310ed43c718714eb63d5aa57b78b54704e256024e90635c11d795906131a79086908690869061dead904290600401614f70565b60008164ffffffffff168364ffffffffff16106139dc57816139de565b825b9392505050565b60008281600184166139ff57670de0b6b3a7640000613a01565b815b9050600184901c93505b8315613a3f57613a1b828361451c565b91506001841615613a3357613a30818361451c565b90505b600184901c9350613a0b565b949350505050565b60006139de613a56848461451c565b90565b6019546040516319765dc960e21b81526001600160a01b03909116906365d9772490613a8c908490600090600401614c82565b600060405180830381600087803b158015613aa657600080fd5b505af1158015611ba3573d6000803e3d6000fd5b600080806014816064613acd8389614c6b565b613ad79190614e2f565b945060005b88518110156140a057888181518110613af757613af7614bc2565b6020908102919091018101516001600160a01b03811660009081526015909252604082206001015490965090888211613b31576000613b3b565b613b3b8983614c58565b6001600160a01b0388166000908152601560205260409020600181018290555490915060ff16613b6c57505061408e565b6001600160a01b038716600090815260156020526040902060010154600c549096508610801590613b9c57508385115b15613c40576000805160206150ce83398151915263a9059cbb886064613bc2888a614c58565b613bcc908f614c6b565b613bd69190614e2f565b6040518363ffffffff1660e01b8152600401613bf3929190614c82565b6020604051808303816000875af1158015613c12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c369190614c0e565b5060149350613e88565b600b548610801590613c535750600c5486105b8015613c5f5750601084105b15613d04576000805160206150ce83398151915263a9059cbb886064613c86886010614c58565b613c90908f614c6b565b613c9a9190614e2f565b6040518363ffffffff1660e01b8152600401613cb7929190614c82565b6020604051808303816000875af1158015613cd6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cfa9190614c0e565b5060109350613e88565b600a548610801590613d175750600b5486105b8015613d235750600c84105b15613dc8576000805160206150ce83398151915263a9059cbb886064613d4a88600c614c58565b613d54908f614c6b565b613d5e9190614e2f565b6040518363ffffffff1660e01b8152600401613d7b929190614c82565b6020604051808303816000875af1158015613d9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dbe9190614c0e565b50600c9350613e88565b6009548610801590613ddb5750600a5486105b8015613de75750600884105b15613e88576000805160206150ce83398151915263a9059cbb886064613e0e886008614c58565b613e18908f614c6b565b613e229190614e2f565b6040518363ffffffff1660e01b8152600401613e3f929190614c82565b6020604051808303816000875af1158015613e5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e829190614c0e565b50600893505b6008548610801590613e9b575060095486105b8015613ea75750600484105b15613f48576000805160206150ce83398151915263a9059cbb886064613ece886004614c58565b613ed8908f614c6b565b613ee29190614e2f565b6040518363ffffffff1660e01b8152600401613eff929190614c82565b6020604051808303816000875af1158015613f1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f429190614c0e565b50600493505b80600003613f5e57613f5987613a59565b613f67565b613f67876130a7565b60018b51613f759190614c58565b8310613f825750506140a0565b60008b613f90856001614e05565b81518110613fa057613fa0614bc2565b602002602001015190506000600590505b600281106140895760078160068110613fcc57613fcc614bc2565b015483108015613ff0575060078160068110613fea57613fea614bc2565b01548410155b15614077576001600160a01b0382166000908152601460205260409020600190826006811061402157614021614bc2565b600891828204019190066004028282829054906101000a900463ffffffff1661404a9190614f53565b92506101000a81548163ffffffff021916908363ffffffff16021790555061407282826145d2565b614089565b8061408181614e18565b915050613fb1565b505050505b8061409881614e51565b915050613adc565b508082111561153957601a546000805160206150ce8339815191529063a9059cbb906001600160a01b031660646140d7858c614c6b565b6140e19190614e2f565b6140eb9089614c58565b6040518363ffffffff1660e01b8152600401614108929190614c82565b6020604051808303816000875af1158015614127573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061414b9190614c0e565b50505050509392505050565b60006064614166836005614c6b565b6141709190614e2f565b601854604051633b0f0f2f60e01b81526001600160a01b03868116600483015292935060009290911690633b0f0f2f90602401602060405180830381865afa1580156141c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141e49190614d73565b90506001600160a01b0381161580159061421657506001600160a01b03811660009081526015602052604090205460ff165b156142975760405163a9059cbb60e01b81526000805160206150ce8339815191529063a9059cbb9061424e9084908690600401614c82565b6020604051808303816000875af115801561426d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142919190614c0e565b5061431a565b601a5460405163a9059cbb60e01b81526000805160206150ce8339815191529163a9059cbb916142d5916001600160a01b0316908690600401614c82565b6020604051808303816000875af11580156142f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143189190614c0e565b505b5092915050565b600d816006811061433457614334614bc2565b015415806143425750600281105b1561434b575050565b6001600160a01b038216600090815260136020908152604080832084845290915290205460ff161561437b575050565b6001600160a01b038216600090815260146020526040812082600681106143a4576143a4614bc2565b600891828204019190066004029054906101000a900463ffffffff1663ffffffff169050818103610e74576001600d83600681106143e4576143e4614bc2565b0160008282546143f49190614c58565b90915550506001600160a01b0383166000908152601560205260409020805460019190829061442f908290610100900463ffffffff16614cfa565b92506101000a81548163ffffffff021916908363ffffffff1602179055506001600060168282829054906101000a900463ffffffff1661446f9190614cfa565b82546101009290920a63ffffffff8181021990931691831602179091556001600160a01b03851660008181526013602090815260408083208884528252808320805460ff19166001179055928252601590522054600a600160481b909104909116109050610e745760016000601a8282829054906101000a900463ffffffff166144f99190614cfa565b92506101000a81548163ffffffff021916908363ffffffff160217905550505050565b60008080600019848609848602925082811083820303915050806000036145505750670de0b6b3a7640000900490506107c3565b670de0b6b3a7640000811061458257604051635173648d60e01b815260048101869052602481018590526044016107f3565b6000670de0b6b3a764000085870962040000818503049310909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690291505092915050565b600d81600681106145e5576145e5614bc2565b0154604614806145f55750600281105b156145fe575050565b6001600160a01b038216600090815260136020908152604080832084845290915290205460ff1661462d575050565b6001600160a01b0382166000908152601460205260408120826006811061465657614656614bc2565b60088104919091015460079091166004026101000a900463ffffffff169050614680600183614c58565b8103610e74576001600d836006811061469b5761469b614bc2565b0160008282546146ab9190614e05565b90915550506001600160a01b038316600090815260156020526040902054610100900463ffffffff166146df57600061470f565b6001600160a01b03831660009081526015602052604090205461470f90600190610100900463ffffffff16614f53565b6001600160a01b0384166000908152601560205260408120805464ffffffff00191661010063ffffffff9485160217905554600160b01b900416614754576000614770565b60005461477090600190600160b01b900463ffffffff16614f53565b6000805463ffffffff60b01b1916600160b01b63ffffffff938416021781556001600160a01b038516815260156020526040812054610100900490911690036147bc576147bc83613a59565b6001600160a01b038316600090815260156020526040902054600a600160481b90910463ffffffff1610610e7457600054600160d01b900463ffffffff16614805576000614821565b60005461482190600190600160d01b900463ffffffff16614f53565b6000601a6101000a81548163ffffffff021916908363ffffffff160217905550505050565b6001600160a01b03811681146128d157600080fd5b6000806040838503121561486e57600080fd5b823561487981614846565b946020939093013593505050565b803560ff8116811461489857600080fd5b919050565b600080604083850312156148b057600080fd5b82356148bb81614846565b91506148c960208401614887565b90509250929050565b600060208083528351808285015260005b818110156148ff578581018301518582016040015282016148e3565b506000604082860101526040601f19601f8301168501019250505092915050565b60006020828403121561493257600080fd5b81356139de81614846565b60006020828403121561494f57600080fd5b5035919050565b6000806000806080858703121561496c57600080fd5b843593506020850135925061498360408601614887565b9150606085013561499381614846565b939692955090935050565b63ffffffff811681146128d157600080fd5b6000806000606084860312156149c557600080fd5b83356149d081614846565b925060208401356149e08161499e565b915060408401356149f08161499e565b809150509250925092565b602080825282518282018190526000919060409081850190868401855b82811015614a9b578151805163ffffffff1685528681015164ffffffffff1687860152858101516001600160a01b03168686015260608082015115159086015260808082015160ff169086015260a080820151614a7d8288018264ffffffffff169052565b505060c0908101519085015260e09093019290850190600101614a18565b5091979650505050505050565b600080600060608486031215614abd57600080fd5b8335925060208401359150614ad460408501614887565b90509250925092565b60008060208385031215614af057600080fd5b823567ffffffffffffffff80821115614b0857600080fd5b818501915085601f830112614b1c57600080fd5b813581811115614b2b57600080fd5b8660208260051b8501011115614b4057600080fd5b60209290920196919550909350505050565b602080825282518282018190526000919060409081850190868401855b82811015614a9b57815180516001600160a01b0316855286810151878601528501518585015260609093019290850190600101614b6f565b600060208284031215614bb957600080fd5b6139de82614887565b634e487b7160e01b600052603260045260246000fd5b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b8051801515811461489857600080fd5b600060208284031215614c2057600080fd5b6139de82614bfe565b600060208284031215614c3b57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b818103818111156107c3576107c3614c42565b80820281158282048414176107c3576107c3614c42565b6001600160a01b03929092168252602082015260400190565b600060208284031215614cad57600080fd5b81516001600160701b03811681146139de57600080fd5b60008060008060808587031215614cda57600080fd5b505082516020840151604085015160609095015191969095509092509050565b63ffffffff81811683821601908082111561431a5761431a614c42565b60008060008060808587031215614d2d57600080fd5b8451614d3881614846565b6020860151909450614d498161499e565b6040860151909350614d5a8161499e565b9150614d6860608601614bfe565b905092959194509250565b600060208284031215614d8557600080fd5b81516139de81614846565b634e487b7160e01b600052604160045260246000fd5b64ffffffffff81811683821601908082111561431a5761431a614c42565b64ffffffffff82811682821603908082111561431a5761431a614c42565b600063ffffffff808316818103614dfb57614dfb614c42565b6001019392505050565b808201808211156107c3576107c3614c42565b600081614e2757614e27614c42565b506000190190565b600082614e4c57634e487b7160e01b600052601260045260246000fd5b500490565b600060018201614e6357614e63614c42565b5060010190565b604051601f8201601f1916810167ffffffffffffffff81118282101715614e9357614e93614d90565b604052919050565b600067ffffffffffffffff821115614eb557614eb5614d90565b5060051b60200190565b60006020808385031215614ed257600080fd5b825167ffffffffffffffff811115614ee957600080fd5b8301601f81018513614efa57600080fd5b8051614f0d614f0882614e9b565b614e6a565b81815260059190911b82018301908381019087831115614f2c57600080fd5b928401925b82841015612fd6578351614f4481614846565b82529284019290840190614f31565b63ffffffff82811682821603908082111561431a5761431a614c42565b600060a082018783526020878185015260a0604085015281875180845260c086019150828901935060005b81811015614fc05784516001600160a01b031683529383019391830191600101614f9b565b50506001600160a01b03969096166060850152505050608001529392505050565b60006020808385031215614ff457600080fd5b825167ffffffffffffffff81111561500b57600080fd5b8301601f8101851361501c57600080fd5b805161502a614f0882614e9b565b81815260059190911b8201830190838101908783111561504957600080fd5b928401925b82841015612fd65783518252928401929084019061504e565b60008060006060848603121561507c57600080fd5b8351925060208401519150604084015190509250925092565b60ff81811683821601908111156107c3576107c3614c42565b600060ff821660ff81036150c4576150c4614c42565b6001019291505056fe00000000000000000000000055d398326f99059ff775485246999027b3197955a26469706673582212209d38504355dd319b952c136a6530a23ccf4b3848957f54e110b1026b53ef735564736f6c63430008140033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000080472ca15f2b6a3ba29e18952e180d859c20e611

-----Decoded View---------------
Arg [0] : _referralAddress (address): 0x80472Ca15f2B6a3Ba29E18952e180D859C20e611

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000080472ca15f2b6a3ba29e18952e180d859c20e611


Block Transaction Gas Used Reward
view all blocks produced
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
View All Validatorset

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.

`; } let ensZeroWidthWarningHtml = ""; if ($("#hdnIsEnsContainZeroWidthChars").val() == "true") { ensZeroWidthWarningHtml = `
${zeroWidthWarningMessage} Check the actual text at SPACE ID.
`; } const ensOnL2NoteHtml = ensOnL2Note != "" ? `
  • ${ensOnL2Note}
  • ` : ""; const contentHtml = `
    Additional Info
    Full Name:
    ${ensNameForkIconSrc}


    Note:
    • Name tag is displayed due to forward and reverse resolution. Find out more.
    • A Domain Name is not necessarily held by a person popularly associated with the name.
    • ${ensOnL2NoteHtml}
    ${ensUnicodeWarningHtml} ${ensZeroWidthWarningHtml}
    `; $('#ensName').popover({ html: true, content: contentHtml, trigger: 'manual', placement: 'right' }); $('#ensName').click(function (event) { $("#udName").popover('hide') $("#ensName").popover('toggle'); event.stopPropagation(); }); $('#ensName').on('shown.bs.popover', async () => { //disable tooltip when hovering over ens name in the main page $("[rel='tooltipEns']").each(function () { $(this).tooltip('hide'); $(this).tooltip('disable'); }); //call ajax here to get result if (!otherENSNamesHtml) { const resolvedAddressesModel = await getEnsResolvedAddress($("#hdnAddress").val(), primaryDomainNameLabel); otherENSNamesHtml = generateEnsPopoverGrid(resolvedAddressesModel.d); if (!otherENSNamesHtml) { otherENSNamesHtml = "There are no other names resolving to this address." } } $(".popOverEnsOwnedAddressTable").html(otherENSNamesHtml); $("#divENSDisplayName").html(ensDisplayName); // append more copy button for ENS let domainName = $("#hdnEnsText").val(); const copyEnsButtonHtml = ` `; $("#spanCopyENSAddress").html(copyEnsButtonHtml); $("[data-bs-toggle='tooltip']").tooltip(); }); $('#ensName').on('hidden.bs.popover', () => { $("[rel='tooltipEns']").each(function () { $(this).tooltip('enable'); }); }); $('#ensName').on('hide.bs.popover', () => { $("[data-bs-toggle='tooltip']").tooltip('hide'); }); $(document).click(function (e) { const popoverElement = document.getElementById('popover-ens-preview'); const popoverTrigger = document.getElementById('ensName'); if (!popoverTrigger.contains(e.target) && (!popoverElement || !popoverElement.contains(e.target))) { $("#ensName").popover('hide'); } }) } async function getEnsResolvedAddress(address, currentEnsText) { try { const requestModel = { "lookupAddress": address, "primaryDomainName": currentEnsText, "provider": ensNameProvider }; const response = await $.ajax({ url: "/name-lookup-search.aspx/GetOtherDomainNameForAddress", type: "POST", contentType: "application/json", dataType: "json", data: JSON.stringify({ requestModel: requestModel }) }) return response; } catch { return ""; } } function generateEnsPopoverGrid(model) { if (!model || model.DomainNames.length == 0) { return ""; } let listOtherENSNames = ""; model.DomainNames.forEach(x => listOtherENSNames += x.Name); let moreOtherENSNames = ""; if (model.Total > 5) { moreOtherENSNames = `More ` } const result = `
    Other names resolving to this address:
    ${listOtherENSNames} ${moreOtherENSNames}
    `; return result; } function removeSpecificDomain(url, domain) { return url.replace(new RegExp(domain + '$'), ''); } // ===== UD name tag const displayUDName = ''; const primaryUDName = ''; const showUDPublicNote = 'false'; let otherUDNamesHtml = ""; function initUDNamePopOver() { //required to allow bootstrap popover to support table $.fn.popover.Constructor.Default.allowList.table = []; $.fn.popover.Constructor.Default.allowList.tr = []; $.fn.popover.Constructor.Default.allowList.td = []; $.fn.popover.Constructor.Default.allowList.th = []; $.fn.popover.Constructor.Default.allowList.div = []; $.fn.popover.Constructor.Default.allowList.tbody = []; $.fn.popover.Constructor.Default.allowList.thead = []; //allowList my inline styling for bootstrap $.fn.popover.Constructor.Default.allowList['*'].push('style') let unicodeWarningHtml = ""; if ($("#hdnIsUDContainUnicodeChars").val() == "true") { unicodeWarningHtml = `
    ${unicodeWarningMessage} Check the actual text at Unstoppable Domains.
    `; } let zeroWidthWarningHtml = ""; if ($("#hdnIsUDContainZeroWidthChars").val() == "true") { zeroWidthWarningHtml = `
    ${unicodeWarningMessage} Check the actual text at Unstoppable Domains.
    `; } const contentHtml = `
    Additional Info
    Full Name:
    Unstoppable Domains Name


    Note:
    • Name tag is displayed due to forward and reverse resolution. Find out more
    • A Domain Name is not necessarily held by a person popularly associated with the name.
    ${unicodeWarningHtml} ${zeroWidthWarningHtml}
    `; $('#udName').popover({ html: true, content: contentHtml, trigger: 'manual' }); $('#udName').click(function (event) { $("#ensName").popover('hide'); $("#udName").popover('toggle'); event.stopPropagation(); }); $('#udName').on('shown.bs.popover', async () => { //disable tooltip when hovering over SID name in the main page $("[rel='tooltipUDName']").each(function () { $(this).tooltip('hide'); $(this).tooltip('disable'); }); //call ajax here to get result if (!otherUDNamesHtml) { const resolvedAddressesModel = await getUDNamesResolvedAddress($("#hdnAddress").val(), primaryUDName); //format the ajax to otherUDNamesHtml otherUDNamesHtml = generateUDPopoverGrid(resolvedAddressesModel.d); if (!otherUDNamesHtml) { otherUDNamesHtml = "There are no other names resolving to this address." } } $(".popoverUDNamesOwnedByAddress").html(otherUDNamesHtml); $("#divDisplayUDName").html(displayUDName); if (showUDPublicNote == true) { $("#noteUD").html('The Unstoppable Domains NFT is minted on the Ethereum blockchain. View and verify its details on Etherscan.'); $("#noteUD").show(); } $("[data-bs-toggle='tooltip']").tooltip(); }); $('#udName').on('hidden.bs.popover', () => { $("[rel='tooltipUDName']").each(function () { $(this).tooltip('enable'); }); }); $('#udName').on('hide.bs.popover', () => { $("[data-bs-toggle='tooltip']").tooltip('hide'); }); // Hide Unstoppable Domains Name popover when click outside the popover popup. $(document).click(function () { $("#udName").popover('hide') }); } async function getUDNamesResolvedAddress(address, primaryUDName) { try { const requestModel = { "lookupAddress": address, "primaryDomainName": primaryUDName, "provider": "UD" }; const response = await $.ajax({ url: "/name-lookup-search.aspx/GetOtherDomainNameForAddress", type: "POST", contentType: "application/json", dataType: "json", data: JSON.stringify({ requestModel: requestModel }) }) return response; } catch { return ""; } } function generateUDPopoverGrid(model) { if (!model || model.DomainNames.length == 0) { return ""; } let listOtherUDNames = ""; model.DomainNames.forEach(x => listOtherUDNames += x.Name); let moreOtherUDNames = ""; if (model.Total > 5) { moreOtherUDNames = `More `; } const result = `
    Other names resolving to this address:
    ${listOtherUDNames} ${moreOtherUDNames}
    `; return result; } // ===== end UD name tag const tooltipForTokenHolding = 'More than 101 tokens found, listing and displaying the total balance of the first 100 tokens only. Click on the Coins icon to see the full list and balance.'; var adjustPosition = 0; $(document).ready(function () { switchAmountToValue(document.getElementById("headerAmountValue"), 'Value (USD)', 'Amount', true); switchAmountToValue(document.getElementById("headerIntAmountValue"), 'Value (USD)', 'Amount', true); switchMethodColumn(document.getElementById("headerMethod"), 'Method', 'Action', true); onDocumentReady(); $("[rel='tooltip']").tooltip(); $("[data-bs-toggle-second='tooltip']").tooltip({ trigger: 'hover' }); $("[rel='tooltipEns']").each(function () { $(this).tooltip({ title: $(this).attr("tooltip-title") }); }); if (hash != '') { activaTab(hash); }; onAddressDocReady(); // Note: this is causing "Copied" tooltip not showing when copy button is clicked in V3, and seems like not applicable to v3, comment out first in case there is issue //$('[data-bs-toggle="tooltip"]').click(function () { // $('[data-bs-toggle="tooltip"]').tooltip("hide"); //}); document.getElementById("copyaddressbutton").classList.remove("disabled"); if ($("#txtSearchContract").length) { initialiseKeyupOnDocReady(); } if (!!$('#ensName')[0]) { initEnsNamePopOver(); } if (!!$("#udName")[0]) { initUDNamePopOver(); } handleToggle(); if (window.matchMedia("(max-width: 767px)").matches) { // Mobile adjustPosition = 90; } else { // Others adjustPosition = 50; } if (tooltipForTokenHolding) { const dropdownMenuBalance = document.getElementById("dropdownMenuBalance"); if (dropdownMenuBalance) { const dropdownWrapper = dropdownMenuBalance.closest(".dropdown"); if (dropdownWrapper) { dropdownWrapper.setAttribute("title", tooltipForTokenHolding); new bootstrap.Tooltip(dropdownWrapper); } } } }); function displayAudit() { $('html, body').animate({ scrollTop: $("#auditReportId").offset().top - adjustPosition }); } var cThemeMode = getCookie('displaymode'); function handleToggle() { var className = document.getElementsByClassName('editor'); var classNameCount = className.length; for (var j = 0; j t.innerWidth()) { if (mb + d > tb) { t.css('padding-bottom', ((mb + d) - tb)); } } else { t.css('overflow', 'visible'); } }).on('hidden.bs.dropdown', function () { $(this).css({ 'padding-bottom': '', 'overflow': '' }); }); var btn_ERC20_sort = { count: 0, reminder_count: 2, list: [], default_list: [], ERC20_sort_start: function (count) { if (document.getElementsByClassName('list-custom-divider-ERC20')[0]) { var self = this if (count != undefined) { self.count = count } var before_el = document.getElementsByClassName('list-custom-divider-ERC20')[0] var parent_el = before_el.parentNode var element_selector = parent_el.querySelectorAll(".list-custom-ERC20"); if (self.list.length == 0) { element_selector.forEach(function (e) { self.list.push(e); self.default_list.push(e); }); } $(".list-custom-ERC20").remove() var type = self.count % self.reminder_count self.sortList(type, parent_el, before_el); self.count++ } }, sortList: function (type, parent_el, before_el) { var self = this var sorted_list = [] var icon_el = $(before_el).find('button').find('i') switch (type) { case 1: icon_el.attr("class", "fad fa-sort-up") sorted_list = self.sortUsdAsc() break; default: icon_el.attr("class", "fad fa-sort-down") sorted_list = self.sortUsdDesc() } for (var i = sorted_list.length - 1; i >= 0; i--) { before_el.insertAdjacentElement('afterend', sorted_list[i]) } }, sortUsdAsc: function () { var self = this var sort_list = self.list sort_list.sort(function (a, b) { var target_a_value = self.formatCurrencyToNumber(a.querySelector('.list-usd-value').textContent.trim() || -1); var target_b_value = self.formatCurrencyToNumber(b.querySelector('.list-usd-value').textContent.trim() || -1); if (target_a_value == -1 || target_b_value == -1) { return 1; } if (target_a_value target_b_value) { return 1; } return 0 }); return sort_list }, sortUsdDesc: function () { var self = this var sort_list = self.list sort_list.sort(function (a, b) { var target_a_value = self.formatCurrencyToNumber(a.querySelector('.list-usd-value').textContent.trim() || -1); var target_b_value = self.formatCurrencyToNumber(b.querySelector('.list-usd-value').textContent.trim() || -1); if (target_a_value target_b_value) { return -1; } return 0 }); return sort_list }, formatCurrencyToNumber: function (strCurrency) { if (typeof strCurrency == "number") return strCurrency else return Number(strCurrency.replace(/[^0-9.-]+/g, "")); }, } function hrefTokenHolding() { var location = "/tokenholdings?a=0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1" var queryString = $("input.form-control.form-control-xs.search.mb-3")[0].value if (queryString) { location += "&q=" + queryString } window.location.href = location } $(document).ready(function () { $("#btn_ERC20_sort").on("click", function (event) { event.preventDefault(); setTimeout(function () { btn_ERC20_sort.ERC20_sort_start() }, 10) }) btn_ERC20_sort.ERC20_sort_start() var mainAddress = $("#hdnAddress").val(); // user search for method filters var searchFuncTimeOut; $("#ContentPlaceHolder1_inputMethodName").on("keyup", function ($event) { if (searchFuncTimeOut) { clearTimeout(searchFuncTimeOut) } var searchTerm = $(this).val(); searchFuncTimeOut = setTimeout(function () { searchFunctions(searchTerm); }, 350); }); var isSearchFunctions = false; $("#dropdownMethod").on("click", function (e) { if (isSearchFunctions === false) { searchFunctions(''); isSearchFunctions = true; } }); const litDefaultMethodFilterHtml = ''; function searchFunctions(searchTerm) { if (searchTerm === '' || searchTerm.length > 3) { const curPath = encodeURIComponent(window.location.search); $.ajax({ type: 'Get', url: `/functionSearchHandler.ashx?ca=${mainAddress}&func=${searchTerm ?? ''}&curPath=${curPath}`, success: function (response) { $("#searchFunctionResult").html(''); if (response && response.length > 0) { for (var i = 0; i ${response[i].name} ${response[i].methodId} ` ); } $("[data-bs-toggle='tooltip']").tooltip(); } else { $("#searchFunctionResult").append( `` ); } $("#inputMethodSpinner").hide(); }, error: function (XMLHttpRequest, textStatus, errorThrown) { $("#searchFunctionResult").html(''); $("#inputMethodSpinner").hide(); } }); } else { $("#inputMethodSpinner").hide(); $("#searchFunctionResult").html(litDefaultMethodFilterHtml); } } // Resize window for analytic tab let isBusy = false; $(window).resize(function () { isBusy = true; if (isBusy) { let analyticFrame = document.getElementById('analytics_pageiframe'); if (analyticFrame && analyticFrame.contentWindow != undefined) { let navtab = analyticFrame.contentWindow.document.getElementsByClassName("nav_tabs1"); let hIframe = "0px"; if (navtab != null && navtab != undefined && navtab.length > 0) { let navH = Number(navtab[0].scrollHeight); hIframe = (Number(analyticFrame.contentWindow.document.getElementsByClassName("tab-content")[0].scrollHeight) + navH + 20) + 'px'; } else { hIframe = analyticFrame.contentWindow.document.body.scrollHeight + 'px'; } analyticFrame.style.height = hIframe } } }); // detect tooltip for token holding dropdown if ($(".addresses-tooltip-over").length > 0) { if (!isMobile()) { $(".addresses-tooltip-over").attr("data-bs-trigger", "hover"); let tooltip = bootstrap.Tooltip.getInstance(".addresses-tooltip-over"); if (tooltip !== null) { tooltip.dispose(); tooltip = new bootstrap.Tooltip($(".addresses-tooltip-over")); tooltip._config.trigger = 'hover'; tooltip.update(); } } } // Quick export transaction csv const quickExportCsvData = '[{"Txhash":"0x66bcc46a12714e8e4d2464c8a87e688d599f15e5619e7d7fc1a0834cd55f19bd","Status":"Success","Method":"Stake","Blockno":"81586074","DateTime":"2026-02-16 16:31:00","Sender":"0x771B13fB197df26fD1571d67746F0D00757A3888","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00004781"},{"Txhash":"0xa290ceea5504b4ae4d680c8680460a7fa266ae35bebaffbcb1b3f193602c2e21","Status":"Success","Method":"Unstake","Blockno":"81585711","DateTime":"2026-02-16 16:28:16","Sender":"0x771B13fB197df26fD1571d67746F0D00757A3888","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00004546"},{"Txhash":"0xdc56b6aed992f322c521149e449e6092a30b43440f2d75db086dfd98a1b8e779","Status":"Success","Method":"Stake","Blockno":"81585272","DateTime":"2026-02-16 16:24:59","Sender":"0xbe43CA53bFe059545Bc11804a9cf8334e78a48E9","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00005965"},{"Txhash":"0xe68dda40c659a36ea5f6c38b34e469d2a661c779f6f756cd22725ecc6ffd9d5c","Status":"Success","Method":"Unstake","Blockno":"81584401","DateTime":"2026-02-16 16:18:27","Sender":"0xbe43CA53bFe059545Bc11804a9cf8334e78a48E9","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006395"},{"Txhash":"0x92fed5fe7e6312884b88beb29bb729147f1e3b9ee8febce95d3358542b28291e","Status":"Success","Method":"Unstake","Blockno":"81582944","DateTime":"2026-02-16 16:07:31","Sender":"0xbe43CA53bFe059545Bc11804a9cf8334e78a48E9","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006292"},{"Txhash":"0xcb2099218c190988fa2c7b2d6f443b5d8df77dd84b3b93e9767748c28a58230b","Status":"Success","Method":"Stake","Blockno":"81582690","DateTime":"2026-02-16 16:05:37","Sender":"0xfcf7eC200b31b8aa2CAeb4D748272478dBaB580b","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00005735"},{"Txhash":"0x67915f459cf427f1ee74b6c0ae82b69b74e3a068709a95f82af9bc3b9f0dbc37","Status":"Success","Method":"Unstake","Blockno":"81582585","DateTime":"2026-02-16 16:04:49","Sender":"0xfcf7eC200b31b8aa2CAeb4D748272478dBaB580b","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006427"},{"Txhash":"0x27415e3d3f9f3133c84a1b59aab66727df537ddbc3a56aeaf48ad32d73945c90","Status":"Success","Method":"Stake","Blockno":"81582416","DateTime":"2026-02-16 16:03:33","Sender":"0x8B4CaC50c7F14dFA65c14759C75A59355aADB326","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006096"},{"Txhash":"0x1892f84811c2cab25f10b364151763cb7fcda2da7918aac96f43a5a4a93cedf2","Status":"Success","Method":"Unstake","Blockno":"81582328","DateTime":"2026-02-16 16:02:54","Sender":"0x8B4CaC50c7F14dFA65c14759C75A59355aADB326","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006501"},{"Txhash":"0xb9f32feebab05c459b8bce45df5d4d1eb7ad330e6881b7a1ddedee10c871abdf","Status":"Success","Method":"Stake","Blockno":"81581877","DateTime":"2026-02-16 15:59:31","Sender":"0xf3604a82A3d580341797208cfd69D47fc510379B","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006361"},{"Txhash":"0x12320e7fa1b255d1fa5b2f66b7c211f9521a1f3481d703156b285d41f841b574","Status":"Success","Method":"Stake","Blockno":"81581757","DateTime":"2026-02-16 15:58:37","Sender":"0xfE37B96146D9AAc5f634Fd0E3266b29757c24Ef1","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.0000595"},{"Txhash":"0x0dd77fcc129a875c73b12f311e1aacd48d9329e1532d7f5fcd36bc39157580ef","Status":"Success","Method":"Unstake","Blockno":"81581663","DateTime":"2026-02-16 15:57:54","Sender":"0xfE37B96146D9AAc5f634Fd0E3266b29757c24Ef1","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006638"},{"Txhash":"0x1ee04ca941cf107047631f8320df717d9839a883acb7834ad27ffc984e8b5dd3","Status":"Success","Method":"Unstake","Blockno":"81581597","DateTime":"2026-02-16 15:57:25","Sender":"0xf3604a82A3d580341797208cfd69D47fc510379B","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006662"},{"Txhash":"0x468a09adc1db9049c9cf32b0a97932766416dda9b9e9853f794c821ebecee3b7","Status":"Success","Method":"Stake","Blockno":"81581544","DateTime":"2026-02-16 15:57:01","Sender":"0x1C09EbD53566787280f4e1137Cdaa9dDfdeEb922","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00005954"},{"Txhash":"0x1c832b6b0c2d48d867feb2c40afd53a66ebaab6562b1c4a52c74c53eda27a66c","Status":"Success","Method":"Unstake","Blockno":"81581445","DateTime":"2026-02-16 15:56:16","Sender":"0x1C09EbD53566787280f4e1137Cdaa9dDfdeEb922","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00010212"},{"Txhash":"0x2b597aaaf5c52451598059e0f98e1b79fd922db9edeec1ede40e8cd097a84a74","Status":"Success","Method":"Unstake","Blockno":"81581168","DateTime":"2026-02-16 15:54:12","Sender":"0x148717d585Dc5A058B3A0C0b9B032Af55981b4eB","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006018"},{"Txhash":"0x9dfe42408ba84e5b7aa4e5935eb02c6cd90df66f54b05fc5bdd5d61d866d81a2","Status":"Success","Method":"Stake","Blockno":"81581011","DateTime":"2026-02-16 15:53:01","Sender":"0x5769bae9513539BE4828a5c5C88c7F7bdBd8FF4a","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006017"},{"Txhash":"0x1bfd37a67707d42d7328c655fdae1d098e478a19042ca62cea6d07ea9f5b7c52","Status":"Success","Method":"Unstake","Blockno":"81580853","DateTime":"2026-02-16 15:51:50","Sender":"0x5769bae9513539BE4828a5c5C88c7F7bdBd8FF4a","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006623"},{"Txhash":"0x55c058c454ff80ee1c319ab05923b7b3f270cfe07740cdb4bacdc9fac7013855","Status":"Success","Method":"Stake","Blockno":"81580624","DateTime":"2026-02-16 15:50:07","Sender":"0x9d3b52A6986849065bF71D9c0aD5Cd805896564a","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00009079"},{"Txhash":"0x9cef05f6917a8b26d789f0f084ebbf197b90c38869ebfd458cbda56c78baa482","Status":"Success","Method":"Unstake","Blockno":"81580542","DateTime":"2026-02-16 15:49:30","Sender":"0x9d3b52A6986849065bF71D9c0aD5Cd805896564a","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00007076"},{"Txhash":"0xb45bbc52768622eddf46d1ccb1323ed02d674c3a02afe78dfc2d3598f5f32177","Status":"Success","Method":"Stake","Blockno":"81580375","DateTime":"2026-02-16 15:48:15","Sender":"0xaB793AB56A9F842FFc8d3eA1b5818afAd465F544","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00005845"},{"Txhash":"0x126e198d51a16860714a99213964d6649a3cd76a3e4f9cba5f0d74a26f2a0698","Status":"Success","Method":"Unstake","Blockno":"81580286","DateTime":"2026-02-16 15:47:35","Sender":"0xaB793AB56A9F842FFc8d3eA1b5818afAd465F544","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006587"},{"Txhash":"0x934d0ef01040cdb7835e664a844451ac9cfefdf435ffefb1c20210b8afa7a716","Status":"Success","Method":"Stake","Blockno":"81580091","DateTime":"2026-02-16 15:46:07","Sender":"0x4A2617deEA7494e5f23af5c6e8b63fe6365b274b","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006179"},{"Txhash":"0xe77725df8bc376e2084d6567d2dec8adc3f68f25f8d96b8e5263cda697bcec72","Status":"Success","Method":"Stake","Blockno":"81580052","DateTime":"2026-02-16 15:45:49","Sender":"0xb7018664eC88bEdcD98f5e9Cb092aA6a7bE95111","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00005634"},{"Txhash":"0x2c6e21f4f79f4df6952249af193cb5097baf7144cfd55cda65ae9fffcac5d0c8","Status":"Success","Method":"Unstake","Blockno":"81579989","DateTime":"2026-02-16 15:45:21","Sender":"0x4A2617deEA7494e5f23af5c6e8b63fe6365b274b","SenderLable":null,"Receiver":"0xB7dab22F4Bc9Bc6eC24cefeFd846c00d401676D1","ReceiverLable":null,"Amount":"0 BNB","Value":"$0.00","TxnFee":"0.00006342"}]'; const quickExportCsvTitle = 'Transaction Hash,Status,Method,Blockno,"DateTime (UTC)",From,From_Nametag,To,To_Nametag,Amount,Value (USD),Txn Fee'; let isExportFinish = true; if ($("#btnExportQuickTableToCSV").length > 0 && quickExportCsvData) { $("#btnExportQuickTableToCSV").click(function () { if (isExportFinish == true) { isExportFinish = false; $("#btnExportQuickTableToCSV").append(''); let lstTxsObj = JSON.parse(quickExportCsvData); if (lstTxsObj.length > 0) { let csvRows = []; csvRows.push(quickExportCsvTitle.replace(/"/g, "")); for (let i = 0; i 0 && quickExportInternalTxsData) { $("#ContentPlaceHolder1_btnQuickExportInternalTxs").click(function () { if (isExportFinish == true) { isExportFinish = false; $("#ContentPlaceHolder1_btnQuickExportInternalTxs").append(''); let lstTxsObj = JSON.parse(quickExportInternalTxsData); if (lstTxsObj.length > 0) { let csvRows = []; csvRows.push(quickExportInternalTxsTitle.replace(/"/g, "")); for (let i = 0; i { if (x.startsWith("F")) { file = x.replace("F", ""); } else if (x.startsWith("L")) { line = x.replace("L", ""); } }) var editorId = "editor" + file var editorElem = $("#" + editorId); if (!editorElem.length) { return; } if (!line) { return; } var editor = ace.edit(editorId); editor.resize(true); editor.scrollToLine(line, true, true, function () { }); editor.gotoLine(line); var Range = ace.require('ace/range').Range $(document).scrollTop($("#" + editorId).offset().top - 95); //document.getElementById(editorId).scrollIntoView(); editor.session.addMarker(new Range(line - 1, 0, line - 1, 1), "myMarker", "fullLine"); //window.onbeforeunload = function () { $(document).scrollTop($("#" + editorId).offset().top); }; } setTimeout(function () { editorGoToLine(); }, 500); }); $("body,html").click(function (evt) { let elm = $(evt.target).attr("id"); let isClickedMode = elm === "darkModaBtn" || elm === "darkModaBtnIcon"; if (isClickedMode) { let isClickedSunMode = false; let clrBorder = "#112641"; if (elm === "darkModaBtn") isClickedSunMode = $(evt.target).find("#darkModaBtnIcon").hasClass("fa-moon"); if (elm === "darkModaBtnIcon") isClickedSunMode = $(evt.target).hasClass("fa-moon"); if (isClickedSunMode) { clrBorder = "#fff"; } let iframes = document.getElementById('analytics_pageiframe'); let heatcell = iframes.contentWindow.document.getElementsByClassName("ch-day").length; for (let i = 0; i