Contract 0x43C36253d3550c78a23Ab3bC7F06d4A0A06b7C31 1

Contract Overview

Balance:
0 ETH
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x2c6643fdfca08b4cbac9cf7d52a7f98d3421071884fc71b38b55e02ff562ecd60x60806040110971462022-04-12 17:50:42166 days 11 hrs ago0xe22650094d07a54b87384b05c0b02ee3e33bcaa4 IN  Create: InsurancePricer0 ETH0.000596731076 ETH
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
InsurancePricer

Compiler Version
v0.8.13+commit.abaa5c0e

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 5 : InsurancePricer.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.13;

// because Math in Solidity is hard: https://medium.com/coinmonks/math-in-solidity-part-3-percents-and-proportions-4db014e080b1
import {PRBMathSD59x18} from "./PRBMathSD59x18.sol";
import {PRBMathUD60x18} from "./PRBMathUD60x18.sol";
import {SafeMath} from "./SafeMath.sol";

// Inspired by Pods Finance - https://github.com/pods-finance/contracts/blob/main/contracts/amm/BlackScholes.sol

contract InsurancePricer {
    using PRBMathSD59x18 for int256;
    using PRBMathUD60x18 for uint256;

    mapping(uint256 => uint256) private _cachedDataPoints;

    uint8 public constant decimals = 18;

    constructor() {
        _cachedDataPoints[0] = 50000;
        _cachedDataPoints[100] = 50399;
        _cachedDataPoints[200] = 50798;
        _cachedDataPoints[300] = 51197;
        _cachedDataPoints[400] = 51595;
        _cachedDataPoints[500] = 51994;
        _cachedDataPoints[600] = 52392;
        _cachedDataPoints[700] = 52790;
        _cachedDataPoints[800] = 53188;
        _cachedDataPoints[900] = 53586;
        _cachedDataPoints[1000] = 53983;
        _cachedDataPoints[1100] = 54380;
        _cachedDataPoints[1200] = 54776;
        _cachedDataPoints[1300] = 55172;
        _cachedDataPoints[1400] = 55567;
        _cachedDataPoints[1500] = 55962;
        _cachedDataPoints[1600] = 56356;
        _cachedDataPoints[1700] = 56749;
        _cachedDataPoints[1800] = 57142;
        _cachedDataPoints[1900] = 57535;
        _cachedDataPoints[2000] = 57926;
        _cachedDataPoints[2100] = 58317;
        _cachedDataPoints[2200] = 58706;
        _cachedDataPoints[2300] = 59095;
        _cachedDataPoints[2400] = 59483;
        _cachedDataPoints[2500] = 59871;
        _cachedDataPoints[2600] = 60257;
        _cachedDataPoints[2700] = 60642;
        _cachedDataPoints[2800] = 61026;
        _cachedDataPoints[2900] = 61409;
        _cachedDataPoints[3000] = 61791;
        _cachedDataPoints[3100] = 62172;
        _cachedDataPoints[3200] = 62552;
        _cachedDataPoints[3300] = 62930;
        _cachedDataPoints[3400] = 63307;
        _cachedDataPoints[3500] = 63683;
        _cachedDataPoints[3600] = 64058;
        _cachedDataPoints[3700] = 64431;
        _cachedDataPoints[3800] = 64803;
        _cachedDataPoints[3900] = 65173;
        _cachedDataPoints[4000] = 65542;
        _cachedDataPoints[4100] = 65910;
        _cachedDataPoints[4200] = 66276;
        _cachedDataPoints[4300] = 66640;
        _cachedDataPoints[4400] = 67003;
        _cachedDataPoints[4500] = 67364;
        _cachedDataPoints[4600] = 67724;
        _cachedDataPoints[4700] = 68082;
        _cachedDataPoints[4800] = 68439;
        _cachedDataPoints[4900] = 68793;
        _cachedDataPoints[5000] = 69146;
        _cachedDataPoints[5100] = 69497;
        _cachedDataPoints[5200] = 69847;
        _cachedDataPoints[5300] = 70194;
        _cachedDataPoints[5400] = 70540;
        _cachedDataPoints[5500] = 70884;
        _cachedDataPoints[5600] = 71226;
        _cachedDataPoints[5700] = 71566;
        _cachedDataPoints[5800] = 71904;
        _cachedDataPoints[5900] = 72240;
        _cachedDataPoints[6000] = 72575;
        _cachedDataPoints[6100] = 72907;
        _cachedDataPoints[6200] = 73237;
        _cachedDataPoints[6300] = 73565;
        _cachedDataPoints[6400] = 73891;
        _cachedDataPoints[6500] = 74215;
        _cachedDataPoints[6600] = 74537;
        _cachedDataPoints[6700] = 74857;
        _cachedDataPoints[6800] = 75175;
        _cachedDataPoints[6900] = 75490;
        _cachedDataPoints[7000] = 75804;
        _cachedDataPoints[7100] = 76115;
        _cachedDataPoints[7200] = 76424;
        _cachedDataPoints[7300] = 76730;
        _cachedDataPoints[7400] = 77035;
        _cachedDataPoints[7500] = 77337;
        _cachedDataPoints[7600] = 77637;
        _cachedDataPoints[7700] = 77935;
        _cachedDataPoints[7800] = 78230;
        _cachedDataPoints[7900] = 78524;
        _cachedDataPoints[8000] = 78814;
        _cachedDataPoints[8100] = 79103;
        _cachedDataPoints[8200] = 79389;
        _cachedDataPoints[8300] = 79673;
        _cachedDataPoints[8400] = 79955;
        _cachedDataPoints[8500] = 80234;
        _cachedDataPoints[8600] = 80511;
        _cachedDataPoints[8700] = 80785;
        _cachedDataPoints[8800] = 81057;
        _cachedDataPoints[8900] = 81327;
        _cachedDataPoints[9000] = 81594;
        _cachedDataPoints[9100] = 81859;
        _cachedDataPoints[9200] = 82121;
        _cachedDataPoints[9300] = 82381;
        _cachedDataPoints[9400] = 82639;
        _cachedDataPoints[9500] = 82894;
        _cachedDataPoints[9600] = 83147;
        _cachedDataPoints[9700] = 83398;
        _cachedDataPoints[9800] = 83646;
        _cachedDataPoints[9900] = 83891;
        _cachedDataPoints[10000] = 84134;
        _cachedDataPoints[10100] = 84375;
        _cachedDataPoints[10200] = 84614;
        _cachedDataPoints[10300] = 84849;
        _cachedDataPoints[10400] = 85083;
        _cachedDataPoints[10500] = 85314;
        _cachedDataPoints[10600] = 85543;
        _cachedDataPoints[10700] = 85769;
        _cachedDataPoints[10800] = 85993;
        _cachedDataPoints[10900] = 86214;
        _cachedDataPoints[11000] = 86433;
        _cachedDataPoints[11100] = 86650;
        _cachedDataPoints[11200] = 86864;
        _cachedDataPoints[11300] = 87076;
        _cachedDataPoints[11400] = 87286;
        _cachedDataPoints[11500] = 87493;
        _cachedDataPoints[11600] = 87698;
        _cachedDataPoints[11700] = 87900;
        _cachedDataPoints[11800] = 88100;
        _cachedDataPoints[11900] = 88298;
        _cachedDataPoints[12000] = 88493;
        _cachedDataPoints[12100] = 88686;
        _cachedDataPoints[12200] = 88877;
        _cachedDataPoints[12300] = 89065;
        _cachedDataPoints[12400] = 89251;
        _cachedDataPoints[12500] = 89435;
        _cachedDataPoints[12600] = 89617;
        _cachedDataPoints[12700] = 89796;
        _cachedDataPoints[12800] = 89973;
        _cachedDataPoints[12900] = 90147;
        _cachedDataPoints[13000] = 90320;
        _cachedDataPoints[13100] = 90490;
        _cachedDataPoints[13200] = 90658;
        _cachedDataPoints[13300] = 90824;
        _cachedDataPoints[13400] = 90988;
        _cachedDataPoints[13500] = 91149;
        _cachedDataPoints[13600] = 91309;
        _cachedDataPoints[13700] = 91466;
        _cachedDataPoints[13800] = 91621;
        _cachedDataPoints[13900] = 91774;
        _cachedDataPoints[14000] = 91924;
        _cachedDataPoints[14100] = 92073;
        _cachedDataPoints[14200] = 92220;
        _cachedDataPoints[14300] = 92364;
        _cachedDataPoints[14400] = 92507;
        _cachedDataPoints[14500] = 92647;
        _cachedDataPoints[14600] = 92785;
        _cachedDataPoints[14700] = 92922;
        _cachedDataPoints[14800] = 93056;
        _cachedDataPoints[14900] = 93189;
        _cachedDataPoints[15000] = 93319;
        _cachedDataPoints[15100] = 93448;
        _cachedDataPoints[15200] = 93574;
        _cachedDataPoints[15300] = 93699;
        _cachedDataPoints[15400] = 93822;
        _cachedDataPoints[15500] = 93943;
        _cachedDataPoints[15600] = 94062;
        _cachedDataPoints[15700] = 94179;
        _cachedDataPoints[15800] = 94295;
        _cachedDataPoints[15900] = 94408;
        _cachedDataPoints[16000] = 94520;
        _cachedDataPoints[16100] = 94630;
        _cachedDataPoints[16200] = 94738;
        _cachedDataPoints[16300] = 94845;
        _cachedDataPoints[16400] = 94950;
        _cachedDataPoints[16500] = 95053;
        _cachedDataPoints[16600] = 95154;
        _cachedDataPoints[16700] = 95254;
        _cachedDataPoints[16800] = 95352;
        _cachedDataPoints[16900] = 95449;
        _cachedDataPoints[17000] = 95543;
        _cachedDataPoints[17100] = 95637;
        _cachedDataPoints[17200] = 95728;
        _cachedDataPoints[17300] = 95818;
        _cachedDataPoints[17400] = 95907;
        _cachedDataPoints[17500] = 95994;
        _cachedDataPoints[17600] = 96080;
        _cachedDataPoints[17700] = 96164;
        _cachedDataPoints[17800] = 96246;
        _cachedDataPoints[17900] = 96327;
        _cachedDataPoints[18000] = 96407;
        _cachedDataPoints[18100] = 96485;
        _cachedDataPoints[18200] = 96562;
        _cachedDataPoints[18300] = 96638;
        _cachedDataPoints[18400] = 96712;
        _cachedDataPoints[18500] = 96784;
        _cachedDataPoints[18600] = 96856;
        _cachedDataPoints[18700] = 96926;
        _cachedDataPoints[18800] = 96995;
        _cachedDataPoints[18900] = 97062;
        _cachedDataPoints[19000] = 97128;
        _cachedDataPoints[19100] = 97193;
        _cachedDataPoints[19200] = 97257;
        _cachedDataPoints[19300] = 97320;
        _cachedDataPoints[19400] = 97381;
        _cachedDataPoints[19500] = 97441;
        _cachedDataPoints[19600] = 97500;
        _cachedDataPoints[19700] = 97558;
        _cachedDataPoints[19800] = 97615;
        _cachedDataPoints[19900] = 97670;
        _cachedDataPoints[20000] = 97725;
        _cachedDataPoints[20100] = 97778;
        _cachedDataPoints[20200] = 97831;
        _cachedDataPoints[20300] = 97882;
        _cachedDataPoints[20400] = 97932;
        _cachedDataPoints[20500] = 97982;
        _cachedDataPoints[20600] = 98030;
        _cachedDataPoints[20700] = 98077;
        _cachedDataPoints[20800] = 98124;
        _cachedDataPoints[20900] = 98169;
        _cachedDataPoints[21000] = 98214;
        _cachedDataPoints[21100] = 98257;
        _cachedDataPoints[21200] = 98300;
        _cachedDataPoints[21300] = 98341;
        _cachedDataPoints[21400] = 98382;
        _cachedDataPoints[21500] = 98422;
        _cachedDataPoints[21600] = 98461;
        _cachedDataPoints[21700] = 98500;
        _cachedDataPoints[21800] = 98537;
        _cachedDataPoints[21900] = 98574;
        _cachedDataPoints[22000] = 98610;
        _cachedDataPoints[22100] = 98645;
        _cachedDataPoints[22200] = 98679;
        _cachedDataPoints[22300] = 98713;
        _cachedDataPoints[22400] = 98745;
        _cachedDataPoints[22500] = 98778;
        _cachedDataPoints[22600] = 98809;
        _cachedDataPoints[22700] = 98840;
        _cachedDataPoints[22800] = 98870;
        _cachedDataPoints[22900] = 98899;
        _cachedDataPoints[23000] = 98928;
        _cachedDataPoints[23100] = 98956;
        _cachedDataPoints[23200] = 98983;
        _cachedDataPoints[23300] = 99010;
        _cachedDataPoints[23400] = 99036;
        _cachedDataPoints[23500] = 99061;
        _cachedDataPoints[23600] = 99086;
        _cachedDataPoints[23700] = 99111;
        _cachedDataPoints[23800] = 99134;
        _cachedDataPoints[23900] = 99158;
        _cachedDataPoints[24000] = 99180;
        _cachedDataPoints[24100] = 99202;
        _cachedDataPoints[24200] = 99224;
        _cachedDataPoints[24300] = 99245;
        _cachedDataPoints[24400] = 99266;
        _cachedDataPoints[24500] = 99286;
        _cachedDataPoints[24600] = 99305;
        _cachedDataPoints[24700] = 99324;
        _cachedDataPoints[24800] = 99343;
        _cachedDataPoints[24900] = 99361;
        _cachedDataPoints[25000] = 99379;
        _cachedDataPoints[25100] = 99396;
        _cachedDataPoints[25200] = 99413;
        _cachedDataPoints[25300] = 99430;
        _cachedDataPoints[25400] = 99446;
        _cachedDataPoints[25500] = 99461;
        _cachedDataPoints[25600] = 99477;
        _cachedDataPoints[25700] = 99492;
        _cachedDataPoints[25800] = 99506;
        _cachedDataPoints[25900] = 99520;
        _cachedDataPoints[26000] = 99534;
        _cachedDataPoints[26100] = 99547;
        _cachedDataPoints[26200] = 99560;
        _cachedDataPoints[26300] = 99573;
        _cachedDataPoints[26400] = 99585;
        _cachedDataPoints[26500] = 99598;
        _cachedDataPoints[26600] = 99609;
        _cachedDataPoints[26700] = 99621;
        _cachedDataPoints[26800] = 99632;
        _cachedDataPoints[26900] = 99643;
        _cachedDataPoints[27000] = 99653;
        _cachedDataPoints[27100] = 99664;
        _cachedDataPoints[27200] = 99674;
        _cachedDataPoints[27300] = 99683;
        _cachedDataPoints[27400] = 99693;
        _cachedDataPoints[27500] = 99702;
        _cachedDataPoints[27600] = 99711;
        _cachedDataPoints[27700] = 99720;
        _cachedDataPoints[27800] = 99728;
        _cachedDataPoints[27900] = 99736;
        _cachedDataPoints[28000] = 99744;
        _cachedDataPoints[28100] = 99752;
        _cachedDataPoints[28200] = 99760;
        _cachedDataPoints[28300] = 99767;
        _cachedDataPoints[28400] = 99774;
        _cachedDataPoints[28500] = 99781;
        _cachedDataPoints[28600] = 99788;
        _cachedDataPoints[28700] = 99795;
        _cachedDataPoints[28800] = 99801;
        _cachedDataPoints[28900] = 99807;
        _cachedDataPoints[29000] = 99813;
        _cachedDataPoints[29100] = 99819;
        _cachedDataPoints[29200] = 99825;
        _cachedDataPoints[29300] = 99831;
        _cachedDataPoints[29400] = 99836;
        _cachedDataPoints[29500] = 99841;
        _cachedDataPoints[29600] = 99846;
        _cachedDataPoints[29700] = 99851;
        _cachedDataPoints[29800] = 99856;
        _cachedDataPoints[29900] = 99861;
        _cachedDataPoints[30000] = 99865;
        _cachedDataPoints[30100] = 99869;
        _cachedDataPoints[30200] = 99874;
        _cachedDataPoints[30300] = 99878;
        _cachedDataPoints[30400] = 99882;
        _cachedDataPoints[30500] = 99886;
        _cachedDataPoints[30600] = 99889;
        _cachedDataPoints[30700] = 99893;
        _cachedDataPoints[30800] = 99896;
        _cachedDataPoints[30900] = 99900;
        _cachedDataPoints[31000] = 99903;
        _cachedDataPoints[31100] = 99906;
        _cachedDataPoints[31200] = 99910;
        _cachedDataPoints[31300] = 99913;
        _cachedDataPoints[31400] = 99916;
        _cachedDataPoints[31500] = 99918;
        _cachedDataPoints[31600] = 99921;
        _cachedDataPoints[31700] = 99924;
        _cachedDataPoints[31800] = 99926;
        _cachedDataPoints[31900] = 99929;
        _cachedDataPoints[32000] = 99931;
        _cachedDataPoints[32100] = 99934;
        _cachedDataPoints[32200] = 99936;
        _cachedDataPoints[32300] = 99938;
        _cachedDataPoints[32400] = 99940;
        _cachedDataPoints[32500] = 99942;
        _cachedDataPoints[32600] = 99944;
        _cachedDataPoints[32700] = 99946;
        _cachedDataPoints[32800] = 99948;
        _cachedDataPoints[32900] = 99950;
        _cachedDataPoints[33000] = 99952;
        _cachedDataPoints[33100] = 99953;
        _cachedDataPoints[33200] = 99955;
        _cachedDataPoints[33300] = 99957;
        _cachedDataPoints[33400] = 99958;
        _cachedDataPoints[33500] = 99960;
        _cachedDataPoints[33600] = 99961;
        _cachedDataPoints[33700] = 99962;
        _cachedDataPoints[33800] = 99964;
        _cachedDataPoints[33900] = 99965;
        _cachedDataPoints[34000] = 99966;
        _cachedDataPoints[34100] = 99968;
        _cachedDataPoints[34200] = 99969;
        _cachedDataPoints[34300] = 99970;
        _cachedDataPoints[34400] = 99971;
        _cachedDataPoints[34500] = 99972;
        _cachedDataPoints[34600] = 99973;
        _cachedDataPoints[34700] = 99974;
        _cachedDataPoints[34800] = 99975;
        _cachedDataPoints[34900] = 99976;
        _cachedDataPoints[35000] = 99977;
        _cachedDataPoints[35100] = 99978;
        _cachedDataPoints[35200] = 99978;
        _cachedDataPoints[35300] = 99979;
        _cachedDataPoints[35400] = 99980;
        _cachedDataPoints[35500] = 99981;
        _cachedDataPoints[35600] = 99981;
        _cachedDataPoints[35700] = 99982;
        _cachedDataPoints[35800] = 99983;
        _cachedDataPoints[35900] = 99983;
        _cachedDataPoints[36000] = 99984;
        _cachedDataPoints[36100] = 99985;
        _cachedDataPoints[36200] = 99985;
        _cachedDataPoints[36300] = 99986;
        _cachedDataPoints[36400] = 99986;
        _cachedDataPoints[36500] = 99987;
        _cachedDataPoints[36600] = 99987;
        _cachedDataPoints[36700] = 99988;
        _cachedDataPoints[36800] = 99988;
        _cachedDataPoints[36900] = 99989;
        _cachedDataPoints[37000] = 99989;
        _cachedDataPoints[37100] = 99990;
        _cachedDataPoints[37200] = 99990;
        _cachedDataPoints[37300] = 99990;
        _cachedDataPoints[37400] = 99991;
        _cachedDataPoints[37500] = 99991;
        _cachedDataPoints[37600] = 99992;
        _cachedDataPoints[37700] = 99992;
        _cachedDataPoints[37800] = 99992;
        _cachedDataPoints[37900] = 99992;
        _cachedDataPoints[38000] = 99993;
        _cachedDataPoints[38100] = 99993;
        _cachedDataPoints[38200] = 99993;
        _cachedDataPoints[38300] = 99994;
        _cachedDataPoints[38400] = 99994;
        _cachedDataPoints[38500] = 99994;
        _cachedDataPoints[38600] = 99994;
        _cachedDataPoints[38700] = 99995;
        _cachedDataPoints[38800] = 99995;
        _cachedDataPoints[38900] = 99995;
        _cachedDataPoints[39000] = 99995;
        _cachedDataPoints[39100] = 99995;
        _cachedDataPoints[39200] = 99996;
        _cachedDataPoints[39300] = 99996;
        _cachedDataPoints[39400] = 99996;
        _cachedDataPoints[39500] = 99996;
        _cachedDataPoints[39600] = 99996;
        _cachedDataPoints[39700] = 99996;
    }

    /**
     * @notice Calculate put option price
     *
     * @param spotPrice Asset spot price
     * @param strikePrice Option strike price
     * @param iv Annually volatility on the asset price
     * @param time Annualized time until maturity
     * @param riskFree The risk-free rate
     * @return put option price - divide by 10**18 to get decimal value
     */
    function getPutPrice(
        uint256 spotPrice,
        uint256 strikePrice,
        uint256 iv,
        uint256 time,
        int256 riskFree
    ) public view returns (uint256) {
        (int256 d1, int256 d2) = _getZScores(
            _uintToInt(spotPrice),
            _uintToInt(strikePrice),
            _uintToInt(iv),
            _uintToInt(time),
            riskFree
        );
        uint256 Nd1 = _getProbability(_additiveInverse(d1));
        uint256 Nd2 = _getProbability(_additiveInverse(d2));

        uint256 get = strikePrice.mul(Nd2);
        uint256 pay = spotPrice.mul(Nd1);

        if (pay > get) {
            // Negative numbers not allowed
            return 0;
        }

        return get - pay;
    }

    /**
     * @notice Returns probability approximations of Z in a normal distribution curve
     * @dev For performance, numbers are truncated to 2 decimals. Ex: 1134500000000000000(1.13) gets truncated to 113
     * @dev For Z > ±0.307 the curve response gets more concentrated, hence some predefined answers can be
     * given for a few sets of z. Otherwise it will calculate a median answer between the saved data points
     * @param z A point in the normal distribution
     * @return The probability of a z variable in a normal distribution
     */
    function _getProbability(int256 z) internal view returns (uint256) {
        uint256 absZ = _abs(z);
        uint256 sub2 = 10**(SafeMath.sub(decimals, 2));
        uint256 sub3 = 10**(SafeMath.sub(decimals, 3));
        uint256 truncatedZ = SafeMath.mul(SafeMath.div(absZ, sub2), 100);
        uint256 fourthDigit = SafeMath.div(absZ, sub3) -
            SafeMath.mul(SafeMath.div(absZ, sub2), 10);
        uint256 responseDecimals = 10**(SafeMath.sub(decimals, 5));
        uint256 responseValue;

        if (truncatedZ >= 41900) {
            // Over 4.18 the answer is rounded to 0.99999
            responseValue = 99999;
        } else if (truncatedZ >= 40600) {
            // Between 4.06 and 4.17 the answer is rounded to 0.99998
            responseValue = 99998;
        } else if (truncatedZ >= 39800) {
            // Between 3.98 and 4.05 the answer is rounded to 0.99997
            responseValue = 99997;
        } else if (fourthDigit >= 7) {
            // If the fourthDigit is 7, 8 or 9, rounds up to the next data point
            responseValue = _cachedDataPoints[truncatedZ + 100];
        } else if (fourthDigit >= 4) {
            // If the fourthDigit is 4, 5 or 6, get the average between the current and the next
            responseValue = SafeMath.div(
                SafeMath.add(
                    _cachedDataPoints[truncatedZ],
                    _cachedDataPoints[truncatedZ + 100]
                ),
                2
            );
        } else {
            // If the fourthDigit is 0, 1, 2 or 3, rounds down to the current data point
            responseValue = _cachedDataPoints[truncatedZ];
        }

        // Handle negative z
        if (z < 0) {
            responseValue = SafeMath.sub(uint256(100000), responseValue);
        }

        return SafeMath.mul(responseValue, responseDecimals);
    }

    /**
     * @dev Returns the absolute value of a number.
     */
    function _abs(int256 a) internal pure returns (uint256) {
        return a < 0 ? uint256(-a) : uint256(a);
    }

    /**
     * @dev Get z-scores d1 and d2
     *
     ***********************************************************************************************
     * So = spotPrice                                                                             //
     * X  = strikePrice                 ln( So / X ) + t ( r + ( σ² / 2 ) )                       //
     * σ  = implied volatility     d1 = --------------------------------------                    //
     * t  = time                                  σ ( sqrt(t) )                                   //
     * r  = riskFree                                                                              //
     *                             d2 = d1 - σ ( sqrt(t) )                                        //
     ***********************************************************************************************
     *
     * @param spotPrice Asset spot price
     * @param strikePrice Option strike price
     * @param iv Annually volatility on the asset price
     * @param time Annualized time until maturity
     * @param riskFree The risk-free rate
     */
    function _getZScores(
        int256 spotPrice,
        int256 strikePrice,
        int256 iv,
        int256 time,
        int256 riskFree
    ) internal pure returns (int256 d1, int256 d2) {
        int256 iv2 = iv.mul(iv);

        int256 A = spotPrice.div(strikePrice).ln();
        int256 B = (iv2.div(2e18) + riskFree).mul(time);

        int256 n = A + B;
        int256 d = iv.mul(time.sqrt());

        d1 = n.div(d);
        d2 = d1 - d;

        return (d1, d2);
    }

    /**
     * Convert uint256 to int256 taking in account overflow.
     */
    function _uintToInt(uint256 input) internal pure returns (int256) {
        int256 output = int256(input);
        require(output >= 0, "InsurancePricer: casting overflow");
        return output;
    }

    /**
     * Return the additive inverse b of a number a
     */
    function _additiveInverse(int256 a) internal pure returns (int256 b) {
        b = -a;
        bool isAPositive = a > 0;
        bool isBPositive = b > 0;
        require(
            isBPositive != isAPositive,
            "InsurancePricer: additiveInverse overflow"
        );
    }
}

File 2 of 5 : PRBMathSD59x18.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.13;

import "./PRBMath.sol";

/// @title PRBMathSD59x18
/// @author Paul Razvan Berg
/// @notice Smart contract library for advanced fixed-point math that works with int256 numbers considered to have 18
/// trailing decimals. We call this number representation signed 59.18-decimal fixed-point, since the numbers can have
/// a sign and there can be up to 59 digits in the integer part and up to 18 decimals in the fractional part. The numbers
/// are bound by the minimum and the maximum values permitted by the Solidity type int256.
library PRBMathSD59x18 {
    /// @dev log2(e) as a signed 59.18-decimal fixed-point number.
    int256 internal constant LOG2_E = 1_442695040888963407;

    /// @dev Half the SCALE number.
    int256 internal constant HALF_SCALE = 5e17;

    /// @dev The maximum value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MAX_SD59x18 =
        57896044618658097711785492504343953926634992332820282019728_792003956564819967;

    /// @dev The maximum whole value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MAX_WHOLE_SD59x18 =
        57896044618658097711785492504343953926634992332820282019728_000000000000000000;

    /// @dev The minimum value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MIN_SD59x18 =
        -57896044618658097711785492504343953926634992332820282019728_792003956564819968;

    /// @dev The minimum whole value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MIN_WHOLE_SD59x18 =
        -57896044618658097711785492504343953926634992332820282019728_000000000000000000;

    /// @dev How many trailing decimals can be represented.
    int256 internal constant SCALE = 1e18;

    /// INTERNAL FUNCTIONS ///

    /// @notice Calculate the absolute value of x.
    ///
    /// @dev Requirements:
    /// - x must be greater than MIN_SD59x18.
    ///
    /// @param x The number to calculate the absolute value for.
    /// @param result The absolute value of x.
    function abs(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x == MIN_SD59x18) {
                revert PRBMathSD59x18__AbsInputTooSmall();
            }
            result = x < 0 ? -x : x;
        }
    }

    /// @notice Calculates the arithmetic average of x and y, rounding down.
    /// @param x The first operand as a signed 59.18-decimal fixed-point number.
    /// @param y The second operand as a signed 59.18-decimal fixed-point number.
    /// @return result The arithmetic average as a signed 59.18-decimal fixed-point number.
    function avg(int256 x, int256 y) internal pure returns (int256 result) {
        // The operations can never overflow.
        unchecked {
            int256 sum = (x >> 1) + (y >> 1);
            if (sum < 0) {
                // If at least one of x and y is odd, we add 1 to the result. This is because shifting negative numbers to the
                // right rounds down to infinity.
                assembly {
                    result := add(sum, and(or(x, y), 1))
                }
            } else {
                // If both x and y are odd, we add 1 to the result. This is because if both numbers are odd, the 0.5
                // remainder gets truncated twice.
                result = sum + (x & y & 1);
            }
        }
    }

    /// @notice Yields the least greatest signed 59.18 decimal fixed-point number greater 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 must be less than or equal to MAX_WHOLE_SD59x18.
    ///
    /// @param x The signed 59.18-decimal fixed-point number to ceil.
    /// @param result The least integer greater than or equal to x, as a signed 58.18-decimal fixed-point number.
    function ceil(int256 x) internal pure returns (int256 result) {
        if (x > MAX_WHOLE_SD59x18) {
            revert PRBMathSD59x18__CeilOverflow(x);
        }
        unchecked {
            int256 remainder = x % SCALE;
            if (remainder == 0) {
                result = x;
            } else {
                // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                result = x - remainder;
                if (x > 0) {
                    result += SCALE;
                }
            }
        }
    }

    /// @notice Divides two signed 59.18-decimal fixed-point numbers, returning a new signed 59.18-decimal fixed-point number.
    ///
    /// @dev Variant of "mulDiv" that works with signed numbers. Works by computing the signs and the absolute values separately.
    ///
    /// Requirements:
    /// - All from "PRBMath.mulDiv".
    /// - None of the inputs can be MIN_SD59x18.
    /// - The denominator cannot be zero.
    /// - The result must fit within int256.
    ///
    /// Caveats:
    /// - All from "PRBMath.mulDiv".
    ///
    /// @param x The numerator as a signed 59.18-decimal fixed-point number.
    /// @param y The denominator as a signed 59.18-decimal fixed-point number.
    /// @param result The quotient as a signed 59.18-decimal fixed-point number.
    function div(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == MIN_SD59x18 || y == MIN_SD59x18) {
            revert PRBMathSD59x18__DivInputTooSmall();
        }

        // Get hold of the absolute values of x and y.
        uint256 ax;
        uint256 ay;
        unchecked {
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);
        }

        // Compute the absolute value of (x*SCALE)÷y. The result must fit within int256.
        uint256 rAbs = PRBMath.mulDiv(ax, uint256(SCALE), ay);
        if (rAbs > uint256(MAX_SD59x18)) {
            revert PRBMathSD59x18__DivOverflow(rAbs);
        }

        // Get the signs of x and y.
        uint256 sx;
        uint256 sy;
        assembly {
            sx := sgt(x, sub(0, 1))
            sy := sgt(y, sub(0, 1))
        }

        // XOR over sx and sy. This is basically checking whether the inputs have the same sign. If yes, the result
        // should be positive. Otherwise, it should be negative.
        result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Returns Euler's number as a signed 59.18-decimal fixed-point number.
    /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant).
    function e() internal pure returns (int256 result) {
        result = 2_718281828459045235;
    }

    /// @notice Calculates the natural exponent of x.
    ///
    /// @dev Based on the insight that e^x = 2^(x * log2(e)).
    ///
    /// Requirements:
    /// - All from "log2".
    /// - x must be less than 133.084258667509499441.
    ///
    /// Caveats:
    /// - All from "exp2".
    /// - For any x less than -41.446531673892822322, the result is zero.
    ///
    /// @param x The exponent as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function exp(int256 x) internal pure returns (int256 result) {
        // Without this check, the value passed to "exp2" would be less than -59.794705707972522261.
        if (x < -41_446531673892822322) {
            return 0;
        }

        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133_084258667509499441) {
            revert PRBMathSD59x18__ExpInputTooBig(x);
        }

        // Do the fixed-point multiplication inline to save gas.
        unchecked {
            int256 doubleScaleProduct = x * LOG2_E;
            result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE);
        }
    }

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    ///
    /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
    ///
    /// Requirements:
    /// - x must be 192 or less.
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - For any x less than -59.794705707972522261, the result is zero.
    ///
    /// @param x The exponent as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function exp2(int256 x) internal pure returns (int256 result) {
        // This works because 2^(-x) = 1/2^x.
        if (x < 0) {
            // 2^59.794705707972522262 is the maximum number whose inverse does not truncate down to zero.
            if (x < -59_794705707972522261) {
                return 0;
            }

            // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE.
            unchecked {
                result = 1e36 / exp2(-x);
            }
        } else {
            // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
            if (x >= 192e18) {
                revert PRBMathSD59x18__Exp2InputTooBig(x);
            }

            unchecked {
                // Convert x to the 192.64-bit fixed-point format.
                uint256 x192x64 = (uint256(x) << 64) / uint256(SCALE);

                // Safe to convert the result to int256 directly because the maximum input allowed is 192.
                result = int256(PRBMath.exp2(x192x64));
            }
        }
    }

    /// @notice Yields the greatest signed 59.18 decimal fixed-point 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 must be greater than or equal to MIN_WHOLE_SD59x18.
    ///
    /// @param x The signed 59.18-decimal fixed-point number to floor.
    /// @param result The greatest integer less than or equal to x, as a signed 58.18-decimal fixed-point number.
    function floor(int256 x) internal pure returns (int256 result) {
        if (x < MIN_WHOLE_SD59x18) {
            revert PRBMathSD59x18__FloorUnderflow(x);
        }
        unchecked {
            int256 remainder = x % SCALE;
            if (remainder == 0) {
                result = x;
            } else {
                // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                result = x - remainder;
                if (x < 0) {
                    result -= SCALE;
                }
            }
        }
    }

    /// @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 signed 59.18-decimal fixed-point number to get the fractional part of.
    /// @param result The fractional part of x as a signed 59.18-decimal fixed-point number.
    function frac(int256 x) internal pure returns (int256 result) {
        unchecked {
            result = x % SCALE;
        }
    }

    /// @notice Converts a number from basic integer form to signed 59.18-decimal fixed-point representation.
    ///
    /// @dev Requirements:
    /// - x must be greater than or equal to MIN_SD59x18 divided by SCALE.
    /// - x must be less than or equal to MAX_SD59x18 divided by SCALE.
    ///
    /// @param x The basic integer to convert.
    /// @param result The same number in signed 59.18-decimal fixed-point representation.
    function fromInt(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x < MIN_SD59x18 / SCALE) {
                revert PRBMathSD59x18__FromIntUnderflow(x);
            }
            if (x > MAX_SD59x18 / SCALE) {
                revert PRBMathSD59x18__FromIntOverflow(x);
            }
            result = x * SCALE;
        }
    }

    /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down.
    ///
    /// @dev Requirements:
    /// - x * y must fit within MAX_SD59x18, lest it overflows.
    /// - x * y cannot be negative.
    ///
    /// @param x The first operand as a signed 59.18-decimal fixed-point number.
    /// @param y The second operand as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function gm(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == 0) {
            return 0;
        }

        unchecked {
            // Checking for overflow this way is faster than letting Solidity do it.
            int256 xy = x * y;
            if (xy / x != y) {
                revert PRBMathSD59x18__GmOverflow(x, y);
            }

            // The product cannot be negative.
            if (xy < 0) {
                revert PRBMathSD59x18__GmNegativeProduct(x, y);
            }

            // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE
            // during multiplication. See the comments within the "sqrt" function.
            result = int256(PRBMath.sqrt(uint256(xy)));
        }
    }

    /// @notice Calculates 1 / x, rounding toward zero.
    ///
    /// @dev Requirements:
    /// - x cannot be zero.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the inverse.
    /// @return result The inverse as a signed 59.18-decimal fixed-point number.
    function inv(int256 x) internal pure returns (int256 result) {
        unchecked {
            // 1e36 is SCALE * SCALE.
            result = 1e36 / x;
        }
    }

    /// @notice Calculates the natural logarithm of x.
    ///
    /// @dev Based on the insight that ln(x) = log2(x) / log2(e).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    /// - This doesn't return exactly 1 for 2718281828459045235, for that we would need more fine-grained precision.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the natural logarithm.
    /// @return result The natural logarithm as a signed 59.18-decimal fixed-point number.
    function ln(int256 x) internal pure returns (int256 result) {
        // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x)
        // can return is 195205294292027477728.
        unchecked {
            result = (log2(x) * SCALE) / LOG2_E;
        }
    }

    /// @notice Calculates the common logarithm of x.
    ///
    /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common
    /// logarithm based on the insight that log10(x) = log2(x) / log2(10).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the common logarithm.
    /// @return result The common logarithm as a signed 59.18-decimal fixed-point number.
    function log10(int256 x) internal pure returns (int256 result) {
        if (x <= 0) {
            revert PRBMathSD59x18__LogInputTooSmall(x);
        }

        // Note that the "mul" in this block is the assembly mul operation, not the "mul" function defined in this contract.
        // prettier-ignore
        assembly {
            switch x
            case 1 { result := mul(SCALE, sub(0, 18)) }
            case 10 { result := mul(SCALE, sub(1, 18)) }
            case 100 { result := mul(SCALE, sub(2, 18)) }
            case 1000 { result := mul(SCALE, sub(3, 18)) }
            case 10000 { result := mul(SCALE, sub(4, 18)) }
            case 100000 { result := mul(SCALE, sub(5, 18)) }
            case 1000000 { result := mul(SCALE, sub(6, 18)) }
            case 10000000 { result := mul(SCALE, sub(7, 18)) }
            case 100000000 { result := mul(SCALE, sub(8, 18)) }
            case 1000000000 { result := mul(SCALE, sub(9, 18)) }
            case 10000000000 { result := mul(SCALE, sub(10, 18)) }
            case 100000000000 { result := mul(SCALE, sub(11, 18)) }
            case 1000000000000 { result := mul(SCALE, sub(12, 18)) }
            case 10000000000000 { result := mul(SCALE, sub(13, 18)) }
            case 100000000000000 { result := mul(SCALE, sub(14, 18)) }
            case 1000000000000000 { result := mul(SCALE, sub(15, 18)) }
            case 10000000000000000 { result := mul(SCALE, sub(16, 18)) }
            case 100000000000000000 { result := mul(SCALE, sub(17, 18)) }
            case 1000000000000000000 { result := 0 }
            case 10000000000000000000 { result := SCALE }
            case 100000000000000000000 { result := mul(SCALE, 2) }
            case 1000000000000000000000 { result := mul(SCALE, 3) }
            case 10000000000000000000000 { result := mul(SCALE, 4) }
            case 100000000000000000000000 { result := mul(SCALE, 5) }
            case 1000000000000000000000000 { result := mul(SCALE, 6) }
            case 10000000000000000000000000 { result := mul(SCALE, 7) }
            case 100000000000000000000000000 { result := mul(SCALE, 8) }
            case 1000000000000000000000000000 { result := mul(SCALE, 9) }
            case 10000000000000000000000000000 { result := mul(SCALE, 10) }
            case 100000000000000000000000000000 { result := mul(SCALE, 11) }
            case 1000000000000000000000000000000 { result := mul(SCALE, 12) }
            case 10000000000000000000000000000000 { result := mul(SCALE, 13) }
            case 100000000000000000000000000000000 { result := mul(SCALE, 14) }
            case 1000000000000000000000000000000000 { result := mul(SCALE, 15) }
            case 10000000000000000000000000000000000 { result := mul(SCALE, 16) }
            case 100000000000000000000000000000000000 { result := mul(SCALE, 17) }
            case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) }
            case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) }
            case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) }
            case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) }
            case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) }
            case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) }
            case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) }
            case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) }
            case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) }
            case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) }
            case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) }
            case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) }
            case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) }
            case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) }
            case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) }
            case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) }
            case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) }
            case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) }
            case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) }
            case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) }
            case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) }
            case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) }
            case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) }
            case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) }
            case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) }
            case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) }
            case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) }
            case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) }
            case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) }
            case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) }
            case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) }
            case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) }
            case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) }
            default {
                result := MAX_SD59x18
            }
        }

        if (result == MAX_SD59x18) {
            // Do the fixed-point division inline to save gas. The denominator is log2(10).
            unchecked {
                result = (log2(x) * SCALE) / 3_321928094887362347;
            }
        }
    }

    /// @notice Calculates the binary logarithm of x.
    ///
    /// @dev Based on the iterative approximation algorithm.
    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
    ///
    /// Requirements:
    /// - x must be greater than zero.
    ///
    /// Caveats:
    /// - The results are not perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the binary logarithm.
    /// @return result The binary logarithm as a signed 59.18-decimal fixed-point number.
    function log2(int256 x) internal pure returns (int256 result) {
        if (x <= 0) {
            revert PRBMathSD59x18__LogInputTooSmall(x);
        }
        unchecked {
            // This works because log2(x) = -log2(1/x).
            int256 sign;
            if (x >= SCALE) {
                sign = 1;
            } else {
                sign = -1;
                // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE.
                assembly {
                    x := div(1000000000000000000000000000000000000, x)
                }
            }

            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).
            uint256 n = PRBMath.mostSignificantBit(uint256(x / SCALE));

            // The integer part of the logarithm as a signed 59.18-decimal fixed-point number. The operation can't overflow
            // because n is maximum 255, SCALE is 1e18 and sign is either 1 or -1.
            result = int256(n) * SCALE;

            // This is y = x * 2^(-n).
            int256 y = x >> n;

            // If y = 1, the fractional part is zero.
            if (y == SCALE) {
                return result * sign;
            }

            // Calculate the fractional part via the iterative approximation.
            // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster.
            for (int256 delta = int256(HALF_SCALE); delta > 0; delta >>= 1) {
                y = (y * y) / SCALE;

                // Is y^2 > 2 and so in the range [2,4)?
                if (y >= 2 * SCALE) {
                    // Add the 2^(-m) factor to the logarithm.
                    result += delta;

                    // Corresponds to z/2 on Wikipedia.
                    y >>= 1;
                }
            }
            result *= sign;
        }
    }

    /// @notice Multiplies two signed 59.18-decimal fixed-point numbers together, returning a new signed 59.18-decimal
    /// fixed-point number.
    ///
    /// @dev Variant of "mulDiv" that works with signed numbers and employs constant folding, i.e. the denominator is
    /// always 1e18.
    ///
    /// Requirements:
    /// - All from "PRBMath.mulDivFixedPoint".
    /// - None of the inputs can be MIN_SD59x18
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works.
    ///
    /// @param x The multiplicand as a signed 59.18-decimal fixed-point number.
    /// @param y The multiplier as a signed 59.18-decimal fixed-point number.
    /// @return result The product as a signed 59.18-decimal fixed-point number.
    function mul(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == MIN_SD59x18 || y == MIN_SD59x18) {
            revert PRBMathSD59x18__MulInputTooSmall();
        }

        unchecked {
            uint256 ax;
            uint256 ay;
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);

            uint256 rAbs = PRBMath.mulDivFixedPoint(ax, ay);
            if (rAbs > uint256(MAX_SD59x18)) {
                revert PRBMathSD59x18__MulOverflow(rAbs);
            }

            uint256 sx;
            uint256 sy;
            assembly {
                sx := sgt(x, sub(0, 1))
                sy := sgt(y, sub(0, 1))
            }
            result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs);
        }
    }

    /// @notice Returns PI as a signed 59.18-decimal fixed-point number.
    function pi() internal pure returns (int256 result) {
        result = 3_141592653589793238;
    }

    /// @notice Raises x to the power of y.
    ///
    /// @dev Based on the insight that x^y = 2^(log2(x) * y).
    ///
    /// Requirements:
    /// - All from "exp2", "log2" and "mul".
    /// - z cannot be zero.
    ///
    /// Caveats:
    /// - All from "exp2", "log2" and "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x Number to raise to given power y, as a signed 59.18-decimal fixed-point number.
    /// @param y Exponent to raise x to, as a signed 59.18-decimal fixed-point number.
    /// @return result x raised to power y, as a signed 59.18-decimal fixed-point number.
    function pow(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == 0) {
            result = y == 0 ? SCALE : int256(0);
        } else {
            result = exp2(mul(log2(x), y));
        }
    }

    /// @notice Raises x (signed 59.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
    /// famous algorithm "exponentiation by squaring".
    ///
    /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
    ///
    /// Requirements:
    /// - All from "abs" and "PRBMath.mulDivFixedPoint".
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - All from "PRBMath.mulDivFixedPoint".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x The base as a signed 59.18-decimal fixed-point number.
    /// @param y The exponent as an uint256.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function powu(int256 x, uint256 y) internal pure returns (int256 result) {
        uint256 xAbs = uint256(abs(x));

        // Calculate the first iteration of the loop in advance.
        uint256 rAbs = y & 1 > 0 ? xAbs : uint256(SCALE);

        // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster.
        uint256 yAux = y;
        for (yAux >>= 1; yAux > 0; yAux >>= 1) {
            xAbs = PRBMath.mulDivFixedPoint(xAbs, xAbs);

            // Equivalent to "y % 2 == 1" but faster.
            if (yAux & 1 > 0) {
                rAbs = PRBMath.mulDivFixedPoint(rAbs, xAbs);
            }
        }

        // The result must fit within the 59.18-decimal fixed-point representation.
        if (rAbs > uint256(MAX_SD59x18)) {
            revert PRBMathSD59x18__PowuOverflow(rAbs);
        }

        // Is the base negative and the exponent an odd number?
        bool isNegative = x < 0 && y & 1 == 1;
        result = isNegative ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Returns 1 as a signed 59.18-decimal fixed-point number.
    function scale() internal pure returns (int256 result) {
        result = SCALE;
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Requirements:
    /// - x cannot be negative.
    /// - x must be less than MAX_SD59x18 / SCALE.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the square root.
    /// @return result The result as a signed 59.18-decimal fixed-point .
    function sqrt(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x < 0) {
                revert PRBMathSD59x18__SqrtNegativeInput(x);
            }
            if (x > MAX_SD59x18 / SCALE) {
                revert PRBMathSD59x18__SqrtOverflow(x);
            }
            // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two signed
            // 59.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root).
            result = int256(PRBMath.sqrt(uint256(x * SCALE)));
        }
    }

    /// @notice Converts a signed 59.18-decimal fixed-point number to basic integer form, rounding down in the process.
    /// @param x The signed 59.18-decimal fixed-point number to convert.
    /// @return result The same number in basic integer form.
    function toInt(int256 x) internal pure returns (int256 result) {
        unchecked {
            result = x / SCALE;
        }
    }
}

File 3 of 5 : PRBMathUD60x18.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.13;

import "./PRBMath.sol";

/// @title PRBMathUD60x18
/// @author Paul Razvan Berg
/// @notice Smart contract library for advanced fixed-point math that works with uint256 numbers considered to have 18
/// trailing decimals. We call this number representation unsigned 60.18-decimal fixed-point, since there can be up to 60
/// digits in the integer part and up to 18 decimals in the fractional part. The numbers are bound by the minimum and the
/// maximum values permitted by the Solidity type uint256.
library PRBMathUD60x18 {
    /// @dev Half the SCALE number.
    uint256 internal constant HALF_SCALE = 5e17;

    /// @dev log2(e) as an unsigned 60.18-decimal fixed-point number.
    uint256 internal constant LOG2_E = 1_442695040888963407;

    /// @dev The maximum value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_584007913129639935;

    /// @dev The maximum whole value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_WHOLE_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_000000000000000000;

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @notice Calculates the arithmetic average of x and y, rounding down.
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number.
    function avg(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // The operations can never overflow.
        unchecked {
            // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need
            // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice.
            result = (x >> 1) + (y >> 1) + (x & y & 1);
        }
    }

    /// @notice Yields the least unsigned 60.18 decimal fixed-point number greater 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 must be less than or equal to MAX_WHOLE_UD60x18.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number to ceil.
    /// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function ceil(uint256 x) internal pure returns (uint256 result) {
        if (x > MAX_WHOLE_UD60x18) {
            revert PRBMathUD60x18__CeilOverflow(x);
        }
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "SCALE - remainder" but faster.
            let delta := sub(SCALE, remainder)

            // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster.
            result := add(x, mul(delta, gt(remainder, 0)))
        }
    }

    /// @notice Divides two unsigned 60.18-decimal fixed-point numbers, returning a new unsigned 60.18-decimal fixed-point number.
    ///
    /// @dev Uses mulDiv to enable overflow-safe multiplication and division.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    ///
    /// @param x The numerator as an unsigned 60.18-decimal fixed-point number.
    /// @param y The denominator as an unsigned 60.18-decimal fixed-point number.
    /// @param result The quotient as an unsigned 60.18-decimal fixed-point number.
    function div(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDiv(x, SCALE, y);
    }

    /// @notice Returns Euler's number as an unsigned 60.18-decimal fixed-point number.
    /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant).
    function e() internal pure returns (uint256 result) {
        result = 2_718281828459045235;
    }

    /// @notice Calculates the natural exponent of x.
    ///
    /// @dev Based on the insight that e^x = 2^(x * log2(e)).
    ///
    /// Requirements:
    /// - All from "log2".
    /// - x must be less than 133.084258667509499441.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp(uint256 x) internal pure returns (uint256 result) {
        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133_084258667509499441) {
            revert PRBMathUD60x18__ExpInputTooBig(x);
        }

        // Do the fixed-point multiplication inline to save gas.
        unchecked {
            uint256 doubleScaleProduct = x * LOG2_E;
            result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE);
        }
    }

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    ///
    /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
    ///
    /// Requirements:
    /// - x must be 192 or less.
    /// - The result must fit within MAX_UD60x18.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
        if (x >= 192e18) {
            revert PRBMathUD60x18__Exp2InputTooBig(x);
        }

        unchecked {
            // Convert x to the 192.64-bit fixed-point format.
            uint256 x192x64 = (x << 64) / SCALE;

            // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation.
            result = PRBMath.exp2(x192x64);
        }
    }

    /// @notice Yields the greatest unsigned 60.18 decimal fixed-point 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.
    /// @param x The unsigned 60.18-decimal fixed-point number to floor.
    /// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function floor(uint256 x) internal pure returns (uint256 result) {
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster.
            result := sub(x, mul(remainder, gt(remainder, 0)))
        }
    }

    /// @notice Yields the excess beyond the floor of x.
    /// @dev Based on the odd function definition https://en.wikipedia.org/wiki/Fractional_part.
    /// @param x The unsigned 60.18-decimal fixed-point number to get the fractional part of.
    /// @param result The fractional part of x as an unsigned 60.18-decimal fixed-point number.
    function frac(uint256 x) internal pure returns (uint256 result) {
        assembly {
            result := mod(x, SCALE)
        }
    }

    /// @notice Converts a number from basic integer form to unsigned 60.18-decimal fixed-point representation.
    ///
    /// @dev Requirements:
    /// - x must be less than or equal to MAX_UD60x18 divided by SCALE.
    ///
    /// @param x The basic integer to convert.
    /// @param result The same number in unsigned 60.18-decimal fixed-point representation.
    function fromUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__FromUintOverflow(x);
            }
            result = x * SCALE;
        }
    }

    /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down.
    ///
    /// @dev Requirements:
    /// - x * y must fit within MAX_UD60x18, lest it overflows.
    ///
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function gm(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        unchecked {
            // Checking for overflow this way is faster than letting Solidity do it.
            uint256 xy = x * y;
            if (xy / x != y) {
                revert PRBMathUD60x18__GmOverflow(x, y);
            }

            // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE
            // during multiplication. See the comments within the "sqrt" function.
            result = PRBMath.sqrt(xy);
        }
    }

    /// @notice Calculates 1 / x, rounding toward zero.
    ///
    /// @dev Requirements:
    /// - x cannot be zero.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the inverse.
    /// @return result The inverse as an unsigned 60.18-decimal fixed-point number.
    function inv(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // 1e36 is SCALE * SCALE.
            result = 1e36 / x;
        }
    }

    /// @notice Calculates the natural logarithm of x.
    ///
    /// @dev Based on the insight that ln(x) = log2(x) / log2(e).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    /// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm.
    /// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number.
    function ln(uint256 x) internal pure returns (uint256 result) {
        // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x)
        // can return is 196205294292027477728.
        unchecked {
            result = (log2(x) * SCALE) / LOG2_E;
        }
    }

    /// @notice Calculates the common logarithm of x.
    ///
    /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common
    /// logarithm based on the insight that log10(x) = log2(x) / log2(10).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the common logarithm.
    /// @return result The common logarithm as an unsigned 60.18-decimal fixed-point number.
    function log10(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }

        // Note that the "mul" in this block is the assembly multiplication operation, not the "mul" function defined
        // in this contract.
        // prettier-ignore
        assembly {
            switch x
            case 1 { result := mul(SCALE, sub(0, 18)) }
            case 10 { result := mul(SCALE, sub(1, 18)) }
            case 100 { result := mul(SCALE, sub(2, 18)) }
            case 1000 { result := mul(SCALE, sub(3, 18)) }
            case 10000 { result := mul(SCALE, sub(4, 18)) }
            case 100000 { result := mul(SCALE, sub(5, 18)) }
            case 1000000 { result := mul(SCALE, sub(6, 18)) }
            case 10000000 { result := mul(SCALE, sub(7, 18)) }
            case 100000000 { result := mul(SCALE, sub(8, 18)) }
            case 1000000000 { result := mul(SCALE, sub(9, 18)) }
            case 10000000000 { result := mul(SCALE, sub(10, 18)) }
            case 100000000000 { result := mul(SCALE, sub(11, 18)) }
            case 1000000000000 { result := mul(SCALE, sub(12, 18)) }
            case 10000000000000 { result := mul(SCALE, sub(13, 18)) }
            case 100000000000000 { result := mul(SCALE, sub(14, 18)) }
            case 1000000000000000 { result := mul(SCALE, sub(15, 18)) }
            case 10000000000000000 { result := mul(SCALE, sub(16, 18)) }
            case 100000000000000000 { result := mul(SCALE, sub(17, 18)) }
            case 1000000000000000000 { result := 0 }
            case 10000000000000000000 { result := SCALE }
            case 100000000000000000000 { result := mul(SCALE, 2) }
            case 1000000000000000000000 { result := mul(SCALE, 3) }
            case 10000000000000000000000 { result := mul(SCALE, 4) }
            case 100000000000000000000000 { result := mul(SCALE, 5) }
            case 1000000000000000000000000 { result := mul(SCALE, 6) }
            case 10000000000000000000000000 { result := mul(SCALE, 7) }
            case 100000000000000000000000000 { result := mul(SCALE, 8) }
            case 1000000000000000000000000000 { result := mul(SCALE, 9) }
            case 10000000000000000000000000000 { result := mul(SCALE, 10) }
            case 100000000000000000000000000000 { result := mul(SCALE, 11) }
            case 1000000000000000000000000000000 { result := mul(SCALE, 12) }
            case 10000000000000000000000000000000 { result := mul(SCALE, 13) }
            case 100000000000000000000000000000000 { result := mul(SCALE, 14) }
            case 1000000000000000000000000000000000 { result := mul(SCALE, 15) }
            case 10000000000000000000000000000000000 { result := mul(SCALE, 16) }
            case 100000000000000000000000000000000000 { result := mul(SCALE, 17) }
            case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) }
            case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) }
            case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) }
            case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) }
            case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) }
            case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) }
            case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) }
            case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) }
            case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) }
            case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) }
            case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) }
            case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) }
            case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) }
            case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) }
            case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) }
            case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) }
            case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) }
            case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) }
            case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) }
            case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) }
            case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) }
            case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) }
            case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) }
            case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) }
            case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) }
            case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) }
            case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) }
            case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) }
            case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) }
            case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) }
            case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) }
            case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) }
            case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 59) }
            default {
                result := MAX_UD60x18
            }
        }

        if (result == MAX_UD60x18) {
            // Do the fixed-point division inline to save gas. The denominator is log2(10).
            unchecked {
                result = (log2(x) * SCALE) / 3_321928094887362347;
            }
        }
    }

    /// @notice Calculates the binary logarithm of x.
    ///
    /// @dev Based on the iterative approximation algorithm.
    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
    ///
    /// Requirements:
    /// - x must be greater than or equal to SCALE, otherwise the result would be negative.
    ///
    /// Caveats:
    /// - The results are nor perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the binary logarithm.
    /// @return result The binary logarithm as an unsigned 60.18-decimal fixed-point number.
    function log2(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }
        unchecked {
            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).
            uint256 n = PRBMath.mostSignificantBit(x / SCALE);

            // The integer part of the logarithm as an unsigned 60.18-decimal fixed-point number. The operation can't overflow
            // because n is maximum 255 and SCALE is 1e18.
            result = n * SCALE;

            // This is y = x * 2^(-n).
            uint256 y = x >> n;

            // If y = 1, the fractional part is zero.
            if (y == SCALE) {
                return result;
            }

            // Calculate the fractional part via the iterative approximation.
            // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster.
            for (uint256 delta = HALF_SCALE; delta > 0; delta >>= 1) {
                y = (y * y) / SCALE;

                // Is y^2 > 2 and so in the range [2,4)?
                if (y >= 2 * SCALE) {
                    // Add the 2^(-m) factor to the logarithm.
                    result += delta;

                    // Corresponds to z/2 on Wikipedia.
                    y >>= 1;
                }
            }
        }
    }

    /// @notice Multiplies two unsigned 60.18-decimal fixed-point numbers together, returning a new unsigned 60.18-decimal
    /// fixed-point number.
    /// @dev See the documentation for the "PRBMath.mulDivFixedPoint" function.
    /// @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 product as an unsigned 60.18-decimal fixed-point number.
    function mul(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDivFixedPoint(x, y);
    }

    /// @notice Returns PI as an unsigned 60.18-decimal fixed-point number.
    function pi() internal pure returns (uint256 result) {
        result = 3_141592653589793238;
    }

    /// @notice Raises x to the power of y.
    ///
    /// @dev Based on the insight that x^y = 2^(log2(x) * y).
    ///
    /// Requirements:
    /// - All from "exp2", "log2" and "mul".
    ///
    /// Caveats:
    /// - All from "exp2", "log2" and "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number.
    /// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number.
    /// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number.
    function pow(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            result = y == 0 ? SCALE : uint256(0);
        } else {
            result = exp2(mul(log2(x), y));
        }
    }

    /// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
    /// famous algorithm "exponentiation by squaring".
    ///
    /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
    ///
    /// Requirements:
    /// - The result must fit within MAX_UD60x18.
    ///
    /// Caveats:
    /// - All from "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x The base as an unsigned 60.18-decimal fixed-point number.
    /// @param y The exponent as an uint256.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function powu(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // Calculate the first iteration of the loop in advance.
        result = y & 1 > 0 ? x : SCALE;

        // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster.
        for (y >>= 1; y > 0; y >>= 1) {
            x = PRBMath.mulDivFixedPoint(x, x);

            // Equivalent to "y % 2 == 1" but faster.
            if (y & 1 > 0) {
                result = PRBMath.mulDivFixedPoint(result, x);
            }
        }
    }

    /// @notice Returns 1 as an unsigned 60.18-decimal fixed-point number.
    function scale() internal pure returns (uint256 result) {
        result = SCALE;
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Requirements:
    /// - x must be less than MAX_UD60x18 / SCALE.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root.
    /// @return result The result as an unsigned 60.18-decimal fixed-point .
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__SqrtOverflow(x);
            }
            // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned
            // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root).
            result = PRBMath.sqrt(x * SCALE);
        }
    }

    /// @notice Converts a unsigned 60.18-decimal fixed-point number to basic integer form, rounding down in the process.
    /// @param x The unsigned 60.18-decimal fixed-point number to convert.
    /// @return result The same number in basic integer form.
    function toUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            result = x / SCALE;
        }
    }
}

File 4 of 5 : SafeMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol)

pragma solidity >=0.8.13;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b)
        internal
        pure
        returns (bool, uint256)
    {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

File 5 of 5 : PRBMath.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.13;

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivFixedPointOverflow(uint256 prod1);

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator);

/// @notice Emitted when one of the inputs is type(int256).min.
error PRBMath__MulDivSignedInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows int256.
error PRBMath__MulDivSignedOverflow(uint256 rAbs);

/// @notice Emitted when the input is MIN_SD59x18.
error PRBMathSD59x18__AbsInputTooSmall();

/// @notice Emitted when ceiling a number overflows SD59x18.
error PRBMathSD59x18__CeilOverflow(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__DivInputTooSmall();

/// @notice Emitted when one of the intermediary unsigned results overflows SD59x18.
error PRBMathSD59x18__DivOverflow(uint256 rAbs);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathSD59x18__ExpInputTooBig(int256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathSD59x18__Exp2InputTooBig(int256 x);

/// @notice Emitted when flooring a number underflows SD59x18.
error PRBMathSD59x18__FloorUnderflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMathSD59x18__FromIntOverflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMathSD59x18__FromIntUnderflow(int256 x);

/// @notice Emitted when the product of the inputs is negative.
error PRBMathSD59x18__GmNegativeProduct(int256 x, int256 y);

/// @notice Emitted when multiplying the inputs overflows SD59x18.
error PRBMathSD59x18__GmOverflow(int256 x, int256 y);

/// @notice Emitted when the input is less than or equal to zero.
error PRBMathSD59x18__LogInputTooSmall(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__MulInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__MulOverflow(uint256 rAbs);

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__PowuOverflow(uint256 rAbs);

/// @notice Emitted when the input is negative.
error PRBMathSD59x18__SqrtNegativeInput(int256 x);

/// @notice Emitted when the calculating the square root overflows SD59x18.
error PRBMathSD59x18__SqrtOverflow(int256 x);

/// @notice Emitted when addition overflows UD60x18.
error PRBMathUD60x18__AddOverflow(uint256 x, uint256 y);

/// @notice Emitted when ceiling a number overflows UD60x18.
error PRBMathUD60x18__CeilOverflow(uint256 x);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathUD60x18__ExpInputTooBig(uint256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathUD60x18__Exp2InputTooBig(uint256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format format overflows UD60x18.
error PRBMathUD60x18__FromUintOverflow(uint256 x);

/// @notice Emitted when multiplying the inputs overflows UD60x18.
error PRBMathUD60x18__GmOverflow(uint256 x, uint256 y);

/// @notice Emitted when the input is less than 1.
error PRBMathUD60x18__LogInputTooSmall(uint256 x);

/// @notice Emitted when the calculating the square root overflows UD60x18.
error PRBMathUD60x18__SqrtOverflow(uint256 x);

/// @notice Emitted when subtraction underflows UD60x18.
error PRBMathUD60x18__SubUnderflow(uint256 x, uint256 y);

/// @dev Common mathematical functions used in both PRBMathSD59x18 and PRBMathUD60x18. Note that this shared library
/// does not always assume the signed 59.18-decimal fixed-point or the unsigned 60.18-decimal fixed-point
/// representation. When it does not, it is explicitly mentioned in the NatSpec documentation.
library PRBMath {
    /// STRUCTS ///

    struct SD59x18 {
        int256 value;
    }

    struct UD60x18 {
        uint256 value;
    }

    /// STORAGE ///

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @dev Largest power of two divisor of SCALE.
    uint256 internal constant SCALE_LPOTD = 262144;

    /// @dev SCALE inverted mod 2^256.
    uint256 internal constant SCALE_INVERSE =
        78156646155174841979727994598816262306175212592076161876661_508869554232690281;

    /// 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.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // Start from 0.5 in the 192.64-bit fixed-point format.
            result = 0x800000000000000000000000000000000000000000000000;

            // Multiply the result by root(2, 2^-i) when the bit at position i is 1. None of the intermediary results overflows
            // because the initial result is 2^191 and all magic factors are less than 2^65.
            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 & 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 & 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 & 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 & 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 & 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 & 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 & 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;
            }

            // We're doing two things at the same time:
            //
            //   1. Multiply the result by 2^n + 1, where "2^n" is the integer part and the one is added to account for
            //      the fact that we initially set the result to 0.5. This is accomplished by subtracting from 191
            //      rather than 192.
            //   2. Convert the result to the unsigned 60.18-decimal fixed-point format.
            //
            // This works because 2^(191-ip) = 2^ip / 2^191, where "ip" is the integer part "2^n".
            result *= SCALE;
            result >>= (191 - (x >> 64));
        }
    }

    /// @notice Finds the zero-based index of the first one in the binary representation of x.
    /// @dev See the note on msb in the "Find First Set" Wikipedia article https://en.wikipedia.org/wiki/Find_first_set
    /// @param x The uint256 number for which to find the index of the most significant bit.
    /// @return msb The index of the most significant bit as an uint256.
    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {
        if (x >= 2**128) {
            x >>= 128;
            msb += 128;
        }
        if (x >= 2**64) {
            x >>= 64;
            msb += 64;
        }
        if (x >= 2**32) {
            x >>= 32;
            msb += 32;
        }
        if (x >= 2**16) {
            x >>= 16;
            msb += 16;
        }
        if (x >= 2**8) {
            x >>= 8;
            msb += 8;
        }
        if (x >= 2**4) {
            x >>= 4;
            msb += 4;
        }
        if (x >= 2**2) {
            x >>= 2;
            msb += 2;
        }
        if (x >= 2**1) {
            // No need to shift x any more.
            msb += 1;
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The multiplicand as an uint256.
    /// @param y The multiplier as an uint256.
    /// @param denominator The divisor as an uint256.
    /// @return result The result as an uint256.
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal 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 {
            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 {
                result = prod0 / denominator;
            }
            return result;
        }

        // Make sure the result is less than 2^256. Also prevents denominator == 0.
        if (prod1 >= denominator) {
            revert PRBMath__MulDivOverflow(prod1, denominator);
        }

        ///////////////////////////////////////////////
        // 512 by 256 division.
        ///////////////////////////////////////////////

        // Make division exact by subtracting the remainder from [prod1 prod0].
        uint256 remainder;
        assembly {
            // Compute remainder using mulmod.
            remainder := mulmod(x, y, denominator)

            // Subtract 256 bit number from 512 bit number.
            prod1 := sub(prod1, gt(remainder, prod0))
            prod0 := sub(prod0, remainder)
        }

        // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
        // See https://cs.stackexchange.com/q/138556/92363.
        unchecked {
            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 lpotdod = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by lpotdod.
                denominator := div(denominator, lpotdod)

                // Divide [prod1 prod0] by lpotdod.
                prod0 := div(prod0, lpotdod)

                // Flip lpotdod such that it is 2^256 / lpotdod. If lpotdod is zero, then it becomes one.
                lpotdod := add(div(sub(0, lpotdod), lpotdod), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * lpotdod;

            // 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;
            return result;
        }
    }

    /// @notice Calculates floor(x*y÷1e18) with full precision.
    ///
    /// @dev Variant of "mulDiv" with constant folding, i.e. in which the denominator is always 1e18. Before returning the
    /// final result, we add 1 if (x * y) % SCALE >= HALF_SCALE. Without this, 6.6e-19 would be truncated to 0 instead of
    /// being rounded to 1e-18.  See "Listing 6" and text above it at https://accu.org/index.php/journals/1717.
    ///
    /// Requirements:
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works.
    /// - It is assumed that the result can never be type(uint256).max when x and y solve the following two equations:
    ///     1. x * y = type(uint256).max * SCALE
    ///     2. (x * y) % SCALE >= SCALE / 2
    ///
    /// @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.
    function mulDivFixedPoint(uint256 x, uint256 y)
        internal
        pure
        returns (uint256 result)
    {
        uint256 prod0;
        uint256 prod1;
        assembly {
            let mm := mulmod(x, y, not(0))
            prod0 := mul(x, y)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        if (prod1 >= SCALE) {
            revert PRBMath__MulDivFixedPointOverflow(prod1);
        }

        uint256 remainder;
        uint256 roundUpUnit;
        assembly {
            remainder := mulmod(x, y, SCALE)
            roundUpUnit := gt(remainder, 499999999999999999)
        }

        if (prod1 == 0) {
            unchecked {
                result = (prod0 / SCALE) + roundUpUnit;
                return result;
            }
        }

        assembly {
            result := add(
                mul(
                    or(
                        div(sub(prod0, remainder), SCALE_LPOTD),
                        mul(
                            sub(prod1, gt(remainder, prod0)),
                            add(div(sub(0, SCALE_LPOTD), SCALE_LPOTD), 1)
                        )
                    ),
                    SCALE_INVERSE
                ),
                roundUpUnit
            )
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev An extension of "mulDiv" for signed numbers. Works by computing the signs and the absolute values separately.
    ///
    /// Requirements:
    /// - None of the inputs can be type(int256).min.
    /// - The result must fit within 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.
    function mulDivSigned(
        int256 x,
        int256 y,
        int256 denominator
    ) internal pure returns (int256 result) {
        if (
            x == type(int256).min ||
            y == type(int256).min ||
            denominator == type(int256).min
        ) {
            revert PRBMath__MulDivSignedInputTooSmall();
        }

        // Get hold of the absolute values of x, y and the denominator.
        uint256 ax;
        uint256 ay;
        uint256 ad;
        unchecked {
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);
            ad = denominator < 0 ? uint256(-denominator) : uint256(denominator);
        }

        // Compute the absolute value of (x*y)÷denominator. The result must fit within int256.
        uint256 rAbs = mulDiv(ax, ay, ad);
        if (rAbs > uint256(type(int256).max)) {
            revert PRBMath__MulDivSignedOverflow(rAbs);
        }

        // Get the signs of x, y and the denominator.
        uint256 sx;
        uint256 sy;
        uint256 sd;
        assembly {
            sx := sgt(x, sub(0, 1))
            sy := sgt(y, sub(0, 1))
            sd := sgt(denominator, sub(0, 1))
        }

        // XOR over sx, sy and sd. This is checking whether there are one or three negative signs in the inputs.
        // If yes, the result should be negative.
        result = sx ^ sy ^ sd == 0 ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The uint256 number for which to calculate the square root.
    /// @return result The result as an uint256.
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        // Set the initial guess to the least power of two that is greater than or equal to sqrt(x).
        uint256 xAux = uint256(x);
        result = 1;
        if (xAux >= 0x100000000000000000000000000000000) {
            xAux >>= 128;
            result <<= 64;
        }
        if (xAux >= 0x10000000000000000) {
            xAux >>= 64;
            result <<= 32;
        }
        if (xAux >= 0x100000000) {
            xAux >>= 32;
            result <<= 16;
        }
        if (xAux >= 0x10000) {
            xAux >>= 16;
            result <<= 8;
        }
        if (xAux >= 0x100) {
            xAux >>= 8;
            result <<= 4;
        }
        if (xAux >= 0x10) {
            xAux >>= 4;
            result <<= 2;
        }
        if (xAux >= 0x8) {
            result <<= 1;
        }

        // The operations can never overflow because the result is max 2^127 when it enters this block.
        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; // Seven iterations should be enough
            uint256 roundedDownResult = x / result;
            return result >= roundedDownResult ? roundedDownResult : result;
        }
    }
}

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

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"PRBMathSD59x18__DivInputTooSmall","type":"error"},{"inputs":[{"internalType":"uint256","name":"rAbs","type":"uint256"}],"name":"PRBMathSD59x18__DivOverflow","type":"error"},{"inputs":[{"internalType":"int256","name":"x","type":"int256"}],"name":"PRBMathSD59x18__LogInputTooSmall","type":"error"},{"inputs":[],"name":"PRBMathSD59x18__MulInputTooSmall","type":"error"},{"inputs":[{"internalType":"uint256","name":"rAbs","type":"uint256"}],"name":"PRBMathSD59x18__MulOverflow","type":"error"},{"inputs":[{"internalType":"int256","name":"x","type":"int256"}],"name":"PRBMathSD59x18__SqrtNegativeInput","type":"error"},{"inputs":[{"internalType":"int256","name":"x","type":"int256"}],"name":"PRBMathSD59x18__SqrtOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"}],"name":"PRBMath__MulDivFixedPointOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"PRBMath__MulDivOverflow","type":"error"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"spotPrice","type":"uint256"},{"internalType":"uint256","name":"strikePrice","type":"uint256"},{"internalType":"uint256","name":"iv","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"},{"internalType":"int256","name":"riskFree","type":"int256"}],"name":"getPutPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b5061c3506000808081526020019081526020016000208190555061c4df600080606481526020019081526020016000208190555061c66e60008060c881526020019081526020016000208190555061c7fd60008061012c81526020019081526020016000208190555061c98b60008061019081526020019081526020016000208190555061cb1a6000806101f481526020019081526020016000208190555061cca860008061025881526020019081526020016000208190555061ce366000806102bc81526020019081526020016000208190555061cfc460008061032081526020019081526020016000208190555061d15260008061038481526020019081526020016000208190555061d2df6000806103e881526020019081526020016000208190555061d46c60008061044c81526020019081526020016000208190555061d5f86000806104b081526020019081526020016000208190555061d78460008061051481526020019081526020016000208190555061d90f60008061057881526020019081526020016000208190555061da9a6000806105dc81526020019081526020016000208190555061dc2460008061064081526020019081526020016000208190555061ddad6000806106a481526020019081526020016000208190555061df3660008061070881526020019081526020016000208190555061e0bf60008061076c81526020019081526020016000208190555061e2466000806107d081526020019081526020016000208190555061e3cd60008061083481526020019081526020016000208190555061e55260008061089881526020019081526020016000208190555061e6d76000806108fc81526020019081526020016000208190555061e85b60008061096081526020019081526020016000208190555061e9df6000806109c481526020019081526020016000208190555061eb61600080610a2881526020019081526020016000208190555061ece2600080610a8c81526020019081526020016000208190555061ee62600080610af081526020019081526020016000208190555061efe1600080610b5481526020019081526020016000208190555061f15f600080610bb881526020019081526020016000208190555061f2dc600080610c1c81526020019081526020016000208190555061f458600080610c8081526020019081526020016000208190555061f5d2600080610ce481526020019081526020016000208190555061f74b600080610d4881526020019081526020016000208190555061f8c3600080610dac81526020019081526020016000208190555061fa3a600080610e1081526020019081526020016000208190555061fbaf600080610e7481526020019081526020016000208190555061fd23600080610ed881526020019081526020016000208190555061fe95600080610f3c81526020019081526020016000208190555062010006600080610fa081526020019081526020016000208190555062010176600080611004815260200190815260200160002081905550620102e4600080611068815260200190815260200160002081905550620104506000806110cc815260200190815260200160002081905550620105bb600080611130815260200190815260200160002081905550620107246000806111948152602001908152602001600020819055506201088c6000806111f8815260200190815260200160002081905550620109f260008061125c81526020019081526020016000208190555062010b576000806112c081526020019081526020016000208190555062010cb960008061132481526020019081526020016000208190555062010e1a60008061138881526020019081526020016000208190555062010f796000806113ec815260200190815260200160002081905550620110d7600080611450815260200190815260200160002081905550620112326000806114b48152602001908152602001600020819055506201138c600080611518815260200190815260200160002081905550620114e460008061157c8152602001908152602001600020819055506201163a6000806115e08152602001908152602001600020819055506201178e600080611644815260200190815260200160002081905550620118e06000806116a881526020019081526020016000208190555062011a3060008061170c81526020019081526020016000208190555062011b7f60008061177081526020019081526020016000208190555062011ccb6000806117d481526020019081526020016000208190555062011e1560008061183881526020019081526020016000208190555062011f5d60008061189c815260200190815260200160002081905550620120a3600080611900815260200190815260200160002081905550620121e7600080611964815260200190815260200160002081905550620123296000806119c881526020019081526020016000208190555062012469600080611a2c815260200190815260200160002081905550620125a7600080611a90815260200190815260200160002081905550620126e2600080611af48152602001908152602001600020819055506201281c600080611b5881526020019081526020016000208190555062012953600080611bbc81526020019081526020016000208190555062012a88600080611c2081526020019081526020016000208190555062012bba600080611c8481526020019081526020016000208190555062012ceb600080611ce881526020019081526020016000208190555062012e19600080611d4c81526020019081526020016000208190555062012f45600080611db08152602001908152602001600020819055506201306f600080611e1481526020019081526020016000208190555062013196600080611e78815260200190815260200160002081905550620132bc600080611edc815260200190815260200160002081905550620133de600080611f40815260200190815260200160002081905550620134ff600080611fa48152602001908152602001600020819055506201361d6000806120088152602001908152602001600020819055506201373960008061206c815260200190815260200160002081905550620138536000806120d08152602001908152602001600020819055506201396a60008061213481526020019081526020016000208190555062013a7f60008061219881526020019081526020016000208190555062013b916000806121fc81526020019081526020016000208190555062013ca160008061226081526020019081526020016000208190555062013daf6000806122c481526020019081526020016000208190555062013eba60008061232881526020019081526020016000208190555062013fc360008061238c815260200190815260200160002081905550620140c96000806123f0815260200190815260200160002081905550620141cd600080612454815260200190815260200160002081905550620142cf6000806124b8815260200190815260200160002081905550620143ce60008061251c815260200190815260200160002081905550620144cb600080612580815260200190815260200160002081905550620145c66000806125e4815260200190815260200160002081905550620146be600080612648815260200190815260200160002081905550620147b36000806126ac815260200190815260200160002081905550620148a66000806127108152602001908152602001600020819055506201499760008061277481526020019081526020016000208190555062014a866000806127d881526020019081526020016000208190555062014b7160008061283c81526020019081526020016000208190555062014c5b6000806128a081526020019081526020016000208190555062014d4260008061290481526020019081526020016000208190555062014e2760008061296881526020019081526020016000208190555062014f096000806129cc81526020019081526020016000208190555062014fe9600080612a30815260200190815260200160002081905550620150c6600080612a94815260200190815260200160002081905550620151a1600080612af88152602001908152602001600020819055506201527a600080612b5c81526020019081526020016000208190555062015350600080612bc081526020019081526020016000208190555062015424600080612c24815260200190815260200160002081905550620154f6600080612c88815260200190815260200160002081905550620155c5600080612cec81526020019081526020016000208190555062015692600080612d508152602001908152602001600020819055506201575c600080612db481526020019081526020016000208190555062015824600080612e18815260200190815260200160002081905550620158ea600080612e7c815260200190815260200160002081905550620159ad600080612ee081526020019081526020016000208190555062015a6e600080612f4481526020019081526020016000208190555062015b2d600080612fa881526020019081526020016000208190555062015be960008061300c81526020019081526020016000208190555062015ca360008061307081526020019081526020016000208190555062015d5b6000806130d481526020019081526020016000208190555062015e1160008061313881526020019081526020016000208190555062015ec460008061319c81526020019081526020016000208190555062015f7560008061320081526020019081526020016000208190555062016023600080613264815260200190815260200160002081905550620160d06000806132c88152602001908152602001600020819055506201617a60008061332c81526020019081526020016000208190555062016222600080613390815260200190815260200160002081905550620162c86000806133f48152602001908152602001600020819055506201636c6000806134588152602001908152602001600020819055506201640d6000806134bc815260200190815260200160002081905550620164ad6000806135208152602001908152602001600020819055506201654a600080613584815260200190815260200160002081905550620165e56000806135e88152602001908152602001600020819055506201667e60008061364c815260200190815260200160002081905550620167146000806136b0815260200190815260200160002081905550620167a96000806137148152602001908152602001600020819055506201683c600080613778815260200190815260200160002081905550620168cc6000806137dc8152602001908152602001600020819055506201695b600080613840815260200190815260200160002081905550620169e76000806138a481526020019081526020016000208190555062016a7160008061390881526020019081526020016000208190555062016afa60008061396c81526020019081526020016000208190555062016b806000806139d081526020019081526020016000208190555062016c05600080613a3481526020019081526020016000208190555062016c87600080613a9881526020019081526020016000208190555062016d08600080613afc81526020019081526020016000208190555062016d86600080613b6081526020019081526020016000208190555062016e03600080613bc481526020019081526020016000208190555062016e7e600080613c2881526020019081526020016000208190555062016ef7600080613c8c81526020019081526020016000208190555062016f6e600080613cf081526020019081526020016000208190555062016fe3600080613d5481526020019081526020016000208190555062017057600080613db8815260200190815260200160002081905550620170c8600080613e1c81526020019081526020016000208190555062017138600080613e80815260200190815260200160002081905550620171a6600080613ee481526020019081526020016000208190555062017212600080613f488152602001908152602001600020819055506201727d600080613fac815260200190815260200160002081905550620172e66000806140108152602001908152602001600020819055506201734d600080614074815260200190815260200160002081905550620173b26000806140d88152602001908152602001600020819055506201741660008061413c815260200190815260200160002081905550620174786000806141a0815260200190815260200160002081905550620174d960008061420481526020019081526020016000208190555062017537600080614268815260200190815260200160002081905550620175956000806142cc815260200190815260200160002081905550620175f06000806143308152602001908152602001600020819055506201764a600080614394815260200190815260200160002081905550620176a36000806143f8815260200190815260200160002081905550620176fa60008061445c815260200190815260200160002081905550620177506000806144c0815260200190815260200160002081905550620177a4600080614524815260200190815260200160002081905550620177f6600080614588815260200190815260200160002081905550620178476000806145ec81526020019081526020016000208190555062017897600080614650815260200190815260200160002081905550620178e56000806146b4815260200190815260200160002081905550620179326000806147188152602001908152602001600020819055506201797e60008061477c815260200190815260200160002081905550620179c86000806147e081526020019081526020016000208190555062017a1060008061484481526020019081526020016000208190555062017a586000806148a881526020019081526020016000208190555062017a9e60008061490c81526020019081526020016000208190555062017ae360008061497081526020019081526020016000208190555062017b266000806149d481526020019081526020016000208190555062017b68600080614a3881526020019081526020016000208190555062017ba9600080614a9c81526020019081526020016000208190555062017be9600080614b0081526020019081526020016000208190555062017c28600080614b6481526020019081526020016000208190555062017c65600080614bc881526020019081526020016000208190555062017ca1600080614c2c81526020019081526020016000208190555062017cdc600080614c9081526020019081526020016000208190555062017d16600080614cf481526020019081526020016000208190555062017d4f600080614d5881526020019081526020016000208190555062017d86600080614dbc81526020019081526020016000208190555062017dbd600080614e2081526020019081526020016000208190555062017df2600080614e8481526020019081526020016000208190555062017e27600080614ee881526020019081526020016000208190555062017e5a600080614f4c81526020019081526020016000208190555062017e8c600080614fb081526020019081526020016000208190555062017ebe60008061501481526020019081526020016000208190555062017eee60008061507881526020019081526020016000208190555062017f1d6000806150dc81526020019081526020016000208190555062017f4c60008061514081526020019081526020016000208190555062017f796000806151a481526020019081526020016000208190555062017fa660008061520881526020019081526020016000208190555062017fd160008061526c81526020019081526020016000208190555062017ffc6000806152d0815260200190815260200160002081905550620180256000806153348152602001908152602001600020819055506201804e600080615398815260200190815260200160002081905550620180766000806153fc8152602001908152602001600020819055506201809d600080615460815260200190815260200160002081905550620180c46000806154c4815260200190815260200160002081905550620180e96000806155288152602001908152602001600020819055506201810e60008061558c815260200190815260200160002081905550620181326000806155f081526020019081526020016000208190555062018155600080615654815260200190815260200160002081905550620181776000806156b88152602001908152602001600020819055506201819960008061571c815260200190815260200160002081905550620181b9600080615780815260200190815260200160002081905550620181da6000806157e4815260200190815260200160002081905550620181f9600080615848815260200190815260200160002081905550620182186000806158ac8152602001908152602001600020819055506201823660008061591081526020019081526020016000208190555062018253600080615974815260200190815260200160002081905550620182706000806159d88152602001908152602001600020819055506201828c600080615a3c815260200190815260200160002081905550620182a7600080615aa0815260200190815260200160002081905550620182c2600080615b04815260200190815260200160002081905550620182dc600080615b68815260200190815260200160002081905550620182f5600080615bcc8152602001908152602001600020819055506201830e600080615c3081526020019081526020016000208190555062018327600080615c948152602001908152602001600020819055506201833e600080615cf881526020019081526020016000208190555062018356600080615d5c8152602001908152602001600020819055506201836c600080615dc081526020019081526020016000208190555062018382600080615e2481526020019081526020016000208190555062018398600080615e88815260200190815260200160002081905550620183ad600080615eec815260200190815260200160002081905550620183c2600080615f50815260200190815260200160002081905550620183d6600080615fb4815260200190815260200160002081905550620183e9600080616018815260200190815260200160002081905550620183fc60008061607c8152602001908152602001600020819055506201840f6000806160e081526020019081526020016000208190555062018421600080616144815260200190815260200160002081905550620184336000806161a88152602001908152602001600020819055506201844460008061620c81526020019081526020016000208190555062018455600080616270815260200190815260200160002081905550620184666000806162d4815260200190815260200160002081905550620184766000806163388152602001908152602001600020819055506201848560008061639c81526020019081526020016000208190555062018495600080616400815260200190815260200160002081905550620184a4600080616464815260200190815260200160002081905550620184b26000806164c8815260200190815260200160002081905550620184c060008061652c815260200190815260200160002081905550620184ce600080616590815260200190815260200160002081905550620184db6000806165f4815260200190815260200160002081905550620184e8600080616658815260200190815260200160002081905550620184f56000806166bc815260200190815260200160002081905550620185016000806167208152602001908152602001600020819055506201850e600080616784815260200190815260200160002081905550620185196000806167e88152602001908152602001600020819055506201852560008061684c815260200190815260200160002081905550620185306000806168b08152602001908152602001600020819055506201853b60008061691481526020019081526020016000208190555062018545600080616978815260200190815260200160002081905550620185506000806169dc8152602001908152602001600020819055506201855a600080616a4081526020019081526020016000208190555062018563600080616aa48152602001908152602001600020819055506201856d600080616b0881526020019081526020016000208190555062018576600080616b6c8152602001908152602001600020819055506201857f600080616bd081526020019081526020016000208190555062018588600080616c3481526020019081526020016000208190555062018590600080616c9881526020019081526020016000208190555062018598600080616cfc815260200190815260200160002081905550620185a0600080616d60815260200190815260200160002081905550620185a8600080616dc4815260200190815260200160002081905550620185b0600080616e28815260200190815260200160002081905550620185b7600080616e8c815260200190815260200160002081905550620185be600080616ef0815260200190815260200160002081905550620185c5600080616f54815260200190815260200160002081905550620185cc600080616fb8815260200190815260200160002081905550620185d360008061701c815260200190815260200160002081905550620185d9600080617080815260200190815260200160002081905550620185df6000806170e4815260200190815260200160002081905550620185e5600080617148815260200190815260200160002081905550620185eb6000806171ac815260200190815260200160002081905550620185f1600080617210815260200190815260200160002081905550620185f7600080617274815260200190815260200160002081905550620185fc6000806172d88152602001908152602001600020819055506201860160008061733c815260200190815260200160002081905550620186066000806173a08152602001908152602001600020819055506201860b60008061740481526020019081526020016000208190555062018610600080617468815260200190815260200160002081905550620186156000806174cc815260200190815260200160002081905550620186196000806175308152602001908152602001600020819055506201861d600080617594815260200190815260200160002081905550620186226000806175f88152602001908152602001600020819055506201862660008061765c8152602001908152602001600020819055506201862a6000806176c08152602001908152602001600020819055506201862e60008061772481526020019081526020016000208190555062018631600080617788815260200190815260200160002081905550620186356000806177ec815260200190815260200160002081905550620186386000806178508152602001908152602001600020819055506201863c6000806178b48152602001908152602001600020819055506201863f6000806179188152602001908152602001600020819055506201864260008061797c815260200190815260200160002081905550620186466000806179e081526020019081526020016000208190555062018649600080617a448152602001908152602001600020819055506201864c600080617aa88152602001908152602001600020819055506201864e600080617b0c81526020019081526020016000208190555062018651600080617b7081526020019081526020016000208190555062018654600080617bd481526020019081526020016000208190555062018656600080617c3881526020019081526020016000208190555062018659600080617c9c8152602001908152602001600020819055506201865b600080617d008152602001908152602001600020819055506201865e600080617d6481526020019081526020016000208190555062018660600080617dc881526020019081526020016000208190555062018662600080617e2c81526020019081526020016000208190555062018664600080617e9081526020019081526020016000208190555062018666600080617ef481526020019081526020016000208190555062018668600080617f588152602001908152602001600020819055506201866a600080617fbc8152602001908152602001600020819055506201866c6000806180208152602001908152602001600020819055506201866e600080618084815260200190815260200160002081905550620186706000806180e88152602001908152602001600020819055506201867160008061814c815260200190815260200160002081905550620186736000806181b08152602001908152602001600020819055506201867560008061821481526020019081526020016000208190555062018676600080618278815260200190815260200160002081905550620186786000806182dc815260200190815260200160002081905550620186796000806183408152602001908152602001600020819055506201867a6000806183a48152602001908152602001600020819055506201867c6000806184088152602001908152602001600020819055506201867d60008061846c8152602001908152602001600020819055506201867e6000806184d08152602001908152602001600020819055506201868060008061853481526020019081526020016000208190555062018681600080618598815260200190815260200160002081905550620186826000806185fc81526020019081526020016000208190555062018683600080618660815260200190815260200160002081905550620186846000806186c4815260200190815260200160002081905550620186856000806187288152602001908152602001600020819055506201868660008061878c815260200190815260200160002081905550620186876000806187f081526020019081526020016000208190555062018688600080618854815260200190815260200160002081905550620186896000806188b88152602001908152602001600020819055506201868a60008061891c8152602001908152602001600020819055506201868a6000806189808152602001908152602001600020819055506201868b6000806189e48152602001908152602001600020819055506201868c600080618a488152602001908152602001600020819055506201868d600080618aac8152602001908152602001600020819055506201868d600080618b108152602001908152602001600020819055506201868e600080618b748152602001908152602001600020819055506201868f600080618bd88152602001908152602001600020819055506201868f600080618c3c81526020019081526020016000208190555062018690600080618ca081526020019081526020016000208190555062018691600080618d0481526020019081526020016000208190555062018691600080618d6881526020019081526020016000208190555062018692600080618dcc81526020019081526020016000208190555062018692600080618e3081526020019081526020016000208190555062018693600080618e9481526020019081526020016000208190555062018693600080618ef881526020019081526020016000208190555062018694600080618f5c81526020019081526020016000208190555062018694600080618fc08152602001908152602001600020819055506201869560008061902481526020019081526020016000208190555062018695600080619088815260200190815260200160002081905550620186966000806190ec81526020019081526020016000208190555062018696600080619150815260200190815260200160002081905550620186966000806191b4815260200190815260200160002081905550620186976000806192188152602001908152602001600020819055506201869760008061927c815260200190815260200160002081905550620186986000806192e081526020019081526020016000208190555062018698600080619344815260200190815260200160002081905550620186986000806193a88152602001908152602001600020819055506201869860008061940c81526020019081526020016000208190555062018699600080619470815260200190815260200160002081905550620186996000806194d4815260200190815260200160002081905550620186996000806195388152602001908152602001600020819055506201869a60008061959c8152602001908152602001600020819055506201869a6000806196008152602001908152602001600020819055506201869a6000806196648152602001908152602001600020819055506201869a6000806196c88152602001908152602001600020819055506201869b60008061972c8152602001908152602001600020819055506201869b6000806197908152602001908152602001600020819055506201869b6000806197f48152602001908152602001600020819055506201869b6000806198588152602001908152602001600020819055506201869b6000806198bc8152602001908152602001600020819055506201869c6000806199208152602001908152602001600020819055506201869c6000806199848152602001908152602001600020819055506201869c6000806199e88152602001908152602001600020819055506201869c600080619a4c8152602001908152602001600020819055506201869c600080619ab08152602001908152602001600020819055506201869c600080619b148152602001908152602001600020819055506116a780612b7c6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063313ce5671461003b57806398659d2414610059575b600080fd5b610043610089565b6040516100509190610f57565b60405180910390f35b610073600480360381019061006e9190610fe3565b61008e565b604051610080919061106d565b60405180910390f35b601281565b60008060006100c061009f89610151565b6100a889610151565b6100b189610151565b6100ba89610151565b886101a4565b9150915060006100d76100d28461027a565b6102e3565b905060006100ec6100e78461027a565b6102e3565b90506000610103828b61049c90919063ffffffff16565b9050600061011a848d61049c90919063ffffffff16565b9050818111156101335760009650505050505050610148565b808261013f91906110b7565b96505050505050505b95945050505050565b600080829050600081121561019b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101929061116e565b60405180910390fd5b80915050919050565b60008060006101bc86876104b090919063ffffffff16565b905060006101db6101d6898b61060d90919063ffffffff16565b610779565b9050600061021787876101ff671bc16d674ec800008761060d90919063ffffffff16565b610209919061118e565b6104b090919063ffffffff16565b905060008183610227919061118e565b905060006102466102378a6107ad565b8b6104b090919063ffffffff16565b905061025b818361060d90919063ffffffff16565b965080876102699190611222565b955050505050509550959350505050565b600081610286906112b6565b90506000808313905060008083139050811515811515036102dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102d390611370565b60405180910390fd5b5050919050565b6000806102ef8361088b565b90506000610302601260ff1660026108ac565b600a61030e91906114c3565b90506000610321601260ff1660036108ac565b600a61032d91906114c3565b9050600061034561033e85856108c2565b60646108d8565b9050600061035d61035686866108c2565b600a6108d8565b61036786856108c2565b61037191906110b7565b90506000610384601260ff1660056108ac565b600a61039091906114c3565b9050600061a3ac84106103a8576201869f905061046b565b619e9884106103bc576201869e905061046a565b619b7884106103d0576201869d9050610469565b600783106103fe576000806064866103e8919061150e565b8152602001908152602001600020549050610468565b600483106104515761044a6104436000808781526020019081526020016000205460008060648961042f919061150e565b8152602001908152602001600020546108ee565b60026108c2565b9050610467565b6000808581526020019081526020016000205490505b5b5b5b5b600089121561048457610481620186a0826108ac565b90505b61048e81836108d8565b975050505050505050919050565b60006104a88383610904565b905092915050565b60007f80000000000000000000000000000000000000000000000000000000000000008314806104ff57507f800000000000000000000000000000000000000000000000000000000000000082145b15610536576040517f3406846c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008060008512610547578461054c565b846000035b91506000841261055c5783610561565b836000035b9050600061056f8383610904565b90507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8111156105d657806040517fbf79e8d90000000000000000000000000000000000000000000000000000000081526004016105cd919061106d565b60405180910390fd5b6000806001600003881391506001600003871390506001818318146105fb5782610600565b826000035b9550505050505092915050565b60007f800000000000000000000000000000000000000000000000000000000000000083148061065c57507f800000000000000000000000000000000000000000000000000000000000000082145b15610693576040517fb3c754a300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080600085126106a457846106a9565b846000035b9150600084126106b957836106be565b836000035b905060006106d583670de0b6b3a764000084610a01565b90507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81111561073c57806040517f7cb4bef5000000000000000000000000000000000000000000000000000000008152600401610733919061106d565b60405180910390fd5b600080600160000388139150600160000387139050600181831814610761578261076c565b8261076b906112b6565b5b9550505050505092915050565b60006714057b7ef767814f670de0b6b3a764000061079684610b16565b02816107a5576107a4611564565b5b059050919050565b6000808212156107f457816040517fc11907fe0000000000000000000000000000000000000000000000000000000081526004016107eb91906115a2565b60405180910390fd5b670de0b6b3a76400007f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8161082c5761082b611564565b5b0582131561087157816040517f2c482c3900000000000000000000000000000000000000000000000000000000815260040161086891906115a2565b60405180910390fd5b610884670de0b6b3a76400008302610c72565b9050919050565b600080821261089a57816108a5565b816108a4906112b6565b5b9050919050565b600081836108ba91906110b7565b905092915050565b600081836108d091906115bd565b905092915050565b600081836108e691906115ee565b905092915050565b600081836108fc919061150e565b905092915050565b60008060008019848609848602925082811083820303915050670de0b6b3a7640000811061096957806040517fd31b3402000000000000000000000000000000000000000000000000000000008152600401610960919061106d565b60405180910390fd5b600080670de0b6b3a764000086880991506706f05b59d3b1ffff82119050600083036109b55780670de0b6b3a764000085816109a8576109a7611564565b5b04019450505050506109fb565b807faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac1066960016204000080600003040186851186030262040000858803041702019450505050505b92915050565b6000806000801985870985870292508281108382030391505060008103610a3c57838281610a3257610a31611564565b5b0492505050610b0f565b838110610a825780846040517f773cc18c000000000000000000000000000000000000000000000000000000008152600401610a79929190611648565b60405180910390fd5b60008486880990508281118203915080830392506000600186190186169050808604955080840493506001818260000304019050808302841793506000600287600302189050808702600203810290508087026002038102905080870260020381029050808702600203810290508087026002038102905080870260020381029050808502955050505050505b9392505050565b6000808213610b5c57816040517f613f4fba000000000000000000000000000000000000000000000000000000008152600401610b5391906115a2565b60405180910390fd5b6000670de0b6b3a76400008312610b765760019050610bae565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9050826ec097ce7bc90715b34b9f10000000000492505b6000610bd1670de0b6b3a76400008581610bcb57610bca611564565b5b05610e24565b9050670de0b6b3a76400008102925060008185901d9050670de0b6b3a76400008103610c04578284029350505050610c6d565b60006706f05b59d3b2000090505b6000811315610c6357670de0b6b3a764000082830281610c3557610c34611564565b5b059150670de0b6b3a76400006002028212610c57578085019450600182901d91505b600181901d9050610c12565b5082840293505050505b919050565b6000808203610c845760009050610e1f565b6000829050600191507001000000000000000000000000000000008110610cb457608081901c9050604082901b91505b680100000000000000008110610cd357604081901c9050602082901b91505b6401000000008110610cee57602081901c9050601082901b91505b620100008110610d0757601081901c9050600882901b91505b6101008110610d1f57600881901c9050600482901b91505b60108110610d3657600481901c9050600282901b91505b60088110610d4657600182901b91505b6001828481610d5857610d57611564565b5b048301901c91506001828481610d7157610d70611564565b5b048301901c91506001828481610d8a57610d89611564565b5b048301901c91506001828481610da357610da2611564565b5b048301901c91506001828481610dbc57610dbb611564565b5b048301901c91506001828481610dd557610dd4611564565b5b048301901c91506001828481610dee57610ded611564565b5b048301901c91506000828481610e0757610e06611564565b5b04905080831015610e185782610e1a565b805b925050505b919050565b60007001000000000000000000000000000000008210610e5557608082901c9150608081610e52919061150e565b90505b680100000000000000008210610e7c57604082901c9150604081610e79919061150e565b90505b6401000000008210610e9f57602082901c9150602081610e9c919061150e565b90505b620100008210610ec057601082901c9150601081610ebd919061150e565b90505b6101008210610ee057600882901c9150600881610edd919061150e565b90505b60108210610eff57600482901c9150600481610efc919061150e565b90505b60048210610f1e57600282901c9150600281610f1b919061150e565b90505b60028210610f3657600181610f33919061150e565b90505b919050565b600060ff82169050919050565b610f5181610f3b565b82525050565b6000602082019050610f6c6000830184610f48565b92915050565b600080fd5b6000819050919050565b610f8a81610f77565b8114610f9557600080fd5b50565b600081359050610fa781610f81565b92915050565b6000819050919050565b610fc081610fad565b8114610fcb57600080fd5b50565b600081359050610fdd81610fb7565b92915050565b600080600080600060a08688031215610fff57610ffe610f72565b5b600061100d88828901610f98565b955050602061101e88828901610f98565b945050604061102f88828901610f98565b935050606061104088828901610f98565b925050608061105188828901610fce565b9150509295509295909350565b61106781610f77565b82525050565b6000602082019050611082600083018461105e565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006110c282610f77565b91506110cd83610f77565b9250828210156110e0576110df611088565b5b828203905092915050565b600082825260208201905092915050565b7f496e737572616e63655072696365723a2063617374696e67206f766572666c6f60008201527f7700000000000000000000000000000000000000000000000000000000000000602082015250565b60006111586021836110eb565b9150611163826110fc565b604082019050919050565b600060208201905081810360008301526111878161114b565b9050919050565b600061119982610fad565b91506111a483610fad565b9250817f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038313600083121516156111df576111de611088565b5b817f800000000000000000000000000000000000000000000000000000000000000003831260008312161561121757611216611088565b5b828201905092915050565b600061122d82610fad565b915061123883610fad565b9250827f80000000000000000000000000000000000000000000000000000000000000000182126000841215161561127357611272611088565b5b827f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0182136000841216156112ab576112aa611088565b5b828203905092915050565b60006112c182610fad565b91507f800000000000000000000000000000000000000000000000000000000000000082036112f3576112f2611088565b5b816000039050919050565b7f496e737572616e63655072696365723a206164646974697665496e766572736560008201527f206f766572666c6f770000000000000000000000000000000000000000000000602082015250565b600061135a6029836110eb565b9150611365826112fe565b604082019050919050565b600060208201905081810360008301526113898161134d565b9050919050565b60008160011c9050919050565b6000808291508390505b60018511156113e7578086048111156113c3576113c2611088565b5b60018516156113d25780820291505b80810290506113e085611390565b94506113a7565b94509492505050565b60008261140057600190506114bc565b8161140e57600090506114bc565b8160018114611424576002811461142e5761145d565b60019150506114bc565b60ff8411156114405761143f611088565b5b8360020a91508482111561145757611456611088565b5b506114bc565b5060208310610133831016604e8410600b84101617156114925782820a90508381111561148d5761148c611088565b5b6114bc565b61149f848484600161139d565b925090508184048111156114b6576114b5611088565b5b81810290505b9392505050565b60006114ce82610f77565b91506114d983610f77565b92506115067fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84846113f0565b905092915050565b600061151982610f77565b915061152483610f77565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561155957611558611088565b5b828201905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b61159c81610fad565b82525050565b60006020820190506115b76000830184611593565b92915050565b60006115c882610f77565b91506115d383610f77565b9250826115e3576115e2611564565b5b828204905092915050565b60006115f982610f77565b915061160483610f77565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561163d5761163c611088565b5b828202905092915050565b600060408201905061165d600083018561105e565b61166a602083018461105e565b939250505056fea264697066735822122043d572b3e00bdfd67d56e024bfb3766a330d4ee949edeed627a37f2d55f8f32164736f6c634300080d0033

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading